二章-13-使用地图坐标网
2020-04-20 本文已影响0人
彩云飘过
本文基于腾讯课堂老胡的课《跟我学Openlayers--基础实例详解》做的学习笔记,使用的openlayers 5.3.x api。
源码 见 1013.html ,对应的 官网示例

<!DOCTYPE html>
<html>
<head>
<title>使用地图坐标网
</title>
<link rel="stylesheet" href="../include/ol.css" type="text/css">
<script src="../include/ol.js"></script>
</head>
<style>
</style>
<body>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([4.8, 47.75]),
zoom: 5
})
});
//把经纬度坐标转换为XY坐标
var graticule = new ol.Graticule({
strokeStyle: new ol.style.Stroke({
color: 'rgba(255,120,0,0.3)', //定义网格颜色
width: 2,
lineDash: [4] // 用数字数组,定义虚线类型 ;每4个像素一条虚线
}),
showLabels: true
});
graticule.setMap(map);
</script>
</body>
</html>