quick-refactor #2
					 1 changed files with 101 additions and 100 deletions
				
			
		|  | @ -26,9 +26,8 @@ | |||
| 			outline:auto; | ||||
| 		} | ||||
| 		</style> | ||||
| 
 | ||||
| 	 | ||||
| 	</head> | ||||
| 
 | ||||
| 	<body> | ||||
| 		<div class="sliderBox"> | ||||
| 			<input type="range" min="1" max="100" value="50" class="slider" id="myRange"> | ||||
|  | @ -39,44 +38,32 @@ | |||
| 		<div id='map'></div> | ||||
| 
 | ||||
| 		<script> | ||||
| const cities = L.layerGroup(); | ||||
| const mLittleton = L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities); | ||||
| const mDenver = L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.').addTo(cities); | ||||
| const mAurora = L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.').addTo(cities); | ||||
| const mGolden = L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.').addTo(cities); | ||||
| 			const mLittleton 	= L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.'); | ||||
| 			const mDenver 		= L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.'); | ||||
| 			const mAurora 		= L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.'); | ||||
| 			const mGolden 		= L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.'); | ||||
| 			const crownHill 	= L.marker([39.75, -105.09]).bindPopup('This is Crown Hill Park.'); | ||||
| 			const rubyHill 		= L.marker([39.68, -105.00]).bindPopup('This is Ruby Hill Park.'); | ||||
| 
 | ||||
| 			const cities = L.layerGroup([ | ||||
| 				mLittleton, | ||||
| 				mDenver, | ||||
| 				mAurora, | ||||
| 				mGolden | ||||
| 			]); | ||||
| 			const parks = L.layerGroup([ | ||||
| 				crownHill, | ||||
| 				rubyHill | ||||
| 			]); | ||||
| 
 | ||||
| 			const osm = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||||
| 				maxZoom: 19, | ||||
| 				attribution: '© <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: '© <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 map = L.map('map', { | ||||
| 	center: [48.1214044, -1.7109459], | ||||
| 	zoom: 17, | ||||
| 	layers: [osm, cities] | ||||
| }); | ||||
| 
 | ||||
| const baseLayers = { | ||||
| 	'OpenStreetMap': osm, | ||||
| 	'OpenStreetMap.HOT': osmHOT | ||||
| }; | ||||
| 
 | ||||
| const overlays = { | ||||
| 	'Cities': cities | ||||
| }; | ||||
| 
 | ||||
| const layerControl = L.control.layers(baseLayers, overlays).addTo(map); | ||||
| 
 | ||||
| 
 | ||||
| const crownHill = L.marker([39.75, -105.09]).bindPopup('This is Crown Hill Park.'); | ||||
| const rubyHill = L.marker([39.68, -105.00]).bindPopup('This is Ruby Hill Park.'); | ||||
| 
 | ||||
| const parks = L.layerGroup([crownHill, rubyHill]); | ||||
| 
 | ||||
| 			const IGNOrtho = L.tileLayer("https://wxs.ign.fr/essentiels/geoportail/wmts?" + | ||||
| 				"&REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0" + | ||||
| 				"&STYLE=normal" + | ||||
|  | @ -92,10 +79,28 @@ const IGNOrtho = L.tileLayer("https://wxs.ign.fr/essentiels/geoportail/wmts?" + | |||
| 					opacity : 0.5, | ||||
| 					attribution : "IGN-F/Geoportail", | ||||
| 					tileSize : 256 // les tuiles du Géooportail font 256x256px | ||||
| }); | ||||
| layerControl.addOverlay(IGNOrtho, 'IGNORtho'); | ||||
| layerControl.addOverlay(parks, 'Parks'); | ||||
| 				} | ||||
| 			); | ||||
| 
 | ||||
| 			const baseLayers = { | ||||
| 				'OpenStreetMap': osm, | ||||
| 				'OpenStreetMap.HOT': osmHOT | ||||
| 			}; | ||||
| 
 | ||||
| 			const overlays = { | ||||
| 				'Cities': cities, | ||||
| 				'IGNOrtho': IGNOrtho, | ||||
| 				'Parks': parks | ||||
| 			}; | ||||
| 
 | ||||
| 			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"); | ||||
|  | @ -108,17 +113,13 @@ slider.oninput = function() { | |||
| 			// gestion de l'échelle | ||||
| 			L.control.scale().addTo(map); | ||||
| 
 | ||||
| 
 | ||||
| 			//var y = map.getSize().y / 2; | ||||
| var position = map.getCenter(); | ||||
| var widthInMeter = 6378137 * 2 * Math.PI * Math.cos(map.getCenter().lat * Math.PI / 180); | ||||
| 			const widthInMeter 	  = 6378137 * 2 * Math.PI * Math.cos(map.getCenter().lat * Math.PI / 180); | ||||
| 			var scaleOutput 	  = document.getElementById("scaleOutput"); | ||||
| 			scaleOutput.innerHTML = widthInMeter; | ||||
| 			map.on('moveend', function(){ | ||||
| 	scaleOutput.innerHTML = 6378137 * 2 * Math.PI * Math.cos(map.getCenter().lat * Math.PI / 180); | ||||
| 				scaleOutput.innerHTML = widthInMeter; | ||||
| 			}); | ||||
| 		</script> | ||||
| 
 | ||||
| 
 | ||||
| 	</body> | ||||
| </html> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue