-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
183 lines (167 loc) · 5.35 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import Overlay from 'ol/Overlay';
import WMTS from 'ol/source/WMTS';
import { fromLonLat, get as getProjection } from 'ol/proj';
import WMTSTileGrid from 'ol/tilegrid/WMTS';
import { getWidth } from 'ol/extent';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON';
import { tile as tileStrategy } from 'ol/loadingstrategy';
import VectorLayer from 'ol/layer/Vector';
import { Stroke, Style, Fill } from 'ol/style';
import materiaux_mur from './dmatgm.json';
import materiaux_toit from './dmatto.json';
import { Services, olExtended } from 'geoportal-extensions-openlayers';
function createMap() {
// Infobulle
const container = document.getElementById('popup');
const content = document.getElementById('popup-content');
const closer = document.getElementById('popup-closer');
const toPrint = [
'altitude_maximale_sol', 'altitude_maximale_toit',
'altitude_minimale_sol', 'altitude_minimale_toit',
'construction_legere', 'date_d_apparition', 'etat_de_l_objet',
'hauteur', 'materiaux_de_la_toiture', 'materiaux_des_murs',
'nature', 'nombre_d_etages', 'nombre_de_logements', 'usage_1', 'usage_2',
];
const overlay = new Overlay({
element: container,
autoPan: true,
autoPanAnimation: {
duration: 250,
},
});
closer.onclick = function () {
overlay.setPosition(undefined);
closer.blur();
return false;
};
// Définition de la pyramide de résolution Géoportail
const resolutions = [];
const matrixIds = [];
const proj3857 = getProjection('EPSG:3857');
const maxResolution = getWidth(proj3857.getExtent()) / 256;
for (let i = 0; i < 19; i++) {
matrixIds[i] = i.toString();
resolutions[i] = maxResolution / Math.pow(2, i);
}
const tileGrid = new WMTSTileGrid({
origin: [ -20037508, 20037508 ],
resolutions: resolutions,
matrixIds: matrixIds,
});
// Objets WFS Batiments
const vectorSource = new VectorSource({
format: new GeoJSON(),
url: function (extent) {
return (
'https://wxs.ign.fr/essentiels/geoportail/wfs?service=WFS&' +
'version=1.1.0&request=GetFeature&typename=BDTOPO_V3:batiment&' +
'outputFormat=application/json&srsname=EPSG:3857&' +
'bbox=' + extent.join(',') + ',EPSG:3857'
);
},
strategy: tileStrategy(tileGrid),
});
const wfs = new VectorLayer({
source: vectorSource,
style: new Style({
stroke: new Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2,
}),
fill: new Fill({
color: 'rgba(0, 0, 255, 0.2)',
}),
}),
minZoom: 16,
});
// Couche WMTS PLAN IGN v2
const rasterSource1 = new WMTS({
url: 'https://wxs.ign.fr/essentiels/geoportail/wmts',
layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2',
format: 'image/png',
matrixSet: 'PM',
projection: 'EPSG:3857',
tileGrid: tileGrid,
style: 'normal',
attributions:
'<a href="https://www.ign.fr" target="_blank">' +
'<img src="https://wxs.ign.fr/static/logos/IGN/IGN.gif" title="Institut national de l\'' +
'information géographique et forestière" alt="IGN"></a>',
});
const wmts1 = new TileLayer({
source: rasterSource1,
maxZoom: 16,
});
// Couche WMTS ORTHO PHOTO
const rasterSource2 = new WMTS({
url: 'https://wxs.ign.fr/essentiels/geoportail/wmts',
layer: 'ORTHOIMAGERY.ORTHOPHOTOS',
format: 'image/jpeg',
matrixSet: 'PM',
projection: 'EPSG:3857',
tileGrid: tileGrid,
style: 'normal',
attributions:
'<a href="https://www.ign.fr" target="_blank">' +
'<img src="https://wxs.ign.fr/static/logos/IGN/IGN.gif" title="Institut national de l\'' +
'information géographique et forestière" alt="IGN"></a>',
});
const wmts2 = new TileLayer({
source: rasterSource2,
minZoom: 16,
});
// Map OpenLayers
const map = new Map({
layers: [ wmts1, wmts2, wfs ],
overlays: [ overlay ],
target: document.getElementById('map'),
view: new View({
center: fromLonLat([ 3.280578, 47.368489 ]),
maxZoom: 20,
zoom: 19,
}),
});
const search = new olExtended.control.SearchEngine({
collapsed: false,
displayAdvancedSearch: false
});
map.addControl(search);
// Ouverture infobulle
map.on('singleclick', function (evt) {
const coordinate = evt.coordinate;
const feature = map.forEachFeatureAtPixel(evt.pixel,
function (feature) {
return feature;
});
if (feature) {
const props = feature.getProperties();
const id = feature.getId().replace('batiment.', '');
let liste = '<center><b>' + id + '</b></center>';
liste += '<ul>';
for (const p in props) {
if (props[p] && toPrint.includes(p)) {
let value = props[p];
if (p === 'materiaux_des_murs') value = materiaux_mur[props[p]];
if (p === 'materiaux_de_la_toiture') value = materiaux_toit[props[p]];
if (value === 'INDETERMINE' || value === false) continue;
liste += '<li><b>' + p + '</b> : ' + value + '</li>';
}
}
liste += '</ul>';
content.innerHTML = liste;
overlay.setPosition(coordinate);
}
});
}
Services.getConfig({
apiKey : 'essentiels',
timeOut : 20000,
onSuccess : createMap,
serverUrl: 'autoconf-https.json',
callbackSuffix : '',
});