-
Notifications
You must be signed in to change notification settings - Fork 72
/
demo4.html
164 lines (156 loc) · 5.22 KB
/
demo4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>要素标绘(点/聚簇、线、面,符号化/静态动态)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
type="text/css"
media="screen"
href="./lib/Flat-UI-master/dist/css/vendor/bootstrap/css/bootstrap.min.css"
/>
<link rel="stylesheet" href="./lib/Flat-UI-master/dist/css/flat-ui.min.css" />
<link rel="stylesheet" href="./lib/leaflet/leaflet.css" />
</head>
<body>
<nav
class="navbar navbar-inverse navbar-embossed"
role="navigation"
style="margin-bottom: 0; border-radius: 0; z-index: 2"
>
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-01">
<span class="sr-only">Toggle navigation</span>
</button>
<a class="navbar-brand" href="#">Flat UI</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-01">
<ul class="nav navbar-nav navbar-left">
<li>
<a href="#fakelink"
>绘制元素
<span class="navbar-unread">1</span>
</a>
</li>
<li>
<a href="JavaScript:void(0)" onclick="createCircle()">circle</a>
</li>
<li>
<a href="JavaScript:void(0)" onclick="createMarker()">marker</a>
</li>
<li>
<a href="JavaScript:void(0)" onclick="createSelfMarker()">custom marker</a>
</li>
<li>
<a href="JavaScript:void(0)" onclick="createPolyline()">polyline</a>
</li>
<li>
<a href="JavaScript:void(0)" onclick="createPolygon()">polygon</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12" id="mapDiv" style="position: absolute; top: 53px; bottom: 0; z-index: 1"></div>
<!-- 地图面板 -->
<!--底部状态栏部分 -->
</div>
</div>
</body>
<script src="./lib/Flat-UI-master/dist/js/vendor/jquery.min.js"></script>
<script src="./lib/Flat-UI-master/dist/js/flat-ui.js"></script>
<script src="./lib/leaflet/leaflet.js"></script>
<script src="./js/urlTemplate.js"></script>
<script>
const map = L.map('mapDiv', {
crs: L.CRS.EPSG3857,
zoomControl: true,
minZoom: 1,
attributionControl: true,
zoomAnimation: false, //缩放是否带动画
}).setView([36.52, 120.31], 8);
let Baselayer = L.tileLayer(urlTemplate.mapbox_url, {
maxZoom: 18,
id: 'mapbox.streets',
}).addTo(map);
// 画一个circle
const createCircle = () => {
const circle = L.circle([36.52, 120.31], {
color: 'green', //描边色
fillColor: '#f03', //填充色
fillOpacity: 0.5, //透明度
radius: 10000, //半径,单位米
}).addTo(map);
// 绑定一个提示标签
circle.bindTooltip('我是个圆');
map.fitBounds(circle.getBounds());
};
// 做一个maker
const createMarker = () => {
const marker = L.marker([36.52, 120.31]).addTo(map);
// 绑定一个提示标签
marker.bindTooltip('这是个Marker', { direction: 'left' }).openTooltip();
};
//自定义一个maker
const createSelfMarker = () => {
const greenIcon = L.icon({
iconUrl: './icon/logo.png',
iconSize: [300, 79], // size of the icon
popupAnchor: [0, -10], // point from which the popup should open relative to the iconAnchor
});
const oMarker = L.marker([36.52, 124.31], { icon: greenIcon }).addTo(map);
// 绑定一个提示标签
oMarker.bindTooltip('这是个自定义Marker', { direction: 'left', offset: [-150, 0] });
map.panTo(oMarker.getLatLng());
};
//画一根线
const createPolyline = () => {
const polyline = L.polyline(
[
[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2],
],
{ color: 'red' }
).addTo(map);
// 飞到这个线的位置
map.fitBounds(polyline.getBounds());
};
// 画一个polygon
const createPolygon = () => {
const polygon = L.polygon(
[
[
[37, -109.05],
[41, -109.03],
[41, -102.05],
[37, -102.04],
], // outer ring
[
[37.29, -108.58],
[40.71, -108.58],
[40.71, -102.5],
[37.29, -102.5],
], // hole
],
{
color: 'green',
fillColor: '#f03',
fillOpacity: 0.5,
}
).addTo(map);
// 绑定一个提示标签
polygon.bindTooltip('this is 个多边形');
// 飞到这个多边形的位置
map.fitBounds(polygon.getBounds());
};
// 绑定一个监听事件
map.on('zoomend', function (e) {
console.log(e.target._zoom);
});
</script>
</html>