kopia lustrzana https://github.com/robhawkes/vizicities
Added filtering to worker layer to fix existing examples
rodzic
a0a2c93f45
commit
9fe846bbff
|
@ -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);
|
||||||
|
|
Ładowanie…
Reference in New Issue