WFS
Showing
6 changed files
with
186 additions
and
9 deletions
... | @@ -6,3 +6,6 @@ pnpm i i2d --registry=http://core.pashanhoo.com:8932/repository/npm-public/ | ... | @@ -6,3 +6,6 @@ pnpm i i2d --registry=http://core.pashanhoo.com:8932/repository/npm-public/ |
6 | pnpm install @turf/bbox | 6 | pnpm install @turf/bbox |
7 | ``` | 7 | ``` |
8 | 8 | ||
9 | |||
10 | // "i2d": "link:D:/work/private/i2d", | ||
11 | ... | ... |
... | @@ -11,7 +11,8 @@ | ... | @@ -11,7 +11,8 @@ |
11 | "@turf/bbox": "^7.0.0", | 11 | "@turf/bbox": "^7.0.0", |
12 | "axios": "^1.7.2", | 12 | "axios": "^1.7.2", |
13 | "core-js": "^3.8.3", | 13 | "core-js": "^3.8.3", |
14 | "i2d": "^0.1.0", | 14 | "i2d": "0.3.23", |
15 | "leaflet": "^1.9.4", | ||
15 | "vue": "^2.6.14", | 16 | "vue": "^2.6.14", |
16 | "vue-router": "3.5.1" | 17 | "vue-router": "3.5.1" |
17 | }, | 18 | }, | ... | ... |
... | @@ -12,6 +12,9 @@ | ... | @@ -12,6 +12,9 @@ |
12 | <td> | 12 | <td> |
13 | <router-link to="/xzq-map">行政区定位</router-link> | 13 | <router-link to="/xzq-map">行政区定位</router-link> |
14 | </td> | 14 | </td> |
15 | <td> | ||
16 | <router-link to="/wfs">wfs</router-link> | ||
17 | </td> | ||
15 | </tr> | 18 | </tr> |
16 | </tbody> | 19 | </tbody> |
17 | </table> | 20 | </table> | ... | ... |
1 | <template> | 1 | <template> |
2 | <div> | 2 | <div> |
3 | <button @click="removeGraphicLayer">移出graphic图层</button> | 3 | <button @click="removeGraphicLayer">移出graphic图层</button> |
4 | <button @click="getCoord">点击地图拾取坐标</button> | ||
5 | <button @click="draw">绘制</button> | ||
4 | <div id="map"> | 6 | <div id="map"> |
5 | </div> | 7 | </div> |
6 | </div> | 8 | </div> |
... | @@ -13,7 +15,6 @@ import 'i2d/dist/i2d.css' | ... | @@ -13,7 +15,6 @@ import 'i2d/dist/i2d.css' |
13 | import L from "leaflet"; | 15 | import L from "leaflet"; |
14 | import {bbox} from "@turf/bbox"; | 16 | import {bbox} from "@turf/bbox"; |
15 | 17 | ||
16 | |||
17 | export default { | 18 | export default { |
18 | name: 'DkMap', | 19 | name: 'DkMap', |
19 | data() { | 20 | data() { |
... | @@ -55,6 +56,21 @@ export default { | ... | @@ -55,6 +56,21 @@ export default { |
55 | } | 56 | } |
56 | }, | 57 | }, |
57 | methods: { | 58 | methods: { |
59 | draw() { | ||
60 | this.graphicLayer.startDraw({ | ||
61 | type: "distanceMeasure", | ||
62 | style: { | ||
63 | width: 3, | ||
64 | color: "#000dfc" | ||
65 | } | ||
66 | }) | ||
67 | }, | ||
68 | getCoord() { | ||
69 | this.map.once(i2d.EventType.click, function (event) { | ||
70 | console.log(event); | ||
71 | alert(event.latlng) | ||
72 | }) | ||
73 | }, | ||
58 | getArrayRandomOne(arr) { | 74 | getArrayRandomOne(arr) { |
59 | const n = Math.floor(Math.random() * arr.length) | 75 | const n = Math.floor(Math.random() * arr.length) |
60 | return arr[n] | 76 | return arr[n] |
... | @@ -68,15 +84,18 @@ export default { | ... | @@ -68,15 +84,18 @@ export default { |
68 | } | 84 | } |
69 | }, | 85 | }, |
70 | addMarker() { | 86 | addMarker() { |
87 | // eslint-disable-next-line no-debugger | ||
88 | console.log(123123123) | ||
89 | console.log(i2d) | ||
71 | let graphic = new i2d.Graphic.Marker({ | 90 | let graphic = new i2d.Graphic.Marker({ |
72 | latlng: [32.3102954498753, 119.19403010080875], | 91 | latlng: [32.3102954498753, 119.19403010080875], |
73 | style: { | 92 | style: { |
74 | rotationAngle: 49, | 93 | // image: "./sdt.png", |
75 | image: "./sdt.png", | 94 | width: 16, |
76 | width: 32, | 95 | height: 16, |
77 | height: 44, | 96 | pulse: true, |
78 | horizontalOrigin: i2d.HorizontalOrigin.CENTER, | 97 | pulseColor: '#191a1b', |
79 | verticalOrigin: i2d.VerticalOrigin.BOTTOM | 98 | pulseShadowColor: '#191a1b' |
80 | } | 99 | } |
81 | }) | 100 | }) |
82 | this.graphicLayer.addGraphic(graphic) | 101 | this.graphicLayer.addGraphic(graphic) |
... | @@ -156,6 +175,11 @@ export default { | ... | @@ -156,6 +175,11 @@ export default { |
156 | 175 | ||
157 | // 创建矢量数据图层 | 176 | // 创建矢量数据图层 |
158 | this.graphicLayer = new i2d.Layer.GraphicLayer() | 177 | this.graphicLayer = new i2d.Layer.GraphicLayer() |
178 | this.graphicLayer.on(i2d.EventType.click, (e) => { | ||
179 | console.log(e) | ||
180 | // eslint-disable-next-line no-debugger | ||
181 | debugger | ||
182 | }) | ||
159 | this.map.addLayer(this.graphicLayer) | 183 | this.map.addLayer(this.graphicLayer) |
160 | this.addMarker() | 184 | this.addMarker() |
161 | } | 185 | } | ... | ... |
src/components/WFSQuery.vue
0 → 100644
1 | <template> | ||
2 | <div> | ||
3 | <input v-model="zrzh"> | ||
4 | <button @click="query">查询</button> | ||
5 | <div id="map"> | ||
6 | </div> | ||
7 | </div> | ||
8 | </template> | ||
9 | |||
10 | <script> | ||
11 | import * as i2d from "i2d"; | ||
12 | import 'leaflet/dist/leaflet.css' | ||
13 | import 'i2d/dist/i2d.css' | ||
14 | import axios from "axios"; | ||
15 | import proj4 from 'proj4' | ||
16 | |||
17 | export default { | ||
18 | name: 'DkMap', | ||
19 | data() { | ||
20 | return { | ||
21 | mapOptions: { | ||
22 | copyright: false, | ||
23 | basemaps: [ | ||
24 | { | ||
25 | type: 'group', | ||
26 | name: '天地图电子', | ||
27 | layers: [ | ||
28 | { | ||
29 | type: 'tdt', | ||
30 | layer: 'vec_d', | ||
31 | key: i2d.Token.tiandituArr, | ||
32 | crs: i2d.CRS.EPSG4490, | ||
33 | }, | ||
34 | { | ||
35 | type: 'tdt', | ||
36 | layer: 'vec_z', | ||
37 | key: i2d.Token.tiandituArr, | ||
38 | crs: i2d.CRS.EPSG4490, | ||
39 | } | ||
40 | ], | ||
41 | show: true | ||
42 | } | ||
43 | ], | ||
44 | operationallayers: [{ | ||
45 | name: "宗地", | ||
46 | type: "wms", | ||
47 | url: "http://www.hzbdcdj.com/geoserver/hzData/wms", | ||
48 | layers: "hzData:ZRZ", | ||
49 | // 是否启用地图交互(点击查询弹框) | ||
50 | interactive: true, | ||
51 | popup: "all", | ||
52 | show: true, | ||
53 | transparent: true, | ||
54 | format: "image/png", | ||
55 | zIndex: 3 | ||
56 | }], | ||
57 | zoom: 15, | ||
58 | minZoom: 1, | ||
59 | maxZoom: 18, | ||
60 | // 纬度在前 | ||
61 | center: [33.073665, 107.026747], | ||
62 | crs: i2d.CRS.EPSG4490 | ||
63 | }, | ||
64 | map: null, | ||
65 | graphicLayer: null, | ||
66 | zrzh: '610702001204GB00001F0001' | ||
67 | } | ||
68 | }, | ||
69 | methods: { | ||
70 | query() { | ||
71 | this.graphicLayer.clearLayers() | ||
72 | const _self = this | ||
73 | const data = `<wfs:GetFeature service="WFS" version="1.0.0" | ||
74 | outputFormat="application/json" | ||
75 | xmlns:wfs="http://www.opengis.net/wfs" | ||
76 | xmlns:ogc="http://www.opengis.net/ogc" | ||
77 | xmlns:gml="http://www.opengis.net/gml"> | ||
78 | <wfs:Query typeName="hzData:ZRZ"> | ||
79 | <ogc:Filter> | ||
80 | <ogc:PropertyIsEqualTo> | ||
81 | <ogc:PropertyName>自然幢号</ogc:PropertyName> | ||
82 | <ogc:Literal>${this.zrzh}</ogc:Literal> | ||
83 | </ogc:PropertyIsEqualTo> | ||
84 | </ogc:Filter> | ||
85 | </wfs:Query> | ||
86 | </wfs:GetFeature>` | ||
87 | |||
88 | const config = { | ||
89 | method: "post", | ||
90 | url: "https://www.hzbdcdj.com/geoserver/hzData/ows", | ||
91 | headers: { | ||
92 | "Content-Type": "application/xml" | ||
93 | }, | ||
94 | data: data | ||
95 | } | ||
96 | |||
97 | axios(config) | ||
98 | .then(function (response) { | ||
99 | if (response.data.features.length > 0) { | ||
100 | _self.graphicLayer.loadGeoJSON(response.data, { | ||
101 | flyTo: true, | ||
102 | crs: "EPSG:4524" | ||
103 | }) | ||
104 | } else { | ||
105 | alert("未查询到数据") | ||
106 | } | ||
107 | }) | ||
108 | .catch(function (error) { | ||
109 | console.log(error) | ||
110 | alert("查询失败:" + error) | ||
111 | }) | ||
112 | }, | ||
113 | }, | ||
114 | mounted() { | ||
115 | |||
116 | /** | ||
117 | * 定义4524坐标系 | ||
118 | */ | ||
119 | proj4.defs("EPSG:4524", "+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=36500000 +y_0=0 +ellps=GRS80 +units=m +no_defs +type=crs") | ||
120 | console.log("proj4", proj4.defs["EPSG:4524"]) | ||
121 | |||
122 | // 从数据库读取的地块信息 | ||
123 | this.map = new i2d.Map('map', this.mapOptions) | ||
124 | |||
125 | // 创建矢量数据图层 | ||
126 | this.graphicLayer = new i2d.Layer.GraphicLayer() | ||
127 | |||
128 | this.map.addLayer(this.graphicLayer) | ||
129 | } | ||
130 | } | ||
131 | </script> | ||
132 | |||
133 | <style scoped> | ||
134 | #map { | ||
135 | position: absolute; | ||
136 | margin: 0; | ||
137 | height: 60%; | ||
138 | width: 60%; | ||
139 | } | ||
140 | </style> |
... | @@ -2,7 +2,8 @@ import Vue from 'vue' //引入Vue | ... | @@ -2,7 +2,8 @@ import Vue from 'vue' //引入Vue |
2 | import Router from 'vue-router' //引入vue-router | 2 | import Router from 'vue-router' //引入vue-router |
3 | import HomeMap from '@/components/HomeMap' | 3 | import HomeMap from '@/components/HomeMap' |
4 | import DkMap from '@/components/DkMap' | 4 | import DkMap from '@/components/DkMap' |
5 | import XzqMap from '@/components/XzqMap.vue' //引入根目录下的Hello.vue组件 | 5 | import XzqMap from '@/components/XzqMap.vue' |
6 | import WFSQuery from '@/components/WFSQuery.vue' | ||
6 | 7 | ||
7 | Vue.use(Router) //Vue全局使用Router | 8 | Vue.use(Router) //Vue全局使用Router |
8 | 9 | ||
... | @@ -22,6 +23,11 @@ export default new Router({ | ... | @@ -22,6 +23,11 @@ export default new Router({ |
22 | path: '/xzq-map', | 23 | path: '/xzq-map', |
23 | name: 'DkMap', | 24 | name: 'DkMap', |
24 | component: XzqMap | 25 | component: XzqMap |
26 | }, | ||
27 | { | ||
28 | path: '/wfs', | ||
29 | name: 'WFS', | ||
30 | component: WFSQuery | ||
25 | } | 31 | } |
26 | ] | 32 | ] |
27 | }) | 33 | }) | ... | ... |
-
Please register or sign in to post a comment