|
@@ -23,13 +23,13 @@ import View from "ol/View";
|
|
|
import {get as getProjection, transform} from "ol/proj";
|
|
|
import {TileGrid} from "ol/tilegrid/TileGrid";
|
|
|
import {TileImage} from "ol/source/TileImage";
|
|
|
-import {XYZ, Vector as VectorSource} from "ol/source";
|
|
|
-import {Tile,Vector as VectorLayer} from "ol/layer";
|
|
|
+import {XYZ, Vector as SourceVec} from "ol/source";
|
|
|
+import {Tile,Vector as LayerVec} from "ol/layer";
|
|
|
|
|
|
import {Circle as CircleStyle, Fill, Stroke, Style, Icon} from 'ol/style';
|
|
|
import {Draw, Modify, Snap} from 'ol/interaction';
|
|
|
-// import {OSM, Vector as VectorSource} from 'ol/source';
|
|
|
-// import {Tile as TileLayer, Vector as VectorLayer} from 'ol/layer';
|
|
|
+// import {OSM, Vector as SourceVec} from 'ol/source';
|
|
|
+// import {Tile as TileLayer, Vector as LayerVec} from 'ol/layer';
|
|
|
import {get} from 'ol/proj';
|
|
|
import { Feature } from "ol";
|
|
|
|
|
@@ -53,20 +53,23 @@ export default {
|
|
|
source:null,
|
|
|
draw:null,
|
|
|
snap:null,
|
|
|
- locations:[]
|
|
|
+ locations:[],
|
|
|
+ vector:null,
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
// console.log(this.point)
|
|
|
- var point =JSON.parse(this.point);
|
|
|
+ // var point =JSON.parse(this.point);
|
|
|
|
|
|
this.initdev();
|
|
|
- this.addpoint(point);
|
|
|
+ // this.addpoint(point);
|
|
|
|
|
|
|
|
|
|
|
|
+ var that = this
|
|
|
this.map.on("click", function (e) {
|
|
|
-
|
|
|
+ // console.log(e.coordinate);
|
|
|
+ // that.addMarker(e.coordinate,'专家站点.png',0.2);
|
|
|
});
|
|
|
|
|
|
|
|
@@ -82,28 +85,22 @@ export default {
|
|
|
|
|
|
});
|
|
|
|
|
|
+ // this.map.on('keyup', function (e) {
|
|
|
+ // console.log(e.keyCode);
|
|
|
+ // if (e.keyCode == 27)
|
|
|
+ // that.draw.abortDrawing();
|
|
|
+ // else if (that.e.keyCode == 90 && that.e.ctrlKey) {
|
|
|
+ // console.log(draw);
|
|
|
+ // if (that.typeSelect.value== 'Circle')
|
|
|
+ // that.draw.abortDrawing();
|
|
|
+ // else
|
|
|
+ // that.draw.removeLastPoint()
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+
|
|
|
+
|
|
|
},
|
|
|
methods: {
|
|
|
- transpoints: function (points, type) {
|
|
|
- if (false) {
|
|
|
- return points;
|
|
|
- } else {
|
|
|
- if (type == 1) {
|
|
|
- var pp = [];
|
|
|
- points.forEach(point => {
|
|
|
- pp.push(transform(point, "EPSG:3857", "EPSG:4326"));
|
|
|
- });
|
|
|
- return pp;
|
|
|
- } else {
|
|
|
- var pp = [];
|
|
|
- points.forEach(point => {
|
|
|
- pp.push(transform(point, "EPSG:4326", "EPSG:3857"));
|
|
|
- });
|
|
|
- return pp;
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
initdev: function () {
|
|
|
|
|
|
// function getWMTSLayer(url, layer) {
|
|
@@ -174,8 +171,8 @@ export default {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-this.source = new VectorSource();
|
|
|
-const vector = new VectorLayer({
|
|
|
+this.source = new SourceVec();
|
|
|
+const vector = new LayerVec({
|
|
|
source: this.source,
|
|
|
style: new Style({
|
|
|
fill: new Fill({
|
|
@@ -193,6 +190,7 @@ const vector = new VectorLayer({
|
|
|
}),
|
|
|
}),
|
|
|
});
|
|
|
+ this.vector = vector;
|
|
|
|
|
|
// 创建地图
|
|
|
const map = new Map({
|
|
@@ -219,6 +217,7 @@ const vector = new VectorLayer({
|
|
|
|
|
|
// map.getView().fit([75.0, 20.0, 135.0, 50.0], map.getSize());
|
|
|
this.map = map;
|
|
|
+ // this.addDrawLayer();
|
|
|
this.addInteractions();
|
|
|
var that = this;
|
|
|
|
|
@@ -238,6 +237,8 @@ const vector = new VectorLayer({
|
|
|
});
|
|
|
console.log(draw);
|
|
|
draw.on('drawend',that.getLocation,this);
|
|
|
+ draw.on('drawstar',that.removeDraw,this);
|
|
|
+ // draw.on('drawstart',that.removeDraw,this);
|
|
|
this.draw = draw;
|
|
|
this.map.addInteraction(draw);
|
|
|
let snap = new Snap({source: this.source});
|
|
@@ -251,47 +252,76 @@ const vector = new VectorLayer({
|
|
|
var geo = feature.getGeometry();
|
|
|
var cor = geo.getCoordinates();
|
|
|
this.locations = cor;
|
|
|
+ console.log(2);
|
|
|
},
|
|
|
- changeAddInteractions() {
|
|
|
+ changeAddInteractions(evt) {
|
|
|
this.map.removeInteraction(this.draw);
|
|
|
this.map.removeInteraction(this.snap);
|
|
|
this.addInteractions();
|
|
|
},
|
|
|
+ removeDraw(evt){
|
|
|
+ console.log(this.locations.length);
|
|
|
+ if(this.locations.length > 0){
|
|
|
+ console.log(this.locations.length);
|
|
|
+ this.vector.getSource().clear()
|
|
|
+ }
|
|
|
+ },
|
|
|
addPointArry(){
|
|
|
console.log(1111);
|
|
|
},
|
|
|
- addpoint(addrArry) {
|
|
|
- console.log(addrArry);
|
|
|
- // addpoint: function(addrArry, data, img, type) {
|
|
|
- // var lnglat = this.transpoints(addrArry, 0)[0];
|
|
|
-
|
|
|
+ addMarker(lnglats,icon,size) {
|
|
|
+ console.log(lnglats);
|
|
|
let tamarker = new Feature({
|
|
|
tadata: {
|
|
|
sectionId: "point",
|
|
|
towerNumber: 22,
|
|
|
- // data: data,
|
|
|
- // type: type
|
|
|
}, //这里是用来传值用的,在接下来的一章里(事件)中我会讲到。
|
|
|
- geometry: new Point(addrArry) //这里是点坐标的位置,这里要注意fromLonLat
|
|
|
+ geometry: new Point(lnglats) //这里是点坐标的位置,这里要注意fromLonLat
|
|
|
});
|
|
|
- console.log(tamarker);
|
|
|
tamarker.setStyle(
|
|
|
new Style({
|
|
|
image: new Icon({
|
|
|
color: "#eee",
|
|
|
crossOrigin: "anonymous",
|
|
|
- src: require("../../assets/images/组件1.png") //本地的样式
|
|
|
+ src: require("../../assets/images/icons/" + icon) //本地的样式
|
|
|
})
|
|
|
})
|
|
|
); //这里是样式
|
|
|
- var markerta = new VectorLayer({
|
|
|
- source: new VectorSource({
|
|
|
+ var markerta = new LayerVec({
|
|
|
+ source: new SourceVec({
|
|
|
features: [tamarker] //这里放的就是之前的那个点,如果要放置多个点直接push到这里面就行了
|
|
|
})
|
|
|
});
|
|
|
- console.log(markerta);
|
|
|
this.map.addLayer(markerta); //这里是执行,执行之后点就出来了
|
|
|
- }
|
|
|
+ },
|
|
|
+ addline: function() {
|
|
|
+
|
|
|
+ var points = [
|
|
|
+ [118.78, 32.04],
|
|
|
+ [118.88, 32.14]
|
|
|
+ ]
|
|
|
+
|
|
|
+ let line = new Feature({
|
|
|
+ tadata: {
|
|
|
+ sectionId: "line",
|
|
|
+ towerNumber: 22
|
|
|
+ },
|
|
|
+ geometry: new LineString(points)
|
|
|
+ }); //这里要注意写fromLonLat,很重要
|
|
|
+ line.setStyle(new Style({
|
|
|
+ stroke: new Stroke({
|
|
|
+ width: 3,
|
|
|
+ color: "#008000"
|
|
|
+ })
|
|
|
+ }));
|
|
|
+ this.linevectorLayer = new LayerVec({
|
|
|
+ source: new SourceVec({
|
|
|
+ features: [line] //要绘制多段线,直接push到这里面就行了
|
|
|
+ })
|
|
|
+ });
|
|
|
+ this.map.addLayer(this.linevectorLayer); //这里是执行,执行之后点就出来了
|
|
|
+
|
|
|
+ },
|
|
|
}
|
|
|
};
|
|
|
</script>
|