|
31 | 31 | <script src="../dist/itowns_widgets.js"></script>
|
32 | 32 | <script src="js/GUI/GuiTools.js"></script>
|
33 | 33 | <script type="text/javascript">
|
| 34 | + |
| 35 | + function xml2json(xml) { |
| 36 | + try { |
| 37 | + var obj = {}; |
| 38 | + if (xml.children.length > 0) { |
| 39 | + for (var i = 0; i < xml.children.length; i++) { |
| 40 | + var item = xml.children.item(i); |
| 41 | + var nodeName = item.nodeName; |
| 42 | + if (item.attributes.length > 1) { |
| 43 | + for (var j = 0; j < item.attributes.length; j++) { |
| 44 | + const attribute = item.attributes.item(j); |
| 45 | + const newEl = document.createElement(attribute.name); |
| 46 | + const newText = document.createTextNode(attribute.value); |
| 47 | + newEl.appendChild(newText); |
| 48 | + item.appendChild(newEl) |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + if (typeof (obj[nodeName]) == "undefined") { |
| 53 | + obj[nodeName] = xml2json(item); |
| 54 | + } else { |
| 55 | + if (typeof (obj[nodeName].push) == "undefined") { |
| 56 | + var old = obj[nodeName]; |
| 57 | + |
| 58 | + obj[nodeName] = []; |
| 59 | + obj[nodeName].push(old); |
| 60 | + } |
| 61 | + obj[nodeName].push(xml2json(item)); |
| 62 | + } |
| 63 | + } |
| 64 | + } else { |
| 65 | + obj = xml.textContent; |
| 66 | + } |
| 67 | + return obj; |
| 68 | + } catch (e) { |
| 69 | + console.log(e.message); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + const urlWMS = 'https://imagerie.data.grandlyon.com/wms/grandlyon?'; |
| 74 | + const getCapabilities = itowns.Fetcher.xml(`${urlWMS}SERVICE=WMS&REQUEST=GetCapabilities`) |
| 75 | + .then(xml => { |
| 76 | + return xml2json(xml); |
| 77 | + }); |
| 78 | + |
34 | 79 | // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section)
|
35 | 80 | itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
|
36 | 81 | /* global itowns, setupLoadingScreen, GuiTools, debug */
|
37 | 82 | // # Planar (EPSG:3946) viewer
|
38 | 83 |
|
39 |
| - var extent; |
| 84 | + itowns.proj4.defs('CRS:84', itowns.proj4.defs('EPSG:4326')); |
| 85 | + |
| 86 | + async function main() { |
| 87 | + |
| 88 | + let viewCRS; |
| 89 | + viewCRS = 'EPSG:3946'; |
| 90 | + // viewCRS = 'CRS:84'; |
| 91 | + // viewCRS = 'EPSG:3857'; |
| 92 | + |
| 93 | + const capabilities = await getCapabilities; |
| 94 | + console.log(capabilities); |
| 95 | + console.log(capabilities.WMS_Capabilities.Capability.Layer); |
| 96 | + |
| 97 | + const ortho_latest_Capa = capabilities.WMS_Capabilities.Capability.Layer.Layer.filter(l => l.Name === 'ortho_latest')[0]; |
| 98 | + console.log('Ortho_latest crs', ortho_latest_Capa.CRS); |
| 99 | + const boundingBox = ortho_latest_Capa.BoundingBox.filter(bb => bb.crs === viewCRS)[0]; |
| 100 | + const extentOrthoLatest = new itowns.Extent( |
| 101 | + viewCRS, |
| 102 | + +boundingBox.minx, +boundingBox.maxx, |
| 103 | + +boundingBox.miny, +boundingBox.maxy, |
| 104 | + ); |
| 105 | + |
| 106 | + var extent0; |
40 | 107 | var viewerDiv;
|
41 | 108 | var view;
|
42 | 109 | var p;
|
43 | 110 | var menuGlobe;
|
44 | 111 | var d;
|
45 | 112 |
|
46 |
| - // Define geographic extent: CRS, min/max X, min/max Y |
47 |
| - extent = new itowns.Extent( |
| 113 | + // origin extent (the data to display) |
| 114 | + extent0 = new itowns.Extent( |
48 | 115 | 'EPSG:3946',
|
49 | 116 | 1837816.94334, 1847692.32501,
|
50 | 117 | 5170036.4587, 5178412.82698);
|
51 | 118 |
|
| 119 | + // EPSG:3946 global extent |
| 120 | + extent = new itowns.Extent( |
| 121 | + 'EPSG:3946', |
| 122 | + 621509.63, 4660562.44, |
| 123 | + 2320724.18, 5891430.09, |
| 124 | + ); |
| 125 | + |
| 126 | + extent84 = new itowns.Extent('CRS:84', -180, 180, -90, 90) |
| 127 | + |
| 128 | + console.log(extent, extent0, extentOrthoLatest); |
| 129 | + |
| 130 | + |
52 | 131 | // `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
|
53 | 132 | viewerDiv = document.getElementById('viewerDiv');
|
| 133 | + console.log(extent0.center(), extent0.center().as(viewCRS), extent0.as(viewCRS)) |
54 | 134 |
|
| 135 | + const placement = { coord: extent0.center().as(viewCRS), heading: 49.6, range: 6200, tilt: 17 }; |
55 | 136 | // Instanciate PlanarView*
|
56 |
| - view = new itowns.PlanarView(viewerDiv, extent, { placement: { heading: 49.6, range: 6200, tilt: 17 } }); |
| 137 | + view = new itowns.PlanarView(viewerDiv, extent0, { placement }); |
57 | 138 | setupLoadingScreen(viewerDiv, view);
|
58 | 139 |
|
59 |
| - // Add a WMS imagery source |
| 140 | + |
| 141 | + //WMTS |
| 142 | + // itowns.Fetcher.json("./layers/JSONLayers/Ortho.json").then( |
| 143 | + // function _(config) { |
| 144 | + // config.source = new itowns.WMTSSource(config.source); |
| 145 | + // // crs: 'EPSG:3857', |
| 146 | + // var layer = new itowns.ColorLayer("Ortho", config); |
| 147 | + // view.addLayer(layer); |
| 148 | + // } |
| 149 | + // ); |
| 150 | + |
| 151 | + |
| 152 | + // -> TMS imagery source and layer |
| 153 | + // var opensmSource = new itowns.TMSSource({ |
| 154 | + // isInverted: true, |
| 155 | + // url: 'https://tile.openstreetmap.org/${z}/${x}/${y}.png', |
| 156 | + // networkOptions: { crossOrigin: 'anonymous' }, |
| 157 | + // extent: extent0, |
| 158 | + // crs: 'EPSG:3857', |
| 159 | + // attribution: { |
| 160 | + // name: 'OpenStreetMap', |
| 161 | + // url: 'http://www.openstreetmap.org/', |
| 162 | + // }, |
| 163 | + // }); |
| 164 | + // var opensmLayer = new itowns.ColorLayer('OPENSM', { |
| 165 | + // updateStrategy: { |
| 166 | + // type: itowns.STRATEGY_DICHOTOMY, |
| 167 | + // }, |
| 168 | + // source: opensmSource, |
| 169 | + // }); |
| 170 | + // view.addLayer(opensmLayer); |
| 171 | + |
| 172 | + |
| 173 | + // Add a WMS imagery layer |
60 | 174 | var wmsImagerySource = new itowns.WMSSource({
|
61 |
| - extent: extent, |
| 175 | + extent: extentOrthoLatest, |
62 | 176 | name: 'ortho_latest',
|
63 | 177 | url: 'https://imagerie.data.grandlyon.com/wms/grandlyon',
|
64 | 178 | version: '1.3.0',
|
65 |
| - crs: 'EPSG:3946', |
| 179 | + crs: viewCRS, |
66 | 180 | format: 'image/jpeg',
|
67 | 181 | });
|
68 | 182 |
|
69 |
| - // Add a WMS imagery layer |
70 | 183 | var wmsImageryLayer = new itowns.ColorLayer('wms_imagery', {
|
71 | 184 | updateStrategy: {
|
72 | 185 | type: itowns.STRATEGY_DICHOTOMY,
|
|
77 | 190 |
|
78 | 191 | view.addLayer(wmsImageryLayer);
|
79 | 192 |
|
80 |
| - // Add a WMS elevation source |
| 193 | + // Add a WMS elevation layer |
81 | 194 | var wmsElevationSource = new itowns.WMSSource({
|
82 | 195 | extent: extent,
|
83 | 196 | url: 'https://imagerie.data.grandlyon.com/wms/grandlyon',
|
|
87 | 200 | format: 'image/jpeg',
|
88 | 201 | });
|
89 | 202 |
|
90 |
| - // Add a WMS elevation layer |
91 | 203 | var wmsElevationLayer = new itowns.ElevationLayer('wms_elevation', {
|
92 | 204 | useColorTextureElevation: true,
|
93 | 205 | colorTextureElevationMinZ: 144,
|
|
97 | 209 |
|
98 | 210 | view.addLayer(wmsElevationLayer);
|
99 | 211 |
|
| 212 | + // Add a WFS layer for label |
100 | 213 | var wfsCartoSource = new itowns.WFSSource({
|
101 | 214 | url: 'https://data.geopf.fr/wfs/ows?',
|
102 | 215 | version: '2.0.0',
|
|
134 | 247 | // Request redraw
|
135 | 248 | view.notifyChange();
|
136 | 249 |
|
137 |
| - if (view.isDebugMode) { |
138 |
| - menuGlobe = new GuiTools('menuDiv', view); |
139 |
| - menuGlobe.addImageryLayersGUI(view.getLayers(function gui(l) { return l.isColorLayer; })); |
140 |
| - menuGlobe.addElevationLayerGUI(wmsElevationLayer); |
141 |
| - debug.createTileDebugUI(menuGlobe.gui, view); |
142 |
| - } |
| 250 | + view.addEventListener(itowns.GLOBE_VIEW_EVENTS.GLOBE_INITIALIZED, function () { |
| 251 | + if (view.isDebugMode) { |
| 252 | + menuGlobe = new GuiTools('menuDiv', view); |
| 253 | + // console.log(view.getLayers(function gui(l) { return l.isColorLayer; })); |
| 254 | + menuGlobe.addImageryLayersGUI(view.getLayers(function gui(l) { return l.isColorLayer; })); |
| 255 | + // menuGlobe.addElevationLayerGUI(wmsElevationLayer); |
| 256 | + debug.createTileDebugUI(menuGlobe.gui, view); |
| 257 | + } |
| 258 | + }); |
| 259 | + }; |
| 260 | + |
| 261 | + main(); |
143 | 262 | </script>
|
144 | 263 | </body>
|
145 | 264 | </html>
|
0 commit comments