DkMap.vue
2.4 KB
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
<template>
<div id="map">
</div>
</template>
<script>
import * as i2d from "i2d";
import 'leaflet/dist/leaflet.css'
import 'i2d/dist/i2d.css'
import L from "leaflet";
import {bbox} from "@turf/bbox";
export default {
name: 'DkMap',
data() {
return {
mapOptions: {
copyright: false,
basemaps: [
{
type: 'group',
name: '天地图电子',
layers: [
{
type: 'tdt',
layer: 'vec_d',
key: i2d.Token.tiandituArr,
crs: i2d.CRS.EPSG4490,
},
{
type: 'tdt',
layer: 'vec_z',
key: i2d.Token.tiandituArr,
crs: i2d.CRS.EPSG4490,
}
],
icon: './dz.png',
show: true
}
],
zoom: 12,
minZoom: 1,
maxZoom: 16,
// 纬度在前
center: [34.247161, 108.944213],
crs: i2d.CRS.EPSG4490
}
}
},
mounted() {
// 从数据库读取的地块信息
const dkCoord = {"type": "Polygon", "coordinates": [[[100.98204924173348, 40.47840655548055], [101.22951318633983, 40.43081733536394], [101.14765972773921, 40.10340350096175], [100.85070299421159, 40.181449821952924], [100.98204924173348, 40.47840655548055]]]}
const geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": dkCoord
}
]
}
// eslint-disable-next-line no-unused-vars
const map = new i2d.Map('map', this.mapOptions)
const geoJsonLayer = new i2d.Layer.GeoJsonLayer({
name: "安徽各市",
data: geojson,
// 渲染颜色
symbol: {
type: "polygon",
styleOptions: {
fillOpacity: 0.6,
fillColor: "#ff0044",
outline: true
}
}
})
map.addLayer(geoJsonLayer)
//地块自带外包矩形
if (dkCoord.bbox) {
//定位到矩形
map.fitBounds(L.latLngBounds([
[dkCoord.bbox[1], dkCoord.bbox[0]],
[dkCoord.bbox[3], dkCoord.bbox[2]]
]));
} else {
const result = bbox(geojson);
map.fitBounds(L.latLngBounds([
[result[1], result[0]],
[result[3], result[2]]
]));
}
}
}
</script>
<style scoped>
#map {
position: absolute;
margin: 0;
height: 60%;
width: 60%;
}
</style>