采用 OpenLayers + WebGIS 编写浏览器的地图应用入门样例
本样例来自 OpenLayers 官方 Quick Start .
可以在以下几个方面做调整:
1) JS / CSS 文件可以引用网络,也可以引用本地下载的 openlayers 对应文件;
2)图层的中心位置可调;
3)图层的 ZOOM 层级可调,最大为 6 ;
<!doctype html>
<html lang="en">
<head>
<!-- <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/css/ol.css" type="text/css"> -->
<link rel="stylesheet" href="css/ol.css" type="text/css">
<style>
.map {
height: 800px;
width: 100%;
}
</style>
<!-- <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/build/ol.js"></script> -->
<script src="build/ol.js"></script>
<title>OpenLayers example</title>
</head>
<body>
<h2>My Map</h2>
<div id="wxf2" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'wxf2',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: ol.proj.fromLonLat([121.41, 30.82]),
zoom: 4
})
});
</script>
</body>
</html>```