kopia lustrzana https://github.com/robhawkes/vizicities
Using GeoJSONLayer within tiles, though it requires a lot of memory
rodzic
0601e691cb
commit
5164240ceb
Plik diff jest za duży
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -42,6 +42,7 @@ var imageTileLayer = VIZI.imageTileLayer('http://{s}.basemaps.cartocdn.com/light
|
|||
|
||||
// Building and roads from Mapzen (polygons and linestrings)
|
||||
var topoJSONTileLayer = VIZI.topoJSONTileLayer('https://vector.mapzen.com/osm/buildings,roads/{z}/{x}/{y}.topojson?api_key=vector-tiles-NT5Emiw', {
|
||||
interactive: true,
|
||||
style: function(feature) {
|
||||
var height;
|
||||
|
||||
|
@ -61,6 +62,20 @@ var topoJSONTileLayer = VIZI.topoJSONTileLayer('https://vector.mapzen.com/osm/bu
|
|||
lineRenderOrder: 2
|
||||
};
|
||||
},
|
||||
filter: function(feature) {
|
||||
// Don't show points
|
||||
return feature.geometry.type !== 'Point';
|
||||
},
|
||||
onEachFeature: function(feature, layer) {
|
||||
if (feature.geometry.type !== 'Polygon') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make polygons clickable
|
||||
layer.on('click', function(layer, point2d, point3d, intersects) {
|
||||
console.log(layer, point2d, point3d, intersects);
|
||||
});
|
||||
},
|
||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://whosonfirst.mapzen.com#License">Who\'s On First</a>.'
|
||||
}).addTo(world);
|
||||
|
||||
|
|
|
@ -203,7 +203,7 @@ class World extends EventEmitter {
|
|||
|
||||
this._layers.push(layer);
|
||||
|
||||
if (layer.isOutput()) {
|
||||
if (layer.isOutput() && layer.isOutputToScene()) {
|
||||
// Could move this into Layer but it'll do here for now
|
||||
this._engine._scene.add(layer._object3D);
|
||||
this._engine._domScene3D.add(layer._domObject3D);
|
||||
|
@ -223,7 +223,7 @@ class World extends EventEmitter {
|
|||
this._layers.splice(layerIndex, 1);
|
||||
};
|
||||
|
||||
if (layer.isOutput()) {
|
||||
if (layer.isOutput() && layer.isOutputToScene()) {
|
||||
this._engine._scene.remove(layer._object3D);
|
||||
this._engine._domScene3D.remove(layer._domObject3D);
|
||||
this._engine._domScene2D.remove(layer._domObject2D);
|
||||
|
|
|
@ -23,7 +23,8 @@ class Layer extends EventEmitter {
|
|||
super();
|
||||
|
||||
var defaults = {
|
||||
output: true
|
||||
output: true,
|
||||
outputToScene: true
|
||||
};
|
||||
|
||||
this._options = extend({}, defaults, options);
|
||||
|
@ -109,6 +110,10 @@ class Layer extends EventEmitter {
|
|||
return this._options.output;
|
||||
}
|
||||
|
||||
isOutputToScene() {
|
||||
return this._options.outputToScene;
|
||||
}
|
||||
|
||||
// Destroys the layer and removes it from the scene and memory
|
||||
destroy() {
|
||||
if (this._object3D && this._object3D.children) {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Tile from './Tile';
|
||||
import {geoJSONLayer as GeoJSONLayer} from '../GeoJSONLayer';
|
||||
import BoxHelper from '../../vendor/BoxHelper';
|
||||
import THREE from 'three';
|
||||
import reqwest from 'reqwest';
|
||||
|
@ -56,20 +57,33 @@ class GeoJSONTile extends Tile {
|
|||
this._defaultStyle = GeoJSON.defaultStyle;
|
||||
|
||||
var defaults = {
|
||||
picking: false,
|
||||
output: true,
|
||||
outputToScene: false,
|
||||
interactive: false,
|
||||
topojson: false,
|
||||
filter: null,
|
||||
onClick: null,
|
||||
style: this._defaultStyle
|
||||
onEachFeature: null,
|
||||
polygonMaterial: null,
|
||||
onPolygonMesh: null,
|
||||
onPolygonBufferAttributes: null,
|
||||
polylineMaterial: null,
|
||||
onPolylineMesh: null,
|
||||
onPolylineBufferAttributes: null,
|
||||
pointGeometry: null,
|
||||
pointMaterial: null,
|
||||
onPointMesh: null,
|
||||
style: GeoJSON.defaultStyle
|
||||
};
|
||||
|
||||
this._options = extend({}, defaults, options);
|
||||
var _options = extend({}, defaults, options);
|
||||
|
||||
if (typeof options.style === 'function') {
|
||||
this._options.style = options.style;
|
||||
_options.style = options.style;
|
||||
} else {
|
||||
this._options.style = extend({}, defaults.style, options.style);
|
||||
_options.style = extend({}, defaults.style, options.style);
|
||||
}
|
||||
|
||||
this._options = _options;
|
||||
}
|
||||
|
||||
// Request data for the tile
|
||||
|
@ -79,10 +93,6 @@ class GeoJSONTile extends Tile {
|
|||
if (!this._mesh) {
|
||||
this._mesh = this._createMesh();
|
||||
|
||||
if (this._options.picking) {
|
||||
this._pickingMesh = this._createPickingMesh();
|
||||
}
|
||||
|
||||
// this._shadowCanvas = this._createShadowCanvas();
|
||||
|
||||
this._requestTile();
|
||||
|
@ -90,6 +100,7 @@ class GeoJSONTile extends Tile {
|
|||
}, 0);
|
||||
}
|
||||
|
||||
// TODO: Destroy GeoJSONLayer
|
||||
destroy() {
|
||||
// Cancel any pending requests
|
||||
this._abortRequest();
|
||||
|
@ -97,6 +108,13 @@ class GeoJSONTile extends Tile {
|
|||
// Clear request reference
|
||||
this._request = null;
|
||||
|
||||
if (this._geojsonLayer) {
|
||||
this._geojsonLayer.destroy();
|
||||
this._geojsonLayer = null;
|
||||
}
|
||||
|
||||
this._mesh = null;
|
||||
|
||||
// TODO: Properly dispose of picking mesh
|
||||
this._pickingMesh = null;
|
||||
|
||||
|
@ -113,9 +131,6 @@ class GeoJSONTile extends Tile {
|
|||
|
||||
var mesh = new THREE.Object3D();
|
||||
|
||||
mesh.position.x = this._center[0];
|
||||
mesh.position.z = this._center[1];
|
||||
|
||||
// var geom = new THREE.PlaneBufferGeometry(this._side, this._side, 1);
|
||||
//
|
||||
// var material = new THREE.MeshBasicMaterial({
|
||||
|
@ -135,18 +150,18 @@ class GeoJSONTile extends Tile {
|
|||
return mesh;
|
||||
}
|
||||
|
||||
_createPickingMesh() {
|
||||
if (!this._center) {
|
||||
return;
|
||||
}
|
||||
|
||||
var mesh = new THREE.Object3D();
|
||||
|
||||
mesh.position.x = this._center[0];
|
||||
mesh.position.z = this._center[1];
|
||||
|
||||
return mesh;
|
||||
}
|
||||
// _createPickingMesh() {
|
||||
// if (!this._center) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// var mesh = new THREE.Object3D();
|
||||
//
|
||||
// mesh.position.x = this._center[0];
|
||||
// mesh.position.z = this._center[1];
|
||||
//
|
||||
// return mesh;
|
||||
// }
|
||||
|
||||
_createDebugMesh() {
|
||||
var canvas = document.createElement('canvas');
|
||||
|
@ -185,15 +200,15 @@ class GeoJSONTile extends Tile {
|
|||
return mesh;
|
||||
}
|
||||
|
||||
_createShadowCanvas() {
|
||||
var canvas = document.createElement('canvas');
|
||||
|
||||
// Rendered at a low resolution and later scaled up for a low-quality blur
|
||||
canvas.width = 512;
|
||||
canvas.height = 512;
|
||||
|
||||
return canvas;
|
||||
}
|
||||
// _createShadowCanvas() {
|
||||
// var canvas = document.createElement('canvas');
|
||||
//
|
||||
// // Rendered at a low resolution and later scaled up for a low-quality blur
|
||||
// canvas.width = 512;
|
||||
// canvas.height = 512;
|
||||
//
|
||||
// return canvas;
|
||||
// }
|
||||
|
||||
// _addShadow(coordinates) {
|
||||
// var ctx = this._shadowCanvas.getContext('2d');
|
||||
|
@ -268,339 +283,345 @@ class GeoJSONTile extends Tile {
|
|||
_processTileData(data) {
|
||||
console.time(this._tile);
|
||||
|
||||
var geojson = GeoJSON.collectFeatures(data, this._options.topojson);
|
||||
// Using this creates a huge amount of memory due to the quantity of tiles
|
||||
this._geojsonLayer = GeoJSONLayer(data, this._options).addTo(this._world);
|
||||
|
||||
// TODO: Check that GeoJSON is valid / usable
|
||||
this._mesh = this._geojsonLayer._object3D;
|
||||
this._pickingMesh = this._geojsonLayer._pickingMesh;
|
||||
|
||||
var features = geojson.features;
|
||||
|
||||
// Run filter, if provided
|
||||
if (this._options.filter) {
|
||||
features = geojson.features.filter(this._options.filter);
|
||||
}
|
||||
|
||||
var style = this._options.style;
|
||||
|
||||
var offset = Point(0, 0);
|
||||
offset.x = -1 * this._center[0];
|
||||
offset.y = -1 * this._center[1];
|
||||
|
||||
// TODO: Wrap into a helper method so this isn't duplicated in the non-tiled
|
||||
// GeoJSON output layer
|
||||
// var geojson = GeoJSON.collectFeatures(data, this._options.topojson);
|
||||
//
|
||||
// Need to be careful as to not make it impossible to fork this off into a
|
||||
// worker script at a later stage
|
||||
// // TODO: Check that GeoJSON is valid / usable
|
||||
//
|
||||
// Also unsure as to whether it's wise to lump so much into a black box
|
||||
// var features = geojson.features;
|
||||
//
|
||||
// var meshes = GeoJSON.createMeshes(features, offset, style);
|
||||
|
||||
var polygons = {
|
||||
vertices: [],
|
||||
faces: [],
|
||||
colours: [],
|
||||
facesCount: 0,
|
||||
allFlat: true
|
||||
};
|
||||
|
||||
var lines = {
|
||||
vertices: [],
|
||||
colours: [],
|
||||
verticesCount: 0
|
||||
};
|
||||
|
||||
if (this._options.picking) {
|
||||
polygons.pickingIds = [];
|
||||
lines.pickingIds = [];
|
||||
}
|
||||
|
||||
var colour = new THREE.Color();
|
||||
|
||||
features.forEach(feature => {
|
||||
// feature.geometry, feature.properties
|
||||
|
||||
// Skip features that aren't supported
|
||||
//
|
||||
// TODO: Add support for all GeoJSON geometry types, including Multi...
|
||||
// geometry types
|
||||
if (
|
||||
feature.geometry.type !== 'Polygon' &&
|
||||
feature.geometry.type !== 'LineString' &&
|
||||
feature.geometry.type !== 'MultiLineString'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get style object, if provided
|
||||
if (typeof this._options.style === 'function') {
|
||||
style = extend({}, this._defaultStyle, this._options.style(feature));
|
||||
}
|
||||
|
||||
var coordinates = feature.geometry.coordinates;
|
||||
|
||||
// if (feature.geometry.type === 'LineString') {
|
||||
if (feature.geometry.type === 'LineString') {
|
||||
colour.set(style.lineColor);
|
||||
|
||||
coordinates = coordinates.map(coordinate => {
|
||||
var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
var point = this._layer._world.latLonToPoint(latlon);
|
||||
return [point.x, point.y];
|
||||
});
|
||||
|
||||
var height = 0;
|
||||
|
||||
if (style.lineHeight) {
|
||||
height = this._world.metresToWorld(style.lineHeight, this._pointScale);
|
||||
}
|
||||
|
||||
var linestringAttributes = GeoJSON.lineStringAttributes(coordinates, colour, height);
|
||||
|
||||
lines.vertices.push(linestringAttributes.vertices);
|
||||
lines.colours.push(linestringAttributes.colours);
|
||||
|
||||
if (this._options.picking) {
|
||||
var pickingId = this._layer.getPickingId();
|
||||
|
||||
// Inject picking ID
|
||||
//
|
||||
// TODO: Perhaps handle this within the GeoJSON helper
|
||||
lines.pickingIds.push(pickingId);
|
||||
|
||||
if (this._options.onClick) {
|
||||
// TODO: Find a way to properly remove this listener on destroy
|
||||
this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
this._options.onClick(feature, point2d, point3d, intersects);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lines.verticesCount += linestringAttributes.vertices.length;
|
||||
}
|
||||
|
||||
if (feature.geometry.type === 'MultiLineString') {
|
||||
colour.set(style.lineColor);
|
||||
|
||||
coordinates = coordinates.map(_coordinates => {
|
||||
return _coordinates.map(coordinate => {
|
||||
var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
var point = this._layer._world.latLonToPoint(latlon);
|
||||
return [point.x, point.y];
|
||||
});
|
||||
});
|
||||
|
||||
var height = 0;
|
||||
|
||||
if (style.lineHeight) {
|
||||
height = this._world.metresToWorld(style.lineHeight, this._pointScale);
|
||||
}
|
||||
|
||||
var multiLinestringAttributes = GeoJSON.multiLineStringAttributes(coordinates, colour, height);
|
||||
|
||||
lines.vertices.push(multiLinestringAttributes.vertices);
|
||||
lines.colours.push(multiLinestringAttributes.colours);
|
||||
|
||||
if (this._options.picking) {
|
||||
var pickingId = this._layer.getPickingId();
|
||||
|
||||
// Inject picking ID
|
||||
//
|
||||
// TODO: Perhaps handle this within the GeoJSON helper
|
||||
lines.pickingIds.push(pickingId);
|
||||
|
||||
if (this._options.onClick) {
|
||||
// TODO: Find a way to properly remove this listener on destroy
|
||||
this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
this._options.onClick(feature, point2d, point3d, intersects);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
lines.verticesCount += multiLinestringAttributes.vertices.length;
|
||||
}
|
||||
|
||||
if (feature.geometry.type === 'Polygon') {
|
||||
colour.set(style.color);
|
||||
|
||||
coordinates = coordinates.map(ring => {
|
||||
return ring.map(coordinate => {
|
||||
var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
var point = this._layer._world.latLonToPoint(latlon);
|
||||
return [point.x, point.y];
|
||||
});
|
||||
});
|
||||
|
||||
var height = 0;
|
||||
|
||||
if (style.height) {
|
||||
height = this._world.metresToWorld(style.height, this._pointScale);
|
||||
}
|
||||
|
||||
// Draw footprint on shadow canvas
|
||||
//
|
||||
// TODO: Disabled for the time-being until it can be sped up / moved to
|
||||
// a worker
|
||||
// this._addShadow(coordinates);
|
||||
|
||||
var polygonAttributes = GeoJSON.polygonAttributes(coordinates, colour, height);
|
||||
|
||||
polygons.vertices.push(polygonAttributes.vertices);
|
||||
polygons.faces.push(polygonAttributes.faces);
|
||||
polygons.colours.push(polygonAttributes.colours);
|
||||
|
||||
if (this._options.picking) {
|
||||
var pickingId = this._layer.getPickingId();
|
||||
|
||||
// Inject picking ID
|
||||
//
|
||||
// TODO: Perhaps handle this within the GeoJSON helper
|
||||
polygons.pickingIds.push(pickingId);
|
||||
|
||||
if (this._options.onClick) {
|
||||
// TODO: Find a way to properly remove this listener on destroy
|
||||
this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
this._options.onClick(feature, point2d, point3d, intersects);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (polygons.allFlat && !polygonAttributes.flat) {
|
||||
polygons.allFlat = false;
|
||||
}
|
||||
|
||||
polygons.facesCount += polygonAttributes.faces.length;
|
||||
}
|
||||
});
|
||||
|
||||
// Output shadow canvas
|
||||
//
|
||||
// TODO: Disabled for the time-being until it can be sped up / moved to
|
||||
// a worker
|
||||
|
||||
// var texture = new THREE.Texture(this._shadowCanvas);
|
||||
//
|
||||
// // Silky smooth images when tilted
|
||||
// texture.magFilter = THREE.LinearFilter;
|
||||
// texture.minFilter = THREE.LinearMipMapLinearFilter;
|
||||
//
|
||||
// // TODO: Set this to renderer.getMaxAnisotropy() / 4
|
||||
// texture.anisotropy = 4;
|
||||
//
|
||||
// texture.needsUpdate = true;
|
||||
//
|
||||
// var material;
|
||||
// if (!this._world._environment._skybox) {
|
||||
// material = new THREE.MeshBasicMaterial({
|
||||
// map: texture,
|
||||
// transparent: true,
|
||||
// depthWrite: false
|
||||
// });
|
||||
// } else {
|
||||
// material = new THREE.MeshStandardMaterial({
|
||||
// map: texture,
|
||||
// transparent: true,
|
||||
// depthWrite: false
|
||||
// });
|
||||
// material.roughness = 1;
|
||||
// material.metalness = 0.1;
|
||||
// material.envMap = this._world._environment._skybox.getRenderTarget();
|
||||
// // Run filter, if provided
|
||||
// if (this._options.filter) {
|
||||
// features = geojson.features.filter(this._options.filter);
|
||||
// }
|
||||
//
|
||||
// var geom = new THREE.PlaneBufferGeometry(this._side, this._side, 1);
|
||||
// var mesh = new THREE.Mesh(geom, material);
|
||||
// var style = this._options.style;
|
||||
//
|
||||
// mesh.castShadow = false;
|
||||
// mesh.receiveShadow = false;
|
||||
// mesh.renderOrder = 1;
|
||||
// var offset = Point(0, 0);
|
||||
// offset.x = -1 * this._center[0];
|
||||
// offset.y = -1 * this._center[1];
|
||||
//
|
||||
// mesh.rotation.x = -90 * Math.PI / 180;
|
||||
// // TODO: Wrap into a helper method so this isn't duplicated in the non-tiled
|
||||
// // GeoJSON output layer
|
||||
// //
|
||||
// // Need to be careful as to not make it impossible to fork this off into a
|
||||
// // worker script at a later stage
|
||||
// //
|
||||
// // Also unsure as to whether it's wise to lump so much into a black box
|
||||
// //
|
||||
// // var meshes = GeoJSON.createMeshes(features, offset, style);
|
||||
//
|
||||
// this._mesh.add(mesh);
|
||||
|
||||
var geometry;
|
||||
var material;
|
||||
var mesh;
|
||||
|
||||
// Output lines
|
||||
if (lines.vertices.length > 0) {
|
||||
geometry = Buffer.createLineGeometry(lines, offset);
|
||||
|
||||
material = new THREE.LineBasicMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
linewidth: style.lineWidth,
|
||||
transparent: style.lineTransparent,
|
||||
opacity: style.lineOpacity,
|
||||
blending: style.lineBlending
|
||||
});
|
||||
|
||||
mesh = new THREE.LineSegments(geometry, material);
|
||||
|
||||
if (style.lineRenderOrder !== undefined) {
|
||||
material.depthWrite = false;
|
||||
mesh.renderOrder = style.lineRenderOrder;
|
||||
}
|
||||
|
||||
// TODO: Can a line cast a shadow?
|
||||
// mesh.castShadow = true;
|
||||
|
||||
this._mesh.add(mesh);
|
||||
|
||||
if (this._options.picking) {
|
||||
material = new PickingMaterial();
|
||||
material.side = THREE.BackSide;
|
||||
|
||||
// Make the line wider / easier to pick
|
||||
material.linewidth = style.lineWidth + material.linePadding;
|
||||
|
||||
var pickingMesh = new THREE.LineSegments(geometry, material);
|
||||
this._pickingMesh.add(pickingMesh);
|
||||
}
|
||||
}
|
||||
|
||||
// Output polygons
|
||||
if (polygons.facesCount > 0) {
|
||||
geometry = Buffer.createGeometry(polygons, offset);
|
||||
|
||||
if (!this._world._environment._skybox) {
|
||||
material = new THREE.MeshPhongMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
side: THREE.BackSide
|
||||
});
|
||||
} else {
|
||||
material = new THREE.MeshStandardMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
side: THREE.BackSide
|
||||
});
|
||||
material.roughness = 1;
|
||||
material.metalness = 0.1;
|
||||
material.envMapIntensity = 3;
|
||||
material.envMap = this._world._environment._skybox.getRenderTarget();
|
||||
}
|
||||
|
||||
mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
mesh.castShadow = true;
|
||||
mesh.receiveShadow = true;
|
||||
|
||||
if (polygons.allFlat) {
|
||||
material.depthWrite = false;
|
||||
mesh.renderOrder = 1;
|
||||
}
|
||||
|
||||
this._mesh.add(mesh);
|
||||
|
||||
if (this._options.picking) {
|
||||
material = new PickingMaterial();
|
||||
material.side = THREE.BackSide;
|
||||
|
||||
var pickingMesh = new THREE.Mesh(geometry, material);
|
||||
this._pickingMesh.add(pickingMesh);
|
||||
}
|
||||
}
|
||||
// var polygons = {
|
||||
// vertices: [],
|
||||
// faces: [],
|
||||
// colours: [],
|
||||
// facesCount: 0,
|
||||
// allFlat: true
|
||||
// };
|
||||
//
|
||||
// var lines = {
|
||||
// vertices: [],
|
||||
// colours: [],
|
||||
// verticesCount: 0
|
||||
// };
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// polygons.pickingIds = [];
|
||||
// lines.pickingIds = [];
|
||||
// }
|
||||
//
|
||||
// var colour = new THREE.Color();
|
||||
//
|
||||
// features.forEach(feature => {
|
||||
// // feature.geometry, feature.properties
|
||||
//
|
||||
// // Skip features that aren't supported
|
||||
// //
|
||||
// // TODO: Add support for all GeoJSON geometry types, including Multi...
|
||||
// // geometry types
|
||||
// if (
|
||||
// feature.geometry.type !== 'Polygon' &&
|
||||
// feature.geometry.type !== 'LineString' &&
|
||||
// feature.geometry.type !== 'MultiLineString'
|
||||
// ) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Get style object, if provided
|
||||
// if (typeof this._options.style === 'function') {
|
||||
// style = extend({}, this._defaultStyle, this._options.style(feature));
|
||||
// }
|
||||
//
|
||||
// var coordinates = feature.geometry.coordinates;
|
||||
//
|
||||
// // if (feature.geometry.type === 'LineString') {
|
||||
// if (feature.geometry.type === 'LineString') {
|
||||
// colour.set(style.lineColor);
|
||||
//
|
||||
// coordinates = coordinates.map(coordinate => {
|
||||
// var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
// var point = this._layer._world.latLonToPoint(latlon);
|
||||
// return [point.x, point.y];
|
||||
// });
|
||||
//
|
||||
// var height = 0;
|
||||
//
|
||||
// if (style.lineHeight) {
|
||||
// height = this._world.metresToWorld(style.lineHeight, this._pointScale);
|
||||
// }
|
||||
//
|
||||
// var linestringAttributes = GeoJSON.lineStringAttributes(coordinates, colour, height);
|
||||
//
|
||||
// lines.vertices.push(linestringAttributes.vertices);
|
||||
// lines.colours.push(linestringAttributes.colours);
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// var pickingId = this._layer.getPickingId();
|
||||
//
|
||||
// // Inject picking ID
|
||||
// //
|
||||
// // TODO: Perhaps handle this within the GeoJSON helper
|
||||
// lines.pickingIds.push(pickingId);
|
||||
//
|
||||
// if (this._options.onClick) {
|
||||
// // TODO: Find a way to properly remove this listener on destroy
|
||||
// this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
// this._options.onClick(feature, point2d, point3d, intersects);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// lines.verticesCount += linestringAttributes.vertices.length;
|
||||
// }
|
||||
//
|
||||
// if (feature.geometry.type === 'MultiLineString') {
|
||||
// colour.set(style.lineColor);
|
||||
//
|
||||
// coordinates = coordinates.map(_coordinates => {
|
||||
// return _coordinates.map(coordinate => {
|
||||
// var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
// var point = this._layer._world.latLonToPoint(latlon);
|
||||
// return [point.x, point.y];
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// var height = 0;
|
||||
//
|
||||
// if (style.lineHeight) {
|
||||
// height = this._world.metresToWorld(style.lineHeight, this._pointScale);
|
||||
// }
|
||||
//
|
||||
// var multiLinestringAttributes = GeoJSON.multiLineStringAttributes(coordinates, colour, height);
|
||||
//
|
||||
// lines.vertices.push(multiLinestringAttributes.vertices);
|
||||
// lines.colours.push(multiLinestringAttributes.colours);
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// var pickingId = this._layer.getPickingId();
|
||||
//
|
||||
// // Inject picking ID
|
||||
// //
|
||||
// // TODO: Perhaps handle this within the GeoJSON helper
|
||||
// lines.pickingIds.push(pickingId);
|
||||
//
|
||||
// if (this._options.onClick) {
|
||||
// // TODO: Find a way to properly remove this listener on destroy
|
||||
// this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
// this._options.onClick(feature, point2d, point3d, intersects);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// lines.verticesCount += multiLinestringAttributes.vertices.length;
|
||||
// }
|
||||
//
|
||||
// if (feature.geometry.type === 'Polygon') {
|
||||
// colour.set(style.color);
|
||||
//
|
||||
// coordinates = coordinates.map(ring => {
|
||||
// return ring.map(coordinate => {
|
||||
// var latlon = LatLon(coordinate[1], coordinate[0]);
|
||||
// var point = this._layer._world.latLonToPoint(latlon);
|
||||
// return [point.x, point.y];
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// var height = 0;
|
||||
//
|
||||
// if (style.height) {
|
||||
// height = this._world.metresToWorld(style.height, this._pointScale);
|
||||
// }
|
||||
//
|
||||
// // Draw footprint on shadow canvas
|
||||
// //
|
||||
// // TODO: Disabled for the time-being until it can be sped up / moved to
|
||||
// // a worker
|
||||
// // this._addShadow(coordinates);
|
||||
//
|
||||
// var polygonAttributes = GeoJSON.polygonAttributes(coordinates, colour, height);
|
||||
//
|
||||
// polygons.vertices.push(polygonAttributes.vertices);
|
||||
// polygons.faces.push(polygonAttributes.faces);
|
||||
// polygons.colours.push(polygonAttributes.colours);
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// var pickingId = this._layer.getPickingId();
|
||||
//
|
||||
// // Inject picking ID
|
||||
// //
|
||||
// // TODO: Perhaps handle this within the GeoJSON helper
|
||||
// polygons.pickingIds.push(pickingId);
|
||||
//
|
||||
// if (this._options.onClick) {
|
||||
// // TODO: Find a way to properly remove this listener on destroy
|
||||
// this._world.on('pick-' + pickingId, (point2d, point3d, intersects) => {
|
||||
// this._options.onClick(feature, point2d, point3d, intersects);
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (polygons.allFlat && !polygonAttributes.flat) {
|
||||
// polygons.allFlat = false;
|
||||
// }
|
||||
//
|
||||
// polygons.facesCount += polygonAttributes.faces.length;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // Output shadow canvas
|
||||
// //
|
||||
// // TODO: Disabled for the time-being until it can be sped up / moved to
|
||||
// // a worker
|
||||
//
|
||||
// // var texture = new THREE.Texture(this._shadowCanvas);
|
||||
// //
|
||||
// // // Silky smooth images when tilted
|
||||
// // texture.magFilter = THREE.LinearFilter;
|
||||
// // texture.minFilter = THREE.LinearMipMapLinearFilter;
|
||||
// //
|
||||
// // // TODO: Set this to renderer.getMaxAnisotropy() / 4
|
||||
// // texture.anisotropy = 4;
|
||||
// //
|
||||
// // texture.needsUpdate = true;
|
||||
// //
|
||||
// // var material;
|
||||
// // if (!this._world._environment._skybox) {
|
||||
// // material = new THREE.MeshBasicMaterial({
|
||||
// // map: texture,
|
||||
// // transparent: true,
|
||||
// // depthWrite: false
|
||||
// // });
|
||||
// // } else {
|
||||
// // material = new THREE.MeshStandardMaterial({
|
||||
// // map: texture,
|
||||
// // transparent: true,
|
||||
// // depthWrite: false
|
||||
// // });
|
||||
// // material.roughness = 1;
|
||||
// // material.metalness = 0.1;
|
||||
// // material.envMap = this._world._environment._skybox.getRenderTarget();
|
||||
// // }
|
||||
// //
|
||||
// // var geom = new THREE.PlaneBufferGeometry(this._side, this._side, 1);
|
||||
// // var mesh = new THREE.Mesh(geom, material);
|
||||
// //
|
||||
// // mesh.castShadow = false;
|
||||
// // mesh.receiveShadow = false;
|
||||
// // mesh.renderOrder = 1;
|
||||
// //
|
||||
// // mesh.rotation.x = -90 * Math.PI / 180;
|
||||
// //
|
||||
// // this._mesh.add(mesh);
|
||||
//
|
||||
// var geometry;
|
||||
// var material;
|
||||
// var mesh;
|
||||
//
|
||||
// // Output lines
|
||||
// if (lines.vertices.length > 0) {
|
||||
// geometry = Buffer.createLineGeometry(lines, offset);
|
||||
//
|
||||
// material = new THREE.LineBasicMaterial({
|
||||
// vertexColors: THREE.VertexColors,
|
||||
// linewidth: style.lineWidth,
|
||||
// transparent: style.lineTransparent,
|
||||
// opacity: style.lineOpacity,
|
||||
// blending: style.lineBlending
|
||||
// });
|
||||
//
|
||||
// mesh = new THREE.LineSegments(geometry, material);
|
||||
//
|
||||
// if (style.lineRenderOrder !== undefined) {
|
||||
// material.depthWrite = false;
|
||||
// mesh.renderOrder = style.lineRenderOrder;
|
||||
// }
|
||||
//
|
||||
// // TODO: Can a line cast a shadow?
|
||||
// // mesh.castShadow = true;
|
||||
//
|
||||
// this._mesh.add(mesh);
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// material = new PickingMaterial();
|
||||
// material.side = THREE.BackSide;
|
||||
//
|
||||
// // Make the line wider / easier to pick
|
||||
// material.linewidth = style.lineWidth + material.linePadding;
|
||||
//
|
||||
// var pickingMesh = new THREE.LineSegments(geometry, material);
|
||||
// this._pickingMesh.add(pickingMesh);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Output polygons
|
||||
// if (polygons.facesCount > 0) {
|
||||
// geometry = Buffer.createGeometry(polygons, offset);
|
||||
//
|
||||
// if (!this._world._environment._skybox) {
|
||||
// material = new THREE.MeshPhongMaterial({
|
||||
// vertexColors: THREE.VertexColors,
|
||||
// side: THREE.BackSide
|
||||
// });
|
||||
// } else {
|
||||
// material = new THREE.MeshStandardMaterial({
|
||||
// vertexColors: THREE.VertexColors,
|
||||
// side: THREE.BackSide
|
||||
// });
|
||||
// material.roughness = 1;
|
||||
// material.metalness = 0.1;
|
||||
// material.envMapIntensity = 3;
|
||||
// material.envMap = this._world._environment._skybox.getRenderTarget();
|
||||
// }
|
||||
//
|
||||
// mesh = new THREE.Mesh(geometry, material);
|
||||
//
|
||||
// mesh.castShadow = true;
|
||||
// mesh.receiveShadow = true;
|
||||
//
|
||||
// if (polygons.allFlat) {
|
||||
// material.depthWrite = false;
|
||||
// mesh.renderOrder = 1;
|
||||
// }
|
||||
//
|
||||
// this._mesh.add(mesh);
|
||||
//
|
||||
// if (this._options.picking) {
|
||||
// material = new PickingMaterial();
|
||||
// material.side = THREE.BackSide;
|
||||
//
|
||||
// var pickingMesh = new THREE.Mesh(geometry, material);
|
||||
// this._pickingMesh.add(pickingMesh);
|
||||
// }
|
||||
// }
|
||||
|
||||
this._ready = true;
|
||||
console.timeEnd(this._tile);
|
||||
console.log(`${this._tile}: ${features.length} features`);
|
||||
console.log(`${this._tile}: ${this._geojsonLayer._geojson.features.length} features`);
|
||||
}
|
||||
|
||||
_abortRequest() {
|
||||
|
|
|
@ -95,27 +95,27 @@ class GeoJSONTileLayer extends TileLayer {
|
|||
_createTile(quadcode, layer) {
|
||||
var options = {};
|
||||
|
||||
if (this._options.filter) {
|
||||
options.filter = this._options.filter;
|
||||
}
|
||||
// if (this._options.filter) {
|
||||
// options.filter = this._options.filter;
|
||||
// }
|
||||
//
|
||||
// if (this._options.style) {
|
||||
// options.style = this._options.style;
|
||||
// }
|
||||
//
|
||||
// if (this._options.topojson) {
|
||||
// options.topojson = true;
|
||||
// }
|
||||
//
|
||||
// if (this._options.interactive) {
|
||||
// options.interactive = true;
|
||||
// }
|
||||
//
|
||||
// if (this._options.onClick) {
|
||||
// options.onClick = this._options.onClick;
|
||||
// }
|
||||
|
||||
if (this._options.style) {
|
||||
options.style = this._options.style;
|
||||
}
|
||||
|
||||
if (this._options.topojson) {
|
||||
options.topojson = true;
|
||||
}
|
||||
|
||||
if (this._options.picking) {
|
||||
options.picking = true;
|
||||
}
|
||||
|
||||
if (this._options.onClick) {
|
||||
options.onClick = this._options.onClick;
|
||||
}
|
||||
|
||||
return new GeoJSONTile(quadcode, this._path, layer, options);
|
||||
return new GeoJSONTile(quadcode, this._path, layer, this._options);
|
||||
}
|
||||
|
||||
// Destroys the layer and removes it from the scene and memory
|
||||
|
|
Ładowanie…
Reference in New Issue