Added filtering to worker layer to fix existing examples

feature/threejs-update
Robin Hawkes 2016-09-09 12:36:02 +01:00
rodzic a0a2c93f45
commit 9fe846bbff
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 1EC4C2D6765FA8CF
1 zmienionych plików z 16 dodań i 6 usunięć

Wyświetl plik

@ -13,6 +13,9 @@ import {point as Point} from '../geo/Point';
import Geo from '../geo/Geo'; import Geo from '../geo/Geo';
import PickingMaterial from '../engine/PickingMaterial'; import PickingMaterial from '../engine/PickingMaterial';
// TODO: Allow filter method to be run inside a worker to improve performance
// TODO: Allow onEachFeature method to be run inside a worker to improve performance
class GeoJSONWorkerLayer extends Layer { class GeoJSONWorkerLayer extends Layer {
constructor(geojson, options) { constructor(geojson, options) {
var defaults = { var defaults = {
@ -66,16 +69,23 @@ class GeoJSONWorkerLayer extends Layer {
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, transferrables).then(() => {
resolve(); resolve();
}).catch(reject); }).catch(reject);
} else if (typeof this._options.onEachFeature === 'function') { } else if (typeof this._options.filter === 'function' || typeof this._options.onEachFeature === 'function') {
GeoJSONWorkerLayer.RequestGeoJSON(geojson).then((res) => { GeoJSONWorkerLayer.RequestGeoJSON(geojson).then((res) => {
var fc = GeoJSON.collectFeatures(res, this._options.topojson); var fc = GeoJSON.collectFeatures(res, this._options.topojson);
var features = fc.features; var features = fc.features;
var feature; // Run filter, if provided
for (var i = 0; i < features.length; i++) { if (this._options.filter) {
feature = features[i]; fc.features = features.filter(this._options.filter);
this._options.onEachFeature(feature); }
};
if (this._options.onEachFeature) {
var feature;
for (var i = 0; i < features.length; i++) {
feature = features[i];
this._options.onEachFeature(feature);
};
}
this._geojson = geojson = Buffer.stringToUint8Array(JSON.stringify(fc)); this._geojson = geojson = Buffer.stringToUint8Array(JSON.stringify(fc));
transferrables.push(geojson.buffer); transferrables.push(geojson.buffer);