1c20dea7 by unknown

20191218

1 parent 9a443bfa
1 <template>
2 <div>
3 <div id="map"></div>
4 </div>
5 </template>
6
7 <script>
8 import "ol/ol.css";
9 import { Map, View } from "ol";
10 import { XYZ } from "ol/source";
11 import VectorSource from "ol/source/Vector";
12 import Point from "ol/geom/Point";
13 import WKT from "ol/format/WKT";
14 import { Select, Draw, Modify, Snap } from "ol/interaction";
15 import { Tile as TileLayer, Vector as VectorLayer } from "ol/layer";
16 import { Circle as CircleStyle, Fill, Stroke, Style } from "ol/style";
17
18 export default {
19 data() {
20 return {
21 map: null
22 };
23 },
24 mounted() {
25 var tdt_vec = new TileLayer({
26 source: new XYZ({
27 url:
28 "http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=394404c8b901574fdc4cdf8c18a98448"
29 })
30 });
31 var tdt_cva = new TileLayer({
32 source: new XYZ({
33 url:
34 "http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=394404c8b901574fdc4cdf8c18a98448"
35 })
36 });
37 // 矢量绘制图层
38 var source = new VectorSource();
39 var vectorLayer = new VectorLayer({
40 source: source,
41 style: new Style({
42 fill: new Fill({
43 color: "rgba(255, 0, 0, 0.2)"
44 }),
45 stroke: new Stroke({
46 color: "#ffcc33",
47 width: 2
48 }),
49 image: new CircleStyle({
50 radius: 7,
51 fill: new Fill({
52 color: "#ffcc33"
53 })
54 })
55 })
56 });
57 this.map = new Map({
58 target: "map",
59 layers: [tdt_vec, tdt_cva, vectorLayer],
60 view: new View({
61 projection: "EPSG:4326",
62 center: [120.79, 27.99],
63 zoom: 12,
64 minZoom: 10,
65 maxZoom: 18
66 })
67 });
68
69 ////select
70 var select = new Select();
71 this.map.addInteraction(select);
72 ////draw
73 var draw = new Draw({
74 source: source,
75 stopClick: true,
76 freehand: false,
77 type: "LineString"
78 });
79 this.map.addInteraction(draw);
80 draw.setActive(true);
81 draw.on("drawend", function(e) {
82 draw.setActive(false);
83 var feature = e.feature;
84 var wktformat = new WKT();
85 console.log("Draw: " + wktformat.writeGeometry(feature.getGeometry()));
86 });
87 ////modify
88 var modify = new Modify({
89 features: select.getFeatures()
90 });
91 this.map.addInteraction(modify);
92 modify.on("modifyend", function(e) {
93 var features = e.features.array_;
94 var wktformat = new WKT();
95 console.log("Modify: " + wktformat.writeGeometry(features[0].getGeometry()));
96 });
97 }
98 };
99 </script>
100
101 <!-- Add "scoped" attribute to limit CSS to this component only -->
102 <style scoped>
103 #map {
104 position: absolute;
105 height: 100%;
106 width: 100%;
107 background-color: white;
108 }
109 </style>
...@@ -61,7 +61,8 @@ ...@@ -61,7 +61,8 @@
61 <span slot="title"><a-icon type="up-square" /><span>OpenLayers</span></span> 61 <span slot="title"><a-icon type="up-square" /><span>OpenLayers</span></span>
62 <a-menu-item key="7_1"><router-link :to="'/map_ol'">OL点与改变视图</router-link></a-menu-item> 62 <a-menu-item key="7_1"><router-link :to="'/map_ol'">OL点与改变视图</router-link></a-menu-item>
63 <a-menu-item key="7_2"><router-link :to="'/map_ol2'">OL面绘制与修改</router-link></a-menu-item> 63 <a-menu-item key="7_2"><router-link :to="'/map_ol2'">OL面绘制与修改</router-link></a-menu-item>
64 <a-menu-item key="7_3"><router-link :to="'/map_ol_measure'">OL量测(未实现)</router-link></a-menu-item> 64 <a-menu-item key="7_3"><router-link :to="'/map_ol3'">OL线绘制与修改</router-link></a-menu-item>
65 <a-menu-item key="7_4"><router-link :to="'/map_ol_measure'">OL量测(未实现)</router-link></a-menu-item>
65 </a-sub-menu> 66 </a-sub-menu>
66 </a-menu> 67 </a-menu>
67 </template> 68 </template>
......
1 /* 1 /*
2 * @Author: jiangbotao 2 * @Author: jiangbotao
3 * @Date: 2019-12-12 17:40:15 3 * @Date: 2019-12-12 17:40:15
4 * @LastEditors: jiangbotao 4 * @LastEditors : jiangbotao
5 * @LastEditTime: 2019-12-18 00:31:32 5 * @LastEditTime : 2019-12-18 20:05:46
6 * @FilePath: \supermapvue\src\router\index.js 6 * @FilePath: \supermapvue\src\router\index.js
7 */ 7 */
8 /* 8 /*
...@@ -170,6 +170,11 @@ export default new Router({ ...@@ -170,6 +170,11 @@ export default new Router({
170 component: () => import('@/components/ol/OL2') 170 component: () => import('@/components/ol/OL2')
171 }, 171 },
172 { 172 {
173 path: '/map_ol3',
174 name: 'Map_OL3',
175 component: () => import('@/components/ol/OL3')
176 },
177 {
173 path: '/map_ol_measure', 178 path: '/map_ol_measure',
174 name: 'Map_OL_measure', 179 name: 'Map_OL_measure',
175 component: () => import('@/components/ol/OL_measure') 180 component: () => import('@/components/ol/OL_measure')
......