Commit 9d02301d authored by Clément Igonet's avatar Clément Igonet

Oevrpass for integration.

parent 17be6f0a
......@@ -49,13 +49,12 @@
<!-- <script src="js/loaders/TerrainLoader.js" type="text/javascript"></script> -->
<script src="js/loaders/TileLoader.js" type="text/javascript"></script>
<script src="js/loaders/TerrainLoader.js" type="text/javascript"></script>
<script src="js/loaders/GeojsonLoader.js"></script>
<script src="js/loaders/mapzenGeojsonLoader.js"></script>
<!-- <script src="js/toolbox.js" type="text/javascript"></script> -->
<script src="js/loaders/OverpassJsonLoader.js"></script>
<script src="js/controls/EarthControls.js"></script>
<script src="js/layers/Layer.js"></script>
<script src="js/layers/OsmLayer.js"></script>
<script src="js/layers/BuildingLayer.js"></script>
<!-- <script src="js/layers/BuildingLayer.js"></script> -->
<script src="js/layers/OverpassBuildingLayer.js"></script>
<script src="js/terrains/Terrain.js"></script>
<script src="js/terrains/FlatTerrain.js"></script>
<title>OpenEartView example</title>
......@@ -67,47 +66,29 @@
<script type="text/javascript">
var world = new OpenEarthView.World("osmworld");
// world.updateSceneLazy();
world.addLayer(new OpenEarthView.Layer.OSM(
"OpenStreetMap", [
"https://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
"https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
]));
// world.addLayer(new OpenEarthView.Layer.Building(
// "OpenEarthView", [
// 'http://localhost:8081/3dtile?format=geojson&xtile=${x}&ytile=${y}&zoom=${z}&factor=${f}'
// ]));
// http://localhost:8083/proxycache-geojson?tile=${z},${x},${y}
world.addLayer(new OpenEarthView.Layer.OverpassBuilding(
"Overpass", [
'http://overpass-api.de/api/interpreter'
], {
minZoom: 18
}));
// world.addLayer(new OpenEarthView.Layer.OSM(
// "OpenCycleMap", [
// "https://c.tile.opencyclemap.org/cycle/${z}/${x}/${y}.png"
// ]));
// world.addLayer(new OpenEarthView.Layer.OSM(
// "GoogleMap", [
// "https://mt0.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "https://mt1.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "https://mt2.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "https://mt3.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}"
// ], {
// mapTextureRequest: 10
// }));
// world.addLayer(new OpenEarthView.Layer.OSM(
// "GoogleMap", [
// "http://mt0.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "http://mt1.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "http://mt2.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}",
// "http://mt3.google.com/vt/lyrs=y&x=${x}&y=${y}&z=${z}"
// ], {
// mapTextureRequest: 10
// }));
// world.addLayer(new OpenEarthView.Layer.Elevation(
// "OpenEarthView", [
// 'http://localhost:8084/oevElevation?tile=${z},${x},${y},${lod}'
// ]));
// world.addTerrain(new OpenEarthView.Terrain.FlatTerrain("FlatTerrain"));
// UNESCO
// world.setCenter(2.3057599523656336, 48.849568465379264);
world.addLayer(new OpenEarthView.Layer.OSM( "OpenStreetMap", [ "https://a.tile.openstreetmap.org/${z}/${x}/${y}.png", "https://b.tile.openstreetmap.org/${z}/${x}/${y}.png", "https://c.tile.openstreetmap.org/${z}/${x}/${y}.png" ]));
// LOUVRE
world.setCenter(2.3364709900972684, 48.86045538042749);
// MANHATTAN
// world.setCenter(286.02073690310226, 40.747508647167834);
world.setPosition(2.3364709900972684, 48.86045538042749, 1, 1);
</script>
</body>
......
......@@ -126,6 +126,25 @@ THREE.EarthControls = function(object, domElement, render, coord) {
scope.render();
}
this.setPolarAngle = function(phi) {
spherical.phi = phi;
scope.update();
scope.render();
};
this.setAzimuthalAngle = function(theta) {
spherical.theta = theta;
scope.update();
scope.render();
};
this.setPosition = function(lon, lat, phi, theta) {
longitude = lon;
latitude = lat;
sphericalDelta.phi = phi;
sphericalDelta.theta = theta;
scope.update();
scope.render();
}
this.getPolarAngle = function() {
return spherical.phi;
};
......
var toolbox = OpenEarthView.toolbox;
OpenEarthView.Layer.OverpassBuilding = function(name, urls, options) {
this.name = (name !== undefined) ? name : 'Overpass';
this.minZoom = 17;
if (options !== undefined) {
this.minZoom = (options.minZoom !== undefined) ? options.minZoom : 18;
// console.log('minZoom: ' + this.minZoom);
}
if (OpenEarthViewLayers.hasOwnProperty(name)) {
console.err('Cannot register this already existing layer !');
return;
}
OpenEarthViewLayers[name] = (urls !== undefined) ? urls : [
'http://overpass-api.de/api/interpreter'
];
};
OpenEarthView.Layer.OverpassBuilding.prototype = {
constructor: OpenEarthView.Layer.Building,
type: 'overpassBuilding',
getName: function() {
return this.name
},
getUrl: function(zoom, xtile, ytile) {
var scope = this;
var urls = OpenEarthViewLayers[scope.name];
var urlRandom = urls[
Math.floor(Math.random() * urls.length)];
// Process GPS bounds
minLon = toolbox.tile2long(xtile, zoom);
maxLon = toolbox.tile2long(xtile + 1, zoom);
minLat = toolbox.tile2lat(ytile + 1, zoom);
maxLat = toolbox.tile2lat(ytile, zoom);
var url = urlRandom;
url = url + '?data=[out:json];' +
'((relation["building"](' + minLat + ',' + minLon + ',' + maxLat + ',' + maxLon + ');>;);' +
'(way["building"](' + minLat + ',' + minLon + ',' + maxLat + ',' + maxLon + ');>;););' +
'out center;'
return url;
}
}
This diff is collapsed.
......@@ -102,9 +102,11 @@ OpenEarthView.TileLoader.prototype = {
var textureAliveRequests = scope.textureAliveRequests;
var id = zoom + '/' + xtile + '/' + ytile;
// for (var diff = 0; diff < zoom; diff++) {
for (var diff = 0; diff <= Math.min(5, zoom); diff++) {
var power = Math.pow(2, diff);
var idZoomOther = (+zoom - diff) + '/' + Math.floor(xtile / power) + '/' + Math.floor(ytile / power);
// for (var diff = 0; diff <= Math.min(5, zoom); diff++) {
var preLoaded = false;
for (var zoom_ = +zoom; zoom_ >= Math.max(zoom - 5, 2); zoom_--) {
var power = Math.pow(2, +zoom - +zoom_);
var idZoomOther = (+zoom_) + '/' + Math.floor(xtile / power) + '/' + Math.floor(ytile / power);
// console.log('Looking for texture: ', idZoomOther);
if (textures.hasOwnProperty(idZoomOther)) {
// onLoaded(textures[idZoomOther]);
......@@ -121,9 +123,28 @@ OpenEarthView.TileLoader.prototype = {
tex.needsUpdate = true;
onLoaded(tex);
// return;
preLoaded = true;
break;
}
}
if (!preLoaded) {
if (textures.hasOwnProperty(2)) {
var power = Math.pow(2, +zoom - 2);
var tex = textures[2].clone();
tex.repeat.x = 1 / power;
tex.repeat.y = 1 / power;
var xOffset = xtile - Math.floor(xtile / power) * power
var yOffset = (power - 1) - (ytile - Math.floor(ytile / power) * power);
tex.offset.x = xOffset * tex.repeat.x;
tex.offset.y = yOffset * tex.repeat.y;
tex.needsUpdate = true;
onLoaded(tex);
preLoaded = true;
}
}
// for (var diff = Math.min(zoom - 19, -8); diff < Math.min(zoom - 1, -1); diff++) {
// var power = Math.pow(2, diff);
// var idZoomOther = (+zoom - diff) + '/' + Math.floor(xtile / power) + '/' + Math.floor(ytile / power);
......
......@@ -36,21 +36,23 @@ OpenEarthView.World = function(domElement) {
delete scope.layers["defaultLayer"];
}
scope.layers[openEarthViewLayer.getName()] = openEarthViewLayer;
// for (var xtile = 0; xtile < 4; xtile++) {
// for (var ytile = 0; ytile < 4; ytile++) {
// if (openEarthViewLayer.type === 'tile') {
// tileLoader.tileFactory(
// openEarthViewLayer.getUrl(2, xtile, ytile),
// 2,
// xtile,
// ytile,
// function(texture) {
// // Do nothing
// }
// );
// }
// }
// }
for (var xtile = 0; xtile < 4; xtile++) {
for (var ytile = 0; ytile < 4; ytile++) {
if (openEarthViewLayer.type === 'tile') {
tileLoader.tileFactory(
openEarthViewLayer.getUrl(2, xtile, ytile),
2,
xtile,
ytile,
function(texture) {
// Do nothing
}
);
}
}
}
tileLoader.tileFactory(openEarthViewLayer.getUrl(0, 0, 0), 0, 0, 0);
}
this.terrains = {};
......@@ -88,7 +90,7 @@ OpenEarthView.World = function(domElement) {
this.tileGroup = [];
this.defaultAlti = 150;
this.geojsonLoader = THREE.GeojsonLoader.getSingleton();
this.overpassJsonLoader = THREE.OverpassJsonLoader.getSingleton();
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 100000000);
this.camera.up.set(0, 0, 1);
......@@ -275,30 +277,26 @@ OpenEarthView.World = function(domElement) {
var modulus = (zoom_ > 0) ? Math.pow(2, zoom_) : 0;
for (var atile = minXtile; atile <= maxXtile; atile++) {
for (var btile = minYtile; btile <= maxYtile; btile++) {
var id = '' + zoom_ + '/' + (atile % modulus) + '/' + (btile % modulus);
var id = 'z_' + zoom_ + '_' + (atile % modulus) + "_" + (btile % modulus);
for (var zzz = 1; zzz <= 2; zzz++) {
var zoom__ = (zoom_ - zzz);
var xtile__ = Math.floor((atile % modulus) / Math.pow(2, zzz));
var ytile__ = Math.floor((btile % modulus) / Math.pow(2, zzz));
var idNext = '' + zoom__ + '/' + xtile__ + '/' + ytile__;
var idNext = 'z_' + (zoom_ - zzz) + '_' + Math.floor((atile % modulus) / Math.pow(2, zzz)) + "_" + Math.floor((btile % modulus) / Math.pow(2, zzz));
tiles[idNext] = {};
for (var terrainId in scope.terrains) {
switch (scope.terrains[terrainId].type) {
case 'tile':
tileLoader.tileFactory(
scope.terrains[terrainId].getUrl(zoom__, xtile__, ytile__),
zoom__,
xtile__,
ytile__);
break;
}
}
// for (var terrainId in scope.terrains) {
// switch (scope.terrains[terrainId].type) {
// case 'tile':
// tileLoader.tileFactory(
// scope.terrains[terrainId].getUrl(zoom__, xtile__, ytile__),
// zoom__,
// xtile__,
// ytile__);
// break;
// }
// }
}
if (!tiles.hasOwnProperty(id)) {
var tileSupport = new THREE.Object3D(); //create an empty container
var tileMesh = new THREE.Mesh();
tileSupport.add(tileMesh);
// tileMesh.position.set(0, 0, -10);
if (zoom_ < scope.ZOOM_FLAT) {
var tileEarth = new THREE.Object3D(); //create an empty container
tileEarth.rotation.set(0, (toolbox.tile2long(atile, zoom_) + 180) * Math.PI / 180, 0);
......@@ -365,20 +363,6 @@ OpenEarthView.World = function(domElement) {
opacity: scope.layers[layerId].opacity
});
scope.render();
// (function(zoom, xtile, ytile) {
// if (zoom_ === Math.max(zoomMin - 5, 0) && xtile === scope.xtile && ytile === scope.ytile) {
// tileLoader.tileFactory(
// scope.layers[layerId].getUrl(zoom_, xtile, ytile),
// zoom_,
// xtile,
// ytile
// );
// }
// })(zoom_, atile % modulus, btile % modulus);
//
//
//
tileLoader.tilePreload(
zoom_,
atile % modulus,
......@@ -389,7 +373,6 @@ OpenEarthView.World = function(domElement) {
scope.render();
}
);
(function(tileMesh, zoom, xtile, ytile, layerId) {
var url = scope.layers[layerId].getUrl(
zoom,
......@@ -440,6 +423,38 @@ OpenEarthView.World = function(domElement) {
}
break;
case 'overpassBuilding':
Math.max(scope.zoom - 1, scope.layers[layerId].minZoom)
if (scope.zoom >= 17 && zoom_ >= Math.max(scope.zoom - 1, scope.layers[layerId].minZoom)) {
var id = 'tile_' + zoom_ + '_' + (atile % modulus) + '_' + (btile % modulus) + '_' + scope.layers[layerId].getName();
var defaultColor =
((13 * scope.zoom) % 256) * 65536 +
((53 * (atile % modulus)) % 256) * 256 +
((97 * (btile % modulus)) % 256);
var lod = Math.max(0, zoom_ - 15);
(function(tileSupport, zoom, xtile, ytile, lod, defaultColor) {
var url = scope.layers[layerId].getUrl(
zoom, xtile, ytile);
scope.overpassJsonLoader.load({
z: zoom,
x: xtile,
y: ytile
},
url,
function(obj) {
tileSupport.add(obj);
scope.render();
},
function() {},
function() {},
lod,
defaultColor);
})(tileSupport, zoom_, (atile % modulus), (btile % modulus), lod, defaultColor);
}
break;
default:
break;
......@@ -454,4 +469,7 @@ OpenEarthView.World = function(domElement) {
this.setCenter = function(lon, lat) {
scope.controls.setCenter(lon, lat);
}
this.setPosition = function(lon, lat, phi, theta) {
scope.controls.setPosition(lon, lat, phi, theta);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment