reorgation du code

This commit is contained in:
JS 2023-10-28 19:12:56 +02:00
parent 238b35288f
commit 68dcef7596
5 changed files with 95 additions and 96 deletions

View file

@ -1,95 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Layers Control Tutorial - Leaflet</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 400px;
width: 600px;
max-width: 100%;
max-height: 100%;
background-color: white;
outline:auto;
}
</style>
</head>
<body>
<div class="sliderBox">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<span id ="sliderOutput"></span>
<div id="scaleOutput"></div>
</div>
<div id='map'></div>
<script scr="scaleGesture.js"></script>
<script>
const osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
const osmHOT = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Tiles style by <a href="https://www.hotosm.org/" target="_blank">Humanitarian OpenStreetMap Team</a> hosted by <a href="https://openstreetmap.fr/" target="_blank">OpenStreetMap France</a>'
});
const IGNOrtho = L.tileLayer("https://wxs.ign.fr/essentiels/geoportail/wmts?" +
"&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0" +
"&STYLE=normal" +
"&TILEMATRIXSET=PM" +
"&FORMAT=image/jpeg"+
"&LAYER=ORTHOIMAGERY.ORTHOPHOTOS"+
"&TILEMATRIX={z}" +
"&TILEROW={y}" +
"&TILECOL={x}",
{
minZoom : 0,
maxZoom : 24,
opacity : 0.5,
attribution : "IGN-F/Geoportail",
tileSize : 256 // les tuiles du Géooportail font 256x256px
}
);
const baseLayers = {
'OpenStreetMap': osm,
'OpenStreetMap.HOT': osmHOT
};
const overlays = {
'IGNOrtho': IGNOrtho,
};
const map = L.map('map', {
center: [48.1214044, -1.7109459],
zoom: 17,
layers: [
osm
]
});
const layerControl = L.control.layers(baseLayers, overlays).addTo(map);
var slider = document.getElementById("myRange");
var output = document.getElementById("sliderOutput");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
IGNOrtho.setOpacity(this.value/100);
}
</script>
</body>
</html>

49
index.html Normal file
View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Layers Control Tutorial - Leaflet</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<style>
html, body {
height: 100%;
margin: 0;
}
.leaflet-container {
height: 400px;
width: 600px;
max-width: 100%;
max-height: 100%;
background-color: white;
outline:auto;
}
</style>
</head>
<body>
<div class="sliderBox">
<input type="range" min="1" max="100" value="50" class="slider" id="myRange">
<span id ="sliderOutput"></span>
<div id="scaleOutput"></div>
</div>
<div id='Map'></div>
<script src="layers.js"></script>
<script>
const map = L.map('Map', {
center: [48.1214044, -1.7109459],
zoom: 17,
layers: [osm]
});
</script>
<script src="layerControl.js"></script>
<script src="scaleGesture.js"></script>
</body>
</html>

18
layerControl.js Normal file
View file

@ -0,0 +1,18 @@
const baseLayers = {
'OpenStreetMap': osm,
'OpenStreetMap.HOT': osmHOT
};
const overlays = {
'IGNOrtho': IGNOrtho,
};
const layerControl = L.control.layers(baseLayers, overlays).addTo(map);
var slider = document.getElementById("myRange");
var output = document.getElementById("sliderOutput");
output.innerHTML = slider.value;
slider.oninput = function() {
output.innerHTML = this.value;
IGNOrtho.setOpacity(this.value/100);
}

25
layers.js Normal file
View file

@ -0,0 +1,25 @@
const osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
const osmHOT = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Tiles style by <a href="https://www.hotosm.org/" target="_blank">Humanitarian OpenStreetMap Team</a> hosted by <a href="https://openstreetmap.fr/" target="_blank">OpenStreetMap France</a>'
});
const IGNOrtho = L.tileLayer("https://wxs.ign.fr/essentiels/geoportail/wmts?" +
"&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0" +
"&STYLE=normal" +
"&TILEMATRIXSET=PM" +
"&FORMAT=image/jpeg"+
"&LAYER=ORTHOIMAGERY.ORTHOPHOTOS"+
"&TILEMATRIX={z}" +
"&TILEROW={y}" +
"&TILECOL={x}",
{
minZoom : 0,
maxZoom : 24,
opacity : 0.5,
attribution : "IGN-F/Geoportail",
tileSize : 256 // les tuiles du Géooportail font 256x256px
}
);

View file

@ -23,4 +23,6 @@ var scaleOutput = document.getElementById("scaleOutput");
scaleOutput.innerHTML = widthInMeter; scaleOutput.innerHTML = widthInMeter;
map.on('moveend', function(){ map.on('moveend', function(){
scaleOutput.innerHTML = widthInMeter; scaleOutput.innerHTML = widthInMeter;
}); console.log(widthInMeter);
console.log(scaleManage());
});