kopia lustrzana https://github.com/robhawkes/vizicities
- Added rivers to Overpass request
- Added fallback Overpass API endpoint - Features change colour depending on type - Refined worker batching process0.1
rodzic
1d0a314229
commit
e16e9a28f3
|
@ -191,11 +191,11 @@
|
|||
|
||||
var deferred = Q.defer();
|
||||
|
||||
var buildingManager = new VIZI.BuildingManager();
|
||||
var objectManager = new VIZI.ObjectManager();
|
||||
this.data.update().then(function(features) {
|
||||
buildingManager.processFeaturesWorker(features).then(function(result) {
|
||||
objectManager.processFeaturesWorker(features).then(function(result) {
|
||||
VIZI.Log("Finished loading Overpass data in " + (Date.now() - startTime) + "ms");
|
||||
deferred.resolve(buildingManager);
|
||||
deferred.resolve(objectManager);
|
||||
}, undefined, function(progress) {
|
||||
// Pass-through progress
|
||||
deferred.notify(progress);
|
||||
|
|
|
@ -8,8 +8,13 @@
|
|||
VIZI.Data.call(this);
|
||||
|
||||
// URL of data source
|
||||
//this.url = "http://overpass-api.de/api/interpreter?data=[out:json];(way[%22building%22]({s},{w},{n},{e});node(w);way[%22building:part%22=%22yes%22]({s},{w},{n},{e});node(w);relation[%22building%22]({s},{w},{n},{e});way(r);node(w););out;";
|
||||
this.url = "http://overpass-api.de/api/interpreter?data=[out:json];(way[%22building%22]({s},{w},{n},{e});node(w));out;";
|
||||
// Good Overpass queries: https://raw2.github.com/bigr/map1/master/import_osm.eu1000
|
||||
// this.url = "http://overpass-api.de/api/interpreter?data=[out:json];(way[%22building%22]({s},{w},{n},{e});node(w);way[%22building:part%22=%22yes%22]({s},{w},{n},{e});node(w);relation[%22building%22]({s},{w},{n},{e});way(r);node(w););out;";
|
||||
// this.url = "http://overpass-api.de/api/interpreter?data=[out:json];(way[%22building%22]({s},{w},{n},{e});node(w));out;";
|
||||
// this.url = "http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];(way[%22building%22]({s},{w},{n},{e});node(w));out;";
|
||||
// this.url = "http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];((rel({s},{w},{n},{e})[waterway~%22riverbank|dock%22];rel({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];rel({s},{w},{n},{e})[natural=%22water%22];);(._;way(r););(._;node(w););(way({s},{w},{n},{e})[waterway~%22riverbank|dock%22];way({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];way({s},{w},{n},{e})[natural=%22water%22];);(._;node(w);););out;";
|
||||
// this.url = "http://overpass-api.de/api/interpreter?data=[out:json];((rel({s},{w},{n},{e})[waterway~%22riverbank|dock%22];rel({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];rel({s},{w},{n},{e})[natural=%22water%22];);(._;way(r););(._;node(w););(way({s},{w},{n},{e})[waterway~%22riverbank|dock%22];way({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];way({s},{w},{n},{e})[natural=%22water%22];);(._;node(w);););out;";
|
||||
this.url = "http://overpass-api.de/api/interpreter?data=[out:json];((rel({s},{w},{n},{e})[waterway~%22riverbank|dock%22];rel({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];rel({s},{w},{n},{e})[natural=%22water%22];);(._;way(r););(._;node(w););(way({s},{w},{n},{e})[%22building%22];way({s},{w},{n},{e})[waterway~%22riverbank|dock%22];way({s},{w},{n},{e})[waterway=%22canal%22][area=%22yes%22];way({s},{w},{n},{e})[natural=%22water%22];);(._;node(w);););out;";
|
||||
};
|
||||
|
||||
VIZI.DataOverpass.prototype = Object.create( VIZI.Data.prototype );
|
||||
|
@ -88,7 +93,7 @@
|
|||
var coordinates = [];
|
||||
var dupe = false;
|
||||
_.each(points, function(point, index) {
|
||||
// Shouldn't duplicate any points apart from first and last
|
||||
// Shouldn"t duplicate any points apart from first and last
|
||||
if (index < pointCount-1 && self.checkDuplicateCoords(coordinates, nodes[point])) {
|
||||
dupe = true;
|
||||
}
|
||||
|
@ -101,27 +106,47 @@
|
|||
return;
|
||||
}
|
||||
|
||||
// Distance conversion
|
||||
// From: https://github.com/kekscom/osmbuildings/blob/master/src/Import.js#L39
|
||||
var height;
|
||||
var scalingFactor = (tags['building'] === "office") ? 1.35 : 1;
|
||||
if (tags.height) {
|
||||
height = self.toMeters(tags.height);
|
||||
} else if (!height && tags['building:height']) {
|
||||
height = self.toMeters(tags['building:height']);
|
||||
} else if (!height && tags.levels) {
|
||||
height = tags.levels * self.METERS_PER_LEVEL * scalingFactor <<0;
|
||||
} else if (!height && tags['building:levels']) {
|
||||
height = tags['building:levels'] * self.METERS_PER_LEVEL * scalingFactor <<0;
|
||||
} else {
|
||||
height = 10 + Math.random() * 10;
|
||||
}
|
||||
|
||||
tags.height = height;
|
||||
tags.height = this.processHeight(tags);
|
||||
tags.colour = this.processColour(tags);
|
||||
|
||||
ways.push({
|
||||
coordinates: coordinates,
|
||||
properties: tags
|
||||
});
|
||||
};
|
||||
|
||||
VIZI.DataOverpass.prototype.processHeight = function(tags) {
|
||||
// Distance conversion
|
||||
// From: https://github.com/kekscom/osmbuildings/blob/master/src/Import.js#L39
|
||||
var height;
|
||||
var scalingFactor = (tags["building"] === "office") ? 1.35 : 1;
|
||||
if (tags.height) {
|
||||
height = this.toMeters(tags.height);
|
||||
} else if (!height && tags["building:height"]) {
|
||||
height = this.toMeters(tags["building:height"]);
|
||||
} else if (!height && tags.levels) {
|
||||
height = tags.levels * this.METERS_PER_LEVEL * scalingFactor <<0;
|
||||
} else if (!height && tags["building:levels"]) {
|
||||
height = tags["building:levels"] * this.METERS_PER_LEVEL * scalingFactor <<0;
|
||||
} else if (tags["waterway"] || tags["natural"]) {
|
||||
height = 0.1;
|
||||
} else {
|
||||
height = 10 + Math.random() * 10;
|
||||
}
|
||||
|
||||
return height;
|
||||
};
|
||||
|
||||
VIZI.DataOverpass.prototype.processColour = function(tags) {
|
||||
var colour;
|
||||
if (tags["building"] || tags["building:part"]) {
|
||||
colour = 0xEEEEEE;
|
||||
} else if (tags["waterway"] || tags["natural"] === "water") {
|
||||
colour = 0x6DCCFF;
|
||||
} else {
|
||||
colour = 0x00FF00;
|
||||
}
|
||||
|
||||
return colour;
|
||||
};
|
||||
}());
|
|
@ -81,10 +81,11 @@
|
|||
} );
|
||||
};
|
||||
|
||||
//var colour = new THREE.Color(0xcccccc);
|
||||
// Default colour
|
||||
var colour = new THREE.Color(0xFF87FC);
|
||||
|
||||
// Use random colour per worker to show grouping of objects
|
||||
var colour = new THREE.Color(0xFFFFFF * Math.random());
|
||||
// var colour = new THREE.Color(0xFFFFFF * Math.random());
|
||||
|
||||
var combinedGeom = new THREE.Geometry();
|
||||
|
||||
|
@ -125,7 +126,8 @@
|
|||
var extrudeSettings = { amount: height, bevelEnabled: false };
|
||||
var geom = new THREE.ExtrudeGeometry( shape, extrudeSettings );
|
||||
|
||||
applyVertexColors( geom, colour );
|
||||
var elementColour = (properties.colour) ? new THREE.Color(properties.colour) : colour;
|
||||
applyVertexColors( geom, elementColour );
|
||||
|
||||
geom.computeFaceNormals();
|
||||
var mesh = new THREE.Mesh(geom);
|
||||
|
@ -192,7 +194,8 @@
|
|||
|
||||
// Batch features
|
||||
// 4 batches or below seems to stop the model.faces typed array from converting to a normal array
|
||||
var batches = 8;
|
||||
// Ideal 8 batches, if odd then subtract difference to make featuresPerBatch division clean
|
||||
var batches = 8 - (features.length % 8);
|
||||
var featuresPerBatch = Math.ceil(features.length / batches);
|
||||
var batchPromises = [];
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue