diff --git a/examples/globe_wfs_extruded.html b/examples/globe_wfs_extruded.html index ba3b8baad9..e4fd5cfad1 100644 --- a/examples/globe_wfs_extruded.html +++ b/examples/globe_wfs_extruded.html @@ -53,67 +53,67 @@ // Add two elevation layers. // These will deform iTowns globe geometry to represent terrain elevation. - promises.push(itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addLayerCb)); - promises.push(itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addLayerCb)); + // promises.push(itowns.Fetcher.json('./layers/JSONLayers/WORLD_DTM.json').then(addLayerCb)); + // promises.push(itowns.Fetcher.json('./layers/JSONLayers/IGN_MNT_HIGHRES.json').then(addLayerCb)); - function altitudeLine(properties, contour) { - var altitudes = []; - var i = 0; - var result; - var tile; - var layer = globeView.wgs84TileLayer; - if (contour.length && contour.length > 0) { - for (; i < contour.length; i++) { - result = itowns.DEMUtils.getElevationValueAt(layer, contour[i], 0, tile); - if (!result) { - result = itowns.DEMUtils.getElevationValueAt(layer, contour[i], 0); - } - tile = [result.tile]; - altitudes.push(result.z + 2); - } - return altitudes; - } - return 0; - } + // function altitudeLine(properties, contour) { + // var altitudes = []; + // var i = 0; + // var result; + // var tile; + // var layer = globeView.wgs84TileLayer; + // if (contour.length && contour.length > 0) { + // for (; i < contour.length; i++) { + // result = itowns.DEMUtils.getElevationValueAt(layer, contour[i], 0, tile); + // if (!result) { + // result = itowns.DEMUtils.getElevationValueAt(layer, contour[i], 0); + // } + // tile = [result.tile]; + // altitudes.push(result.z + 2); + // } + // return altitudes; + // } + // return 0; + // } - function colorLine(properties) { - var rgb = properties.couleur.split(' '); - return new itowns.THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255); - } + // function colorLine(properties) { + // var rgb = properties.couleur.split(' '); + // return new itowns.THREE.Color(rgb[0] / 255, rgb[1] / 255, rgb[2] / 255); + // } - function acceptFeatureBus(properties) { - var line = properties.ligne + properties.sens; - if (linesBus.indexOf(line) === -1) { - linesBus.push(line); - return true; - } - return false; - } + // function acceptFeatureBus(properties) { + // var line = properties.ligne + properties.sens; + // if (linesBus.indexOf(line) === -1) { + // linesBus.push(line); + // return true; + // } + // return false; + // } - globeView.addLayer({ - name: 'lyon_tcl_bus', - type: 'geometry', - update: itowns.FeatureProcessing.update, - convert: itowns.Feature2Mesh.convert({ - color: colorLine, - altitude: altitudeLine }), - linewidth: 5, - filter: acceptFeatureBus, - url: 'https://download.data.grandlyon.com/wfs/rdata?', - protocol: 'wfs', - version: '2.0.0', - id: 'WFS Bus lines', - typeName: 'tcl_sytral.tcllignebus', - level: 9, - projection: 'EPSG:3946', - extent: { - west: 1822174.60, - east: 1868247.07, - south: 5138876.75, - north: 5205890.19, - }, - format: 'geojson', - }); + // globeView.addLayer({ + // name: 'lyon_tcl_bus', + // type: 'geometry', + // update: itowns.FeatureProcessing.update, + // convert: itowns.Feature2Mesh.convert({ + // color: colorLine, + // altitude: altitudeLine }), + // linewidth: 5, + // filter: acceptFeatureBus, + // url: 'https://download.data.grandlyon.com/wfs/rdata?', + // protocol: 'wfs', + // version: '2.0.0', + // id: 'WFS Bus lines', + // typeName: 'tcl_sytral.tcllignebus', + // level: 9, + // projection: 'EPSG:3946', + // extent: { + // west: 1822174.60, + // east: 1868247.07, + // south: 5138876.75, + // north: 5205890.19, + // }, + // format: 'geojson', + // }); function colorBuildings(properties) { if (properties.id.indexOf('bati_remarquable') === 0) { @@ -155,6 +155,7 @@ globeView.addFrameRequester(itowns.MAIN_LOOP_EVENTS.BEFORE_RENDER, scaler); globeView.addLayer({ + id: 'WFS Buildings', type: 'geometry', update: itowns.FeatureProcessing.update, convert: itowns.Feature2Mesh.convert({ @@ -166,69 +167,76 @@ meshes.push(mesh); }, filter: acceptFeature, - url: 'http://wxs.ign.fr/72hpsel8j8nhb5qgdh07gcyp/geoportail/wfs?', - networkOptions: { crossOrigin: 'anonymous' }, - protocol: 'wfs', - version: '2.0.0', - id: 'WFS Buildings', - typeName: 'BDTOPO_BDD_WLD_WGS84G:bati_remarquable,BDTOPO_BDD_WLD_WGS84G:bati_indifferencie,BDTOPO_BDD_WLD_WGS84G:bati_industriel', - level: 14, - projection: 'EPSG:4326', - ipr: 'IGN', - format: 'application/json', + source: { + url: 'http://wxs.ign.fr/72hpsel8j8nhb5qgdh07gcyp/geoportail/wfs?', + networkOptions: { crossOrigin: 'anonymous' }, + protocol: 'wfs', + version: '2.0.0', + typeName: 'BDTOPO_BDD_WLD_WGS84G:bati_remarquable,BDTOPO_BDD_WLD_WGS84G:bati_indifferencie,BDTOPO_BDD_WLD_WGS84G:bati_industriel', + zoom: { min: 14, max: 14 }, + projection: 'EPSG:4326', + ipr: 'IGN', + format: 'application/json', + extent: { + west: 4.568, + east: 5.18, + south: 45.437, + north: 46.03, + }, + } }); - function configPointMaterial(result) { - var i = 0; - var mesh; - for (; i < result.children.length; i++) { - mesh = result.children[i]; + // function configPointMaterial(result) { + // var i = 0; + // var mesh; + // for (; i < result.children.length; i++) { + // mesh = result.children[i]; - mesh.material.sizeAttenuation = false; - } - } + // mesh.material.sizeAttenuation = false; + // } + // } - function colorPoint(/* properties */) { - return new itowns.THREE.Color(0x7F180D); - } + // function colorPoint(/* properties */) { + // return new itowns.THREE.Color(0x7F180D); + // } - function selectRoad(properties) { - return properties.gestion === 'CEREMA'; - } + // function selectRoad(properties) { + // return properties.gestion === 'CEREMA'; + // } - function altitudePoint(properties, contour) { - var result; - var z = 0; - if (contour.length && contour.length > 0) { - result = itowns.DEMUtils.getElevationValueAt(globeView.wgs84TileLayer, contour[0]); - if (result) { - z = result.z; - } - return z + 5; - } - return 0; - } + // function altitudePoint(properties, contour) { + // var result; + // var z = 0; + // if (contour.length && contour.length > 0) { + // result = itowns.DEMUtils.getElevationValueAt(globeView.wgs84TileLayer, contour[0]); + // if (result) { + // z = result.z; + // } + // return z + 5; + // } + // return 0; + // } - globeView.addLayer({ - type: 'geometry', - update: itowns.FeatureProcessing.update, - convert: itowns.Feature2Mesh.convert({ - altitude: altitudePoint, - color: colorPoint }), - size: 5, - onMeshCreated: configPointMaterial, - filter: selectRoad, - url: 'http://wxs.ign.fr/72hpsel8j8nhb5qgdh07gcyp/geoportail/wfs?', - networkOptions: { crossOrigin: 'anonymous' }, - protocol: 'wfs', - version: '2.0.0', - id: 'WFS Route points', - typeName: 'BDPR_BDD_FXX_LAMB93_20170911:pr', - level: 12, - projection: 'EPSG:2154', - ipr: 'IGN', - format: 'application/json', - }); + // globeView.addLayer({ + // type: 'geometry', + // update: itowns.FeatureProcessing.update, + // convert: itowns.Feature2Mesh.convert({ + // altitude: altitudePoint, + // color: colorPoint }), + // size: 5, + // onMeshCreated: configPointMaterial, + // filter: selectRoad, + // url: 'http://wxs.ign.fr/72hpsel8j8nhb5qgdh07gcyp/geoportail/wfs?', + // networkOptions: { crossOrigin: 'anonymous' }, + // protocol: 'wfs', + // version: '2.0.0', + // id: 'WFS Route points', + // typeName: 'BDPR_BDD_FXX_LAMB93_20170911:pr', + // level: 12, + // projection: 'EPSG:2154', + // ipr: 'IGN', + // format: 'application/json', + // }); var menuGlobe = new GuiTools('menuDiv', globeView); // Listen for globe full initialisation event @@ -266,12 +274,12 @@ } for (let layer of globeView.getLayers()) { - if (layer.id === 'WFS Bus lines') { - layer.whenReady.then( function _(layer) { - var gui = debug.GeometryDebug.createGeometryDebugUI(menuGlobe.gui, globeView, layer); - debug.GeometryDebug.addMaterialLineWidth(gui, globeView, layer, 1, 10); - }); - } + // if (layer.id === 'WFS Bus lines') { + // layer.whenReady.then( function _(layer) { + // var gui = debug.GeometryDebug.createGeometryDebugUI(menuGlobe.gui, globeView, layer); + // debug.GeometryDebug.addMaterialLineWidth(gui, globeView, layer, 1, 10); + // }); + // } if (layer.id === 'WFS Buildings') { layer.whenReady.then( function _(layer) { var gui = debug.GeometryDebug.createGeometryDebugUI(menuGlobe.gui, globeView, layer); @@ -279,12 +287,12 @@ window.addEventListener('mousemove', picking, false); }); } - if (layer.id === 'WFS Route points') { - layer.whenReady.then( function _(layer) { - var gui = debug.GeometryDebug.createGeometryDebugUI(menuGlobe.gui, globeView, layer); - debug.GeometryDebug.addMaterialSize(gui, globeView, layer, 1, 50); - }); - } + // if (layer.id === 'WFS Route points') { + // layer.whenReady.then( function _(layer) { + // var gui = debug.GeometryDebug.createGeometryDebugUI(menuGlobe.gui, globeView, layer); + // debug.GeometryDebug.addMaterialSize(gui, globeView, layer, 1, 50); + // }); + // } } diff --git a/src/Process/FeatureProcessing.js b/src/Process/FeatureProcessing.js index d9f9f05d5b..e146fe8a39 100644 --- a/src/Process/FeatureProcessing.js +++ b/src/Process/FeatureProcessing.js @@ -31,6 +31,9 @@ function applyOffset(obj, offset, quaternion, offsetAltitude) { obj.children.forEach(c => applyOffset(c, offset, quaternion, offsetAltitude)); } +const tileInsideLimit = (node, source, parent, pitch) => + source.extentInsideLimit(node.getCoordsForLayer(source), node.level, node.level, parent, pitch); + const quaternion = new THREE.Quaternion(); export default { update(context, layer, node) { @@ -64,7 +67,9 @@ export default { return features; } - if (!layer.tileInsideLimit(node, layer)) { + const extents = []; + const pitchs = []; + if (!tileInsideLimit(node, layer.source, extents, pitchs)) { return; } @@ -82,6 +87,7 @@ export default { const command = { layer, + extents, view: context.view, threejsLayer: layer.threejsLayer, requester: node,