-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
153 lines (148 loc) · 4.59 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>基于maptalks的2.5D地图绘制</title>
</head>
<body>
<div id="app">
<div id="mapDom" style="width:1000px;height:500px"></div>
</div>
</body>
<script src="https://cdn.bootcss.com/vue/2.5.21/vue.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.css">
<script src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
const edgeColor = '#4682B4'
const polygonColors = ["#C0C0C0", "#87CEFA"];
const mapCenter = [106.355, 26.75]
const altitude = 15000;
let vm = new Vue({
el: '#app',
data() {
return {
polygons: [],
limitLines: []
}
},
mounted() {
this.initMapTalk()
this.drawRegion()
this.drawWall()
},
methods: {
initMapTalk() {
const url = 'https://api.mapbox.com/styles/v1/ling13/cjpv0upr10vc52sodrbmtrmrb/tiles/256/{z}/{x}/{y}?access_token=pk.eyJ1IjoibGluZzEzIiwiYSI6ImNqbHozcGRwZDBzMHIzcXBqNXV2dGR4dHAifQ.32-e7GIttC0FriVwvJ0GqA#6.1/27.044989/106.588086/0'
this.mapDom = new maptalks.Map('mapDom', {
center: mapCenter,
zoom: 7,
pitch: 45, // y方向倾斜角度
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: url,
subdomains: ['a','b','c','d'],
attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>'
})
});
},
drawLimitLines(idx, coordinates, properties) {
const outLine = new maptalks.MultiLineString(coordinates, {
symbol: {
lineColor: edgeColor,
lineWidth: 1,
textPlacement: "vertex"
},
properties: {
altitude: altitude,
index: idx,
id: properties.id,
properties: properties
}
});
this.limitLines.push(outLine);
},
drawBorderLines(coordinates, properties) {
const outLine = new maptalks.MultiLineString(coordinates, {
symbol: {
lineColor: edgeColor,
lineWidth: 1,
textPlacement: "vertex"
},
properties: {
altitude: altitude,
id: properties.id,
properties: properties
}
});
this.limitLines.push(outLine);
},
drawPolygons(idx, coordinates, properties) {
const polygon = new maptalks.MultiPolygon(coordinates, {
symbol: {
lineWidth: 1,
lineColor: edgeColor,
polygonFill: polygonColors[0],
polygonOpacity: 0.5
},
properties: {
altitude: altitude,
id: properties.id,
index: idx,
properties: properties
}
})
.on("mouseenter", function(e) {
e.target.updateSymbol({
polygonFill: polygonColors[1]
});
})
.on("mouseout", function(e) {
e.target.updateSymbol({
polygonFill: polygonColors[0]
});
})
this.polygons.push(polygon);
},
drawRegion() {
const self = this
$.getJSON("guizhou.json", "", function(mapData) {
const features = mapData.features;
features.forEach((g, i) => {
const properties = g.properties;
const coordinates = g.geometry.coordinates
self.drawPolygons(i, coordinates, properties)
});
const polygonsLayer = new maptalks.VectorLayer(
"vector-polygon",
self.polygons,
{
enableAltitude: true
}
).addTo(self.mapDom);
})
},
drawWall() {
const self = this
$.getJSON("guizhou-border.json", "", function(borderMapData) {
const borderFeatures = borderMapData.features[0]
const properties = borderFeatures.properties;
const pathCoordinates = borderFeatures.geometry.coordinates.map(d => { return d[0] })
self.drawBorderLines(pathCoordinates, properties)
const limitLinesLayer = new maptalks.VectorLayer(
"vector-line",
self.limitLines,
{
enableAltitude: true,
drawAltitude: {
polygonFill: edgeColor,
polygonOpacity: 0.3,
lineWidth: 0
}
}
).addTo(self.mapDom);
})
}
}
})
</script>
</html>