gis-map-szdp 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a.vue +323 -0
- package/dist/china_full.json +26527 -0
- package/dist/gismap.es.js +19144 -17832
- package/dist/gismap.umd.js +64 -61
- package/dist/guodao.json +1 -0
- package/dist/index.css +1 -1
- package/dist/sdArea.json +7111 -0
- package/dist/shengdao.json +1 -0
- package/dist//345/244/247/350/275/246.png +0 -0
- package/dist//345/260/217/350/275/246.png +0 -0
- package/package.json +2 -1
package/dist/a.vue
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="container">
|
|
3
|
+
<div id="map" class="map"></div>
|
|
4
|
+
<form class="form-inline">
|
|
5
|
+
<label for="type">Measurement type </label>
|
|
6
|
+
<select id="type">
|
|
7
|
+
<option value="length">Length (LineString)</option>
|
|
8
|
+
<option value="area">Area (Polygon)</option>
|
|
9
|
+
</select>
|
|
10
|
+
</form>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script setup>
|
|
15
|
+
import Draw from 'ol/interaction/Draw';
|
|
16
|
+
import Map from 'ol/Map';
|
|
17
|
+
import Overlay from 'ol/Overlay';
|
|
18
|
+
import View from 'ol/View';
|
|
19
|
+
import {Circle as CircleStyle, Fill, Stroke, Style} from 'ol/style';
|
|
20
|
+
import {LineString, Polygon} from 'ol/geom';
|
|
21
|
+
import {OSM, Vector as VectorSource} from 'ol/source';
|
|
22
|
+
import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
|
|
23
|
+
import {getArea, getLength} from 'ol/sphere';
|
|
24
|
+
import {unByKey} from 'ol/Observable';
|
|
25
|
+
|
|
26
|
+
const raster = new TileLayer({
|
|
27
|
+
source: new OSM(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const source = new VectorSource();
|
|
31
|
+
|
|
32
|
+
const vector = new VectorLayer({
|
|
33
|
+
source: source,
|
|
34
|
+
style: new Style({
|
|
35
|
+
fill: new Fill({
|
|
36
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
37
|
+
}),
|
|
38
|
+
stroke: new Stroke({
|
|
39
|
+
color: '#ffcc33',
|
|
40
|
+
width: 2,
|
|
41
|
+
}),
|
|
42
|
+
image: new CircleStyle({
|
|
43
|
+
radius: 7,
|
|
44
|
+
fill: new Fill({
|
|
45
|
+
color: '#ffcc33',
|
|
46
|
+
}),
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Currently drawn feature.
|
|
53
|
+
* @type {import("../src/ol/Feature.js").default}
|
|
54
|
+
*/
|
|
55
|
+
let sketch;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The help tooltip element.
|
|
59
|
+
* @type {HTMLElement}
|
|
60
|
+
*/
|
|
61
|
+
let helpTooltipElement;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Overlay to show the help messages.
|
|
65
|
+
* @type {Overlay}
|
|
66
|
+
*/
|
|
67
|
+
let helpTooltip;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The measure tooltip element.
|
|
71
|
+
* @type {HTMLElement}
|
|
72
|
+
*/
|
|
73
|
+
let measureTooltipElement;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Overlay to show the measurement.
|
|
77
|
+
* @type {Overlay}
|
|
78
|
+
*/
|
|
79
|
+
let measureTooltip;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Message to show when the user is drawing a polygon.
|
|
83
|
+
* @type {string}
|
|
84
|
+
*/
|
|
85
|
+
const continuePolygonMsg = 'Click to continue drawing the polygon';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Message to show when the user is drawing a line.
|
|
89
|
+
* @type {string}
|
|
90
|
+
*/
|
|
91
|
+
const continueLineMsg = 'Click to continue drawing the line';
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Handle pointer move.
|
|
95
|
+
* @param {import("../src/ol/MapBrowserEvent").default} evt The event.
|
|
96
|
+
*/
|
|
97
|
+
const pointerMoveHandler = function (evt) {
|
|
98
|
+
if (evt.dragging) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
/** @type {string} */
|
|
102
|
+
let helpMsg = 'Click to start drawing';
|
|
103
|
+
|
|
104
|
+
if (sketch) {
|
|
105
|
+
const geom = sketch.getGeometry();
|
|
106
|
+
if (geom instanceof Polygon) {
|
|
107
|
+
helpMsg = continuePolygonMsg;
|
|
108
|
+
} else if (geom instanceof LineString) {
|
|
109
|
+
helpMsg = continueLineMsg;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
helpTooltipElement.innerHTML = helpMsg;
|
|
114
|
+
helpTooltip.setPosition(evt.coordinate);
|
|
115
|
+
|
|
116
|
+
helpTooltipElement.classList.remove('hidden');
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const map = new Map({
|
|
120
|
+
layers: [raster, vector],
|
|
121
|
+
target: 'map',
|
|
122
|
+
view: new View({
|
|
123
|
+
center: [-11000000, 4600000],
|
|
124
|
+
zoom: 15,
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
map.on('pointermove', pointerMoveHandler);
|
|
129
|
+
|
|
130
|
+
map.getViewport().addEventListener('mouseout', function () {
|
|
131
|
+
helpTooltipElement.classList.add('hidden');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const typeSelect = document.getElementById('type');
|
|
135
|
+
|
|
136
|
+
let draw; // global so we can remove it later
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Format length output.
|
|
140
|
+
* @param {LineString} line The line.
|
|
141
|
+
* @return {string} The formatted length.
|
|
142
|
+
*/
|
|
143
|
+
const formatLength = function (line) {
|
|
144
|
+
const length = getLength(line);
|
|
145
|
+
let output;
|
|
146
|
+
if (length > 100) {
|
|
147
|
+
output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
|
|
148
|
+
} else {
|
|
149
|
+
output = Math.round(length * 100) / 100 + ' ' + 'm';
|
|
150
|
+
}
|
|
151
|
+
return output;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Format area output.
|
|
156
|
+
* @param {Polygon} polygon The polygon.
|
|
157
|
+
* @return {string} Formatted area.
|
|
158
|
+
*/
|
|
159
|
+
const formatArea = function (polygon) {
|
|
160
|
+
const area = getArea(polygon);
|
|
161
|
+
let output;
|
|
162
|
+
if (area > 10000) {
|
|
163
|
+
output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
|
|
164
|
+
} else {
|
|
165
|
+
output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
|
|
166
|
+
}
|
|
167
|
+
return output;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
function addInteraction() {
|
|
171
|
+
const type = typeSelect.value == 'area' ? 'Polygon' : 'LineString';
|
|
172
|
+
draw = new Draw({
|
|
173
|
+
source: source,
|
|
174
|
+
type: type,
|
|
175
|
+
style: new Style({
|
|
176
|
+
fill: new Fill({
|
|
177
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
178
|
+
}),
|
|
179
|
+
stroke: new Stroke({
|
|
180
|
+
color: 'rgba(0, 0, 0, 0.5)',
|
|
181
|
+
lineDash: [10, 10],
|
|
182
|
+
width: 2,
|
|
183
|
+
}),
|
|
184
|
+
image: new CircleStyle({
|
|
185
|
+
radius: 5,
|
|
186
|
+
stroke: new Stroke({
|
|
187
|
+
color: 'rgba(0, 0, 0, 0.7)',
|
|
188
|
+
}),
|
|
189
|
+
fill: new Fill({
|
|
190
|
+
color: 'rgba(255, 255, 255, 0.2)',
|
|
191
|
+
}),
|
|
192
|
+
}),
|
|
193
|
+
}),
|
|
194
|
+
});
|
|
195
|
+
map.addInteraction(draw);
|
|
196
|
+
|
|
197
|
+
createMeasureTooltip();
|
|
198
|
+
createHelpTooltip();
|
|
199
|
+
|
|
200
|
+
let listener;
|
|
201
|
+
draw.on('drawstart', function (evt) {
|
|
202
|
+
// set sketch
|
|
203
|
+
sketch = evt.feature;
|
|
204
|
+
|
|
205
|
+
/** @type {import("../src/ol/coordinate.js").Coordinate|undefined} */
|
|
206
|
+
let tooltipCoord = evt.coordinate;
|
|
207
|
+
|
|
208
|
+
listener = sketch.getGeometry().on('change', function (evt) {
|
|
209
|
+
const geom = evt.target;
|
|
210
|
+
let output;
|
|
211
|
+
if (geom instanceof Polygon) {
|
|
212
|
+
output = formatArea(geom);
|
|
213
|
+
tooltipCoord = geom.getInteriorPoint().getCoordinates();
|
|
214
|
+
} else if (geom instanceof LineString) {
|
|
215
|
+
output = formatLength(geom);
|
|
216
|
+
tooltipCoord = geom.getLastCoordinate();
|
|
217
|
+
}
|
|
218
|
+
measureTooltipElement.innerHTML = output;
|
|
219
|
+
measureTooltip.setPosition(tooltipCoord);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
draw.on('drawend', function () {
|
|
224
|
+
measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
|
|
225
|
+
measureTooltip.setOffset([0, -7]);
|
|
226
|
+
// unset sketch
|
|
227
|
+
sketch = null;
|
|
228
|
+
// unset tooltip so that a new one can be created
|
|
229
|
+
measureTooltipElement = null;
|
|
230
|
+
createMeasureTooltip();
|
|
231
|
+
unByKey(listener);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Creates a new help tooltip
|
|
237
|
+
*/
|
|
238
|
+
function createHelpTooltip() {
|
|
239
|
+
if (helpTooltipElement) {
|
|
240
|
+
helpTooltipElement.parentNode.removeChild(helpTooltipElement);
|
|
241
|
+
}
|
|
242
|
+
helpTooltipElement = document.createElement('div');
|
|
243
|
+
helpTooltipElement.className = 'ol-tooltip hidden';
|
|
244
|
+
helpTooltip = new Overlay({
|
|
245
|
+
element: helpTooltipElement,
|
|
246
|
+
offset: [15, 0],
|
|
247
|
+
positioning: 'center-left',
|
|
248
|
+
});
|
|
249
|
+
map.addOverlay(helpTooltip);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Creates a new measure tooltip
|
|
254
|
+
*/
|
|
255
|
+
function createMeasureTooltip() {
|
|
256
|
+
if (measureTooltipElement) {
|
|
257
|
+
measureTooltipElement.parentNode.removeChild(measureTooltipElement);
|
|
258
|
+
}
|
|
259
|
+
measureTooltipElement = document.createElement('div');
|
|
260
|
+
measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
|
|
261
|
+
measureTooltip = new Overlay({
|
|
262
|
+
element: measureTooltipElement,
|
|
263
|
+
offset: [0, -15],
|
|
264
|
+
positioning: 'bottom-center',
|
|
265
|
+
stopEvent: false,
|
|
266
|
+
insertFirst: false,
|
|
267
|
+
});
|
|
268
|
+
map.addOverlay(measureTooltip);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Let user change the geometry type.
|
|
273
|
+
*/
|
|
274
|
+
typeSelect.onchange = function () {
|
|
275
|
+
map.removeInteraction(draw);
|
|
276
|
+
addInteraction();
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
addInteraction();
|
|
280
|
+
|
|
281
|
+
</script>
|
|
282
|
+
|
|
283
|
+
<style scoped>
|
|
284
|
+
.map {
|
|
285
|
+
width: 100%;
|
|
286
|
+
height:400px;
|
|
287
|
+
}
|
|
288
|
+
.ol-tooltip {
|
|
289
|
+
position: relative;
|
|
290
|
+
background: rgba(0, 0, 0, 0.5);
|
|
291
|
+
border-radius: 4px;
|
|
292
|
+
color: white;
|
|
293
|
+
padding: 4px 8px;
|
|
294
|
+
opacity: 0.7;
|
|
295
|
+
white-space: nowrap;
|
|
296
|
+
font-size: 12px;
|
|
297
|
+
cursor: default;
|
|
298
|
+
user-select: none;
|
|
299
|
+
}
|
|
300
|
+
.ol-tooltip-measure {
|
|
301
|
+
opacity: 1;
|
|
302
|
+
font-weight: bold;
|
|
303
|
+
}
|
|
304
|
+
.ol-tooltip-static {
|
|
305
|
+
background-color: #ffcc33;
|
|
306
|
+
color: black;
|
|
307
|
+
border: 1px solid white;
|
|
308
|
+
}
|
|
309
|
+
.ol-tooltip-measure:before,
|
|
310
|
+
.ol-tooltip-static:before {
|
|
311
|
+
border-top: 6px solid rgba(0, 0, 0, 0.5);
|
|
312
|
+
border-right: 6px solid transparent;
|
|
313
|
+
border-left: 6px solid transparent;
|
|
314
|
+
content: "";
|
|
315
|
+
position: absolute;
|
|
316
|
+
bottom: -6px;
|
|
317
|
+
margin-left: -7px;
|
|
318
|
+
left: 50%;
|
|
319
|
+
}
|
|
320
|
+
.ol-tooltip-static:before {
|
|
321
|
+
border-top-color: #ffcc33;
|
|
322
|
+
}
|
|
323
|
+
</style>
|