First attempt at supporting custom pointGeometry in workers

feature/threejs-update
Robin Hawkes 2016-09-09 13:15:21 +01:00
rodzic 9fe846bbff
commit ba2a16dcd5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 1EC4C2D6765FA8CF
3 zmienionych plików z 27 dodań i 11 usunięć

Wyświetl plik

@ -351,7 +351,7 @@ class GeoJSONLayer extends LayerGroup {
if (geometry.type === 'Point' || geometry.type === 'MultiPoint') {
// Get geometry object to use for point, if provided
if (typeof this._options.pointGeometry === 'function') {
options.geometry = this._options.pointGeometry(feature);
options.pointGeometry = this._options.pointGeometry(feature);
}
// Get material instance to use for point, if provided

Wyświetl plik

@ -25,6 +25,7 @@ class GeoJSONWorkerLayer extends Layer {
onEachFeatureWorker: null,
onAddAttributes: null,
interactive: false,
pointGeometry: null,
onClick: null,
headers: {}
};
@ -56,17 +57,25 @@ class GeoJSONWorkerLayer extends Layer {
return new Promise((resolve, reject) => {
var style = this._options.style;
// TODO: Convert to buffer and use transferrable objects
if (typeof this._options.style === 'function') {
style = Stringify.functionToString(this._options.style);
}
var pointGeometry = this._options.pointGeometry;
// TODO: Convert to buffer and use transferrable objects
if (typeof this._options.pointGeometry === 'function') {
pointGeometry = Stringify.functionToString(this._options.pointGeometry);
}
var geojson = _geojson;
var transferrables = [];
if (typeof geojson !== 'string') {
this._geojson = geojson = Buffer.stringToUint8Array(JSON.stringify(geojson));
transferrables.push(geojson.buffer);
this._execWorker(geojson, this._options.topojson, this._world._originPoint, style, this._options.interactive, transferrables).then(() => {
this._execWorker(geojson, this._options.topojson, this._world._originPoint, style, this._options.interactive, pointGeometry, transferrables).then(() => {
resolve();
}).catch(reject);
} else if (typeof this._options.filter === 'function' || typeof this._options.onEachFeature === 'function') {
@ -90,23 +99,23 @@ class GeoJSONWorkerLayer extends Layer {
this._geojson = geojson = Buffer.stringToUint8Array(JSON.stringify(fc));
transferrables.push(geojson.buffer);
this._execWorker(geojson, false, this._options.headers, this._world._originPoint, style, this._options.interactive, transferrables).then(() => {
this._execWorker(geojson, false, this._options.headers, this._world._originPoint, style, this._options.interactive, pointGeometry, transferrables).then(() => {
resolve();
}).catch(reject);
});
} else {
this._execWorker(geojson, this._options.topojson, this._options.headers, this._world._originPoint, style, this._options.interactive, transferrables).then(() => {
this._execWorker(geojson, this._options.topojson, this._options.headers, this._world._originPoint, style, this._options.interactive, pointGeometry, transferrables).then(() => {
resolve();
}).catch(reject);
}
});
}
_execWorker(geojson, topojson, headers, originPoint, style, interactive, transferrables) {
_execWorker(geojson, topojson, headers, originPoint, style, interactive, pointGeometry, transferrables) {
return new Promise((resolve, reject) => {
console.time('Worker round trip');
Worker.exec('GeoJSONWorkerLayer.Process', [geojson, topojson, headers, originPoint, style, interactive], transferrables).then((results) => {
Worker.exec('GeoJSONWorkerLayer.Process', [geojson, topojson, headers, originPoint, style, interactive, pointGeometry], transferrables).then((results) => {
console.timeEnd('Worker round trip');
if (results.polygons) {
@ -452,7 +461,7 @@ class GeoJSONWorkerLayer extends Layer {
// feels a bit messy and against the idea of a static Geo class
//
// TODO: Support passing custom geometry for point layers
static Process(geojson, topojson, headers, originPoint, _style, _properties) {
static Process(geojson, topojson, headers, originPoint, _style, _properties, _pointGeometry) {
return new Promise((resolve, reject) => {
GeoJSONWorkerLayer.ProcessGeoJSON(geojson, headers).then((res) => {
// Collects features into a single FeatureCollection
@ -479,6 +488,12 @@ class GeoJSONWorkerLayer extends Layer {
// Assume that a style won't be set per feature
var style = _style;
var pointGeometry;
// Deserialise pointGeometry function if provided
if (typeof _pointGeometry === 'string') {
pointGeometry = Stringify.stringToFunction(_pointGeometry);
}
var feature;
for (var i = 0; i < features.length; i++) {
feature = features[i];
@ -595,6 +610,7 @@ class GeoJSONWorkerLayer extends Layer {
var point = {
projected: projected,
options: {
pointGeometry: pointGeometry(feature),
pointScale: pointScale,
style: style
}

Wyświetl plik

@ -38,7 +38,7 @@ class PointLayer extends Layer {
output: true,
interactive: false,
// THREE.Geometry or THREE.BufferGeometry to use for point output
geometry: null,
pointGeometry: null,
// Custom material override
//
// TODO: Should this be in the style object?
@ -160,7 +160,7 @@ class PointLayer extends Layer {
// Use default geometry if none has been provided or the provided geometry
// isn't valid
if (!options.geometry || (!options.geometry instanceof THREE.Geometry || !options.geometry instanceof THREE.BufferGeometry)) {
if (!options.pointGeometry || (!options.pointGeometry instanceof THREE.Geometry || !options.pointGeometry instanceof THREE.BufferGeometry)) {
// Debug geometry for points is a thin bar
//
// TODO: Allow point geometry to be customised / overridden
@ -175,9 +175,9 @@ class PointLayer extends Layer {
geometry = new THREE.BufferGeometry().fromGeometry(_geometry);
} else {
if (options.geometry instanceof THREE.BufferGeometry) {
geometry = options.geometry;
geometry = options.pointGeometry;
} else {
geometry = new THREE.BufferGeometry().fromGeometry(options.geometry);
geometry = new THREE.BufferGeometry().fromGeometry(options.pointGeometry);
}
}