Skip to content

Commit 8b41528

Browse files
committed
to reset
1 parent fb8b43a commit 8b41528

File tree

4 files changed

+188
-16
lines changed

4 files changed

+188
-16
lines changed

examples/view_25d_map.html

+135-16
Original file line numberDiff line numberDiff line change
@@ -31,42 +31,155 @@
3131
<script src="../dist/itowns_widgets.js"></script>
3232
<script src="js/GUI/GuiTools.js"></script>
3333
<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+
3479
// Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section)
3580
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');
3681
/* global itowns, setupLoadingScreen, GuiTools, debug */
3782
// # Planar (EPSG:3946) viewer
3883

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;
40107
var viewerDiv;
41108
var view;
42109
var p;
43110
var menuGlobe;
44111
var d;
45112

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(
48115
'EPSG:3946',
49116
1837816.94334, 1847692.32501,
50117
5170036.4587, 5178412.82698);
51118

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+
52131
// `viewerDiv` will contain iTowns' rendering area (`<canvas>`)
53132
viewerDiv = document.getElementById('viewerDiv');
133+
console.log(extent0.center(), extent0.center().as(viewCRS), extent0.as(viewCRS))
54134

135+
const placement = { coord: extent0.center().as(viewCRS), heading: 49.6, range: 6200, tilt: 17 };
55136
// 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 });
57138
setupLoadingScreen(viewerDiv, view);
58139

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
60174
var wmsImagerySource = new itowns.WMSSource({
61-
extent: extent,
175+
extent: extentOrthoLatest,
62176
name: 'ortho_latest',
63177
url: 'https://imagerie.data.grandlyon.com/wms/grandlyon',
64178
version: '1.3.0',
65-
crs: 'EPSG:3946',
179+
crs: viewCRS,
66180
format: 'image/jpeg',
67181
});
68182

69-
// Add a WMS imagery layer
70183
var wmsImageryLayer = new itowns.ColorLayer('wms_imagery', {
71184
updateStrategy: {
72185
type: itowns.STRATEGY_DICHOTOMY,
@@ -77,7 +190,7 @@
77190

78191
view.addLayer(wmsImageryLayer);
79192

80-
// Add a WMS elevation source
193+
// Add a WMS elevation layer
81194
var wmsElevationSource = new itowns.WMSSource({
82195
extent: extent,
83196
url: 'https://imagerie.data.grandlyon.com/wms/grandlyon',
@@ -87,7 +200,6 @@
87200
format: 'image/jpeg',
88201
});
89202

90-
// Add a WMS elevation layer
91203
var wmsElevationLayer = new itowns.ElevationLayer('wms_elevation', {
92204
useColorTextureElevation: true,
93205
colorTextureElevationMinZ: 144,
@@ -97,6 +209,7 @@
97209

98210
view.addLayer(wmsElevationLayer);
99211

212+
// Add a WFS layer for label
100213
var wfsCartoSource = new itowns.WFSSource({
101214
url: 'https://data.geopf.fr/wfs/ows?',
102215
version: '2.0.0',
@@ -134,12 +247,18 @@
134247
// Request redraw
135248
view.notifyChange();
136249

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();
143262
</script>
144263
</body>
145264
</html>

examples/view_3d_map.html

+50
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
<script type="text/javascript">
2828

29+
// Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section)
30+
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');
31+
2932

3033

3134
// ---------- CREATE A GlobeView FOR SUPPORTING DATA VISUALIZATION : ----------
@@ -59,6 +62,53 @@
5962
).then(debugMenu.addLayerGUI.bind(debugMenu));
6063
});
6164

65+
// Define geographic extent: CRS, min/max X, min/max Y
66+
const extent = new itowns.Extent(
67+
'EPSG:3946',
68+
1837816.94334, 1847692.32501,
69+
5170036.4587, 5178412.82698);
70+
71+
var opensmSource = new itowns.TMSSource({
72+
isInverted: true,
73+
url: 'https://tile.openstreetmap.org/${z}/${x}/${y}.png',
74+
networkOptions: { crossOrigin: 'anonymous' },
75+
// extent,
76+
crs: 'EPSG:3857',
77+
attribution: {
78+
name: 'OpenStreetMap',
79+
url: 'http://www.openstreetmap.org/',
80+
},
81+
});
82+
// -> TMS imagery layer
83+
var opensmLayer = new itowns.ColorLayer('OPENSM', {
84+
updateStrategy: {
85+
type: itowns.STRATEGY_DICHOTOMY,
86+
},
87+
source: opensmSource,
88+
});
89+
// view.addLayer(opensmLayer);
90+
91+
// Add a WMS imagery source
92+
var wmsImagerySource = new itowns.WMSSource({
93+
extent: extent,
94+
name: 'ortho_latest',
95+
url: 'https://imagerie.data.grandlyon.com/wms/grandlyon',
96+
version: '1.3.0',
97+
crs: 'EPSG:3946',
98+
format: 'image/jpeg',
99+
});
100+
101+
// Add a WMS imagery layer
102+
var wmsImageryLayer = new itowns.ColorLayer('wms_imagery', {
103+
updateStrategy: {
104+
type: itowns.STRATEGY_DICHOTOMY,
105+
options: {},
106+
},
107+
source: wmsImagerySource,
108+
});
109+
110+
view.addLayer(wmsImageryLayer);
111+
62112

63113

64114
// ---------- DISPLAY A DIGITAL ELEVATION MODEL : ----------

src/Core/Geographic/Crs.js

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function isTms(crs) {
1717
}
1818

1919
function isEpsg(crs) {
20+
if (crs === 'CRS:84') { crs = 'EPSG:4326'; }
2021
return isString(crs) && crs.startsWith('EPSG');
2122
}
2223

@@ -58,6 +59,7 @@ function _unitFromProj4Unit(projunit) {
5859
function toUnit(crs) {
5960
mustBeString(crs);
6061
switch (crs) {
62+
case 'CRS:84' :
6163
case 'EPSG:4326' : return UNIT.DEGREE;
6264
case 'EPSG:4978' : return UNIT.METER;
6365
default: {

src/Core/Geographic/Extent.js

+1
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ globalExtentTMS.set('EPSG:4326', new Extent('EPSG:4326', -180, 180, -90, 90));
745745
const extent3857 = globalExtentTMS.get('EPSG:4326').as('EPSG:3857');
746746
extent3857.clampSouthNorth(extent3857.west, extent3857.east);
747747
globalExtentTMS.set('EPSG:3857', extent3857);
748+
// globalExtentTMS.set('EPSG:3857', new Extent('EPSG:3857', -20037508.3427892, 20037508.3427892, -20037508.3427892, 20037508.3427892));
748749

749750
schemeTiles.set('default', new THREE.Vector2(1, 1));
750751
schemeTiles.set(CRS.tms_3857, schemeTiles.get('default'));

0 commit comments

Comments
 (0)