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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Pyramide écran avec ROK4</title>
<!-- Library OpenLayers 6.5.0 -->
<link rel="stylesheet" href="http://localhost/v6.5.0-dist/ol.css" />
<script src="http://localhost/v6.5.0-dist/ol.js"></script>
<script src="http://localhost/ressources/ol-mapbox-style-6.3.2/ol-mapbox-style-master/src/olms.js"></script>
<script src="http://localhost/ressources/jquery-2.2.4.min.js"></script>
<!-- Library Extension Géoportail pour OpenLayers 3.0.14 -->
<link rel="stylesheet" href="http://localhost/ressources/GpPluginOpenLayers-3.0.14/GpPluginOpenLayers.css" type="text/css">
<script src="http://localhost/ressources/GpPluginOpenLayers-3.0.14/GpPluginOpenLayers.js"></script>
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
font-family: sans-serif;
}
/****** Page d'accueil *****/
h2 {
margin-top: 50px;
margin-bottom: 50px;
text-align: center;
font-size: 30px;
}
body.accueil {
width: 100%;
height: 100%;
padding-top: 100px;
background-image: url("../images/fond.png");
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
a.accueil-lien {
display: block;
margin: 20px auto 20px auto;
width: 40%;
min-width: 500px;
text-align: center;
font-size: 20px;
font-weight: bold;
color: white;
border-radius: 5px;
display:block;
line-height:50px;
text-decoration: none;
background-color: #70777a;
}
a.accueil-lien:link{
color: white;
}
a.accueil-lien:visited{
color: white;
}
a.accueil-lien:hover{
color: white;
font-weight: bold;
font-size: 22px;
background-color: #94c01a;
}
a.accueil-lien:active{
color: white;
font-weight: bold;
font-size: 22px;
background-color: #94c01a;
}
/****** Carte *****/
#map {
width: 100%;
height: 100%;
}
#infos {
border-radius: 5px;
position: fixed;
padding: 10px;
bottom: 10px;
left: 10px;
display: none;
max-height: 50%;
background-color: rgba(255, 255, 255, 0.7);
z-index: 10000;
overflow: auto;
}
#zoomlevel {
position: fixed;
text-align: center;
top: 70px;
left: 18px;
height: 100%;
font-size: 20;
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
/* Infos au clic */
#infos h5 {
margin: 15px auto 2px auto;
text-align: center;
color: rgb(100, 150, 0);
}
#infos ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#infos li {
margin: 0px;
}
#croix {
color: rgb(100, 150, 0);
font-weight: bold;
position: absolute;
font-size: larger;
top: 0px;
right: 5px;
cursor: pointer;
}
/* Openlayers controls buttons */
.ol-rotate {
top: 4.5em;
left: .5em;
right: auto;
}
.ol-zoom {
top: .5em;
left: .5em;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="infos"></div>
<div id="zoomlevel"></div>
<script>
function go() {
/************************* CARTE PRINCIPALE *************************/
var layers = [];
var stamenLayer = new ol.layer.Tile({
title: "Fond de carte",
description: "Stamen maps - Water color",
visible: false,
source: new ol.source.Stamen({
layer: 'watercolor'
})
});
layers.push(stamenLayer);
var planignLayer = new ol.layer.VectorTile({
title: "Plan IGN",
description: "Plan IGN Vecteur tuilé",
mapboxStyleUrl: "https://wxs.ign.fr/[ma clé géoservices]/static/vectorTiles/styles/PLAN.IGN/standard.json",
mapboxStyleSource: "plan_ign",
// gris.json
// sans_toponymes.json
// transparent.json
// accentue.json
// attenue.json
// classique.json
// epure.json
visible: true,
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://wxs.ign.fr/[ma clé géoservices]/geoportail/tms/1.0.0/PLAN.IGN/{z}/{x}/{y}.pbf"
}),
declutter: true,
attributions: '<a href="https://geoservices.ign.fr/documentation/geoservices/vecteur-tuile.html">© IGN</a>',
});
layers.push(planignLayer);
var schapiLayer = new ol.layer.VectorTile({
title: "SCHAPI",
description: "SCHAPI Vecteur tuilé",
mapboxStyleUrl: "https://vectortiles.ign.fr/styles/schapi.json",
mapboxStyleSource: "schapi",
visible: true,
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://vectortiles.ign.fr/rok4server/1.0.0/SCHAPI_TERR_TR_STA/{z}/{x}/{y}.pbf"
}),
declutter: true,
attributions: '<a href="https://fr.wikipedia.org/wiki/Service_central_d%27hydrom%C3%A9t%C3%A9orologie_et_d%27appui_%C3%A0_la_pr%C3%A9vision_des_inondations">SCHAPI</a>',
});
layers.push(schapiLayer);
var pciAriegeLayer = new ol.layer.VectorTile({
title: "PCI_RURAL",
description: "PCI Vecteur tuilé test",
mapboxStyleUrl: "https://vectortiles.ign.fr/styles/pci.json",
mapboxStyleSource: "pci",
visible: true,
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://vectortiles.ign.fr/rok4server/1.0.0/PCI_RURAL/{z}/{x}/{y}.pbf"
}),
declutter: true,
attributions: '<a href="https://geoservices.ign.fr/blog/2018/11/13/lancement_PCI.html">PCI</a>',
});
layers.push(pciAriegeLayer);
var bdtopoAriegeBatiLayer = new ol.layer.VectorTile({
title: "BDTOPO_ARIEGE_BATI",
description: "BDTOPO Vecteur tuilé test",
mapboxStyleUrl: "https://vectortiles.ign.fr/styles/bati.json",
mapboxStyleSource: "bdtopo",
visible: true,
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://vectortiles.ign.fr/rok4server/1.0.0/BDTOPO_BATI_ARIEGE/{z}/{x}/{y}.pbf"
}),
declutter: true,
attributions: '<a href="https://geoservices.ign.fr/blog/2020/10/26/Grand_angle_diffusion_BDTOPO.html">BDTOPO</a>',
});
layers.push(bdtopoAriegeBatiLayer);
var bdtopoAriegeLayer = new ol.layer.VectorTile({
title: "BDTOPO_ARIEGE",
description: "BDTOPO Vecteur tuilé test",
mapboxStyleUrl: "https://vectortiles.ign.fr/styles/",
mapboxStyleSource: "bdtopo",
visible: true,
source: new ol.source.VectorTile({
format: new ol.format.MVT(),
url: "https://vectortiles.ign.fr/rok4server/1.0.0/BDTOPO_ARIEGE/{z}/{x}/{y}.pbf"
}),
declutter: true,
attributions: '<a href="https://geoservices.ign.fr/blog/2020/10/26/Grand_angle_diffusion_BDTOPO.html">BDTOPO</a>',
});
layers.push(bdtopoAriegeLayer);
var map = new ol.Map({
layers: [
stamenLayer,
planignLayer,
schapiLayer,
pciAriegeLayer,
bdtopoAriegeLayer,
bdtopoAriegeBatiLayer
],
controls: ol.control.defaults({
zoom: true,
attribution: true,
rotate: true
}),
target: 'map',
view: new ol.View({
center: [287963, 5948655],
zoom: 6,
constrainResolution: true
})
});
/************************* Application des styles mapbox *************************/
layers.forEach(function (layer) {
if (layer.get('mapboxStyleUrl')) {
fetch(layer.get('mapboxStyleUrl')).then(
function (response) {
if (response.ok) {
response.json().then(
function (style) {
olms.applyStyle(layer, style, layer.get('mapboxStyleSource'));
}
).catch(function (error) {
console.error(error);
});
}
}
);
}
});
/************************* LAYER SWITCHER *************************/
var lsControl = new ol.control.LayerSwitcher({
layers: layers.map(function (layer) {
return {
layer: layer,
config: {
title: layer.get('title'),
description: layer.get('description')
}
}
}),
options: {
collapsed: true
}
});
//Ajout du controle à la carte
map.addControl(lsControl);
// Creation du controle
var searchControl = new ol.control.SearchEngine({});
// Ajout à la carte
map.addControl(searchControl);
/************************* AFFICHAGE *************************/
// Affichage du niveau en haut à gauche
map.on("moveend", function () {
var zoom = map.getView().getZoom();
document.getElementById('zoomlevel').innerHTML = zoom;
});
// Affichage des informations de la feature du dessus
map.on('click', function (event) {
var infos = '';
var something = false;
map.forEachFeatureAtPixel(event.pixel, function (feature, layer) {
if (feature.get('layer') !== 'fond_opaque') {
something = true;
infos += '<h5>' + layer.get('title') + ' - ' + feature.get('layer') + '</h5><ul>';
for (const [key, value] of Object.entries(feature.getProperties())) {
if (key !== 'layer') {
infos += "<li>" + key + ": " + value + "</li>";
}
}
infos += '</ul>';
}
}, {
hitTolerance: 2
});
if (something) {
infos = '<div onclick="close_infos()" id="croix">x</div>' + infos;
document.getElementById('infos').innerHTML = infos;
document.getElementById('infos').style.display = 'block';
} else {
document.getElementById('infos').style.display = 'none';
}
});
}
//Connection au serveur du geoportail
Gp.Services.getConfig({
serverUrl: "http://localhost/autoconf.js",
callbackSuffix: "",
onSuccess: go
});
function close_infos() {
document.getElementById('infos').style.display = 'none';
}
</script>
</body>
</html> |
Partager