openlayers.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>wuyidaxue</title>
  5. <meta http-equiv="imagetoolbar" content="no"/>
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <style type="text/css">
  9. html, body { margin:0; padding: 0; height: 100%; width: 100%; }
  10. body { width:100%; height:100%; background: #ffffff; }
  11. #map { position: absolute; height: 100%; width: 100%; }
  12. #slider { position: absolute; top: 10px; right: 10px; }
  13. </style>
  14. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/4.6.5/ol.css" type="text/css">
  15. <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,fetch,Function.prototype.bind,es5&flags=always,gated&unknown=polyfill" type="text/javascript"></script>
  16. <script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/4.6.5/ol.js" type="text/javascript"></script>
  17. </head>
  18. <body>
  19. <div id="map"></div>
  20. <input id="slider" type="range" min="0" max="1" step="0.1" value="1" oninput="layer.setOpacity(this.value)">
  21. <script type="text/javascript">
  22. var mapExtent = ol.proj.transformExtent([112.916977, 22.483461, 113.179119, 22.809082], 'EPSG:4326', 'EPSG:3857');
  23. var mapMinZoom = 9;
  24. var mapMaxZoom = 18;
  25. var layer = new ol.layer.Tile({
  26. extent: mapExtent,
  27. source: new ol.source.XYZ({
  28. attributions: [new ol.Attribution({html: 'wuyidaxue; Rendered with <a href="https://www.maptiler.com/">MapTiler Desktop</a>'})],
  29. url: "{z}/{x}/{y}.png",
  30. tilePixelRatio: 1.000000,
  31. minZoom: mapMinZoom,
  32. maxZoom: mapMaxZoom
  33. })
  34. });
  35. var osm = new ol.layer.Tile({
  36. source: new ol.source.OSM()
  37. });
  38. var map = new ol.Map({
  39. target: 'map',
  40. layers: [
  41. osm,
  42. layer
  43. ],
  44. view: new ol.View({
  45. center: ol.proj.fromLonLat([113.048048, 22.646271]),
  46. zoom: 10
  47. })
  48. });
  49. </script>
  50. </body>
  51. </html>