Commit 045f3542 by jack

围栏范围不让编辑

1 parent 2f4b861b
<template> <template>
<!-- 围栏调用地图弹框 --> <!-- 围栏调用地图弹框 -->
<!-- <el-dialog id="fenceMapModal1" :visible="fenceMapModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="1200px" top="10vh"> --> <!-- <el-dialog id="fenceMapModal1" :visible="fenceMapModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="1200px" top="10vh"> -->
<!-- <div class="dialog-header" slot="title"> <!-- <div class="dialog-header" slot="title">
<h2 class="header-title">地图引用</h2> <h2 class="header-title">地图引用</h2>
</div> --> </div> -->
<div class="fence-map" :visible="fenceMapModalVisible" v-loading="mapLoading">
<div class="fence-map" :visible="fenceMapModalVisible" v-loading="mapLoading"> <!-- <el-form :model="form" ref="fenceMapForm" :rules="rules" :inline="true" size="mini" >
<!-- <el-form :model="form" ref="fenceMapForm" :rules="rules" :inline="true" size="mini" >
<el-form-item label="经度" prop="lng"> <el-form-item label="经度" prop="lng">
<el-input v-model="form.lng" style="width:100px" @change="transfer"></el-input> <el-input v-model="form.lng" style="width:100px" @change="transfer"></el-input>
</el-form-item> </el-form-item>
...@@ -24,91 +23,88 @@ ...@@ -24,91 +23,88 @@
</el-form-item> </el-form-item>
<el-form-item><el-button type="primary" @click="updateFence">更新围栏</el-button></el-form-item> <el-form-item><el-button type="primary" @click="updateFence">更新围栏</el-button></el-form-item>
</el-form>--> </el-form>-->
<div id="mapContainer" class="map-container"></div> <div id="mapContainer" class="map-container"></div>
<fence-map-controll @onRefreshMap="refreshMap" :isModalMap="true"></fence-map-controll> <fence-map-controll @onRefreshMap="refreshMap" :isModalMap="true"></fence-map-controll>
<div class="map-seacrh-wrap"> <div class="map-seacrh-wrap">
<!-- <input type="text" id="fenceMapSearch"> --> <!-- <input type="text" id="fenceMapSearch"> -->
<el-input placeholder="请输入位置" id="fenceMapSearch" size="small" v-model="fenceMapSearch"> <el-input placeholder="请输入位置" id="fenceMapSearch" size="small" v-model="fenceMapSearch">
<template slot="prepend">搜索</template> <template slot="prepend">搜索</template>
<!-- <el-button slot="append" icon="el-icon-search" @click="search"></el-button> --> <!-- <el-button slot="append" icon="el-icon-search" @click="search"></el-button> -->
</el-input> </el-input>
</div> </div>
</div> </div>
<!-- <div slot="footer" class="dialog-footer"> <!-- <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="sure" size="small">确认</el-button> <el-button type="primary" @click="sure" size="small">确认</el-button>
<el-button @click="$emit('onFenceMapModalChange', false)" size="small">关闭</el-button> <el-button @click="$emit('onFenceMapModalChange', false)" size="small">关闭</el-button>
</div> --> </div> -->
<!-- </el-dialog> --> <!-- </el-dialog> -->
<!-- 围栏调用地图弹框 /-->
<!-- 围栏调用地图弹框 /-->
</template> </template>
<script> <script>
import remoteLoad from '@/utils/remoteLoad.js' import remoteLoad from "@/utils/remoteLoad.js";
import mapService from '@/utils/mapService.js' import mapService from "@/utils/mapService.js";
import FenceMapControll from './fenceMapControll' import FenceMapControll from "./fenceMapControll";
import Constants from '@/utils/constants' import Constants from "@/utils/constants";
export default{ export default {
props: ['init'], props: ["init"],
data(){ data() {
return { return {
fenceMapSearch: '', fenceMapSearch: "",
geolocation: null, geolocation: null,
circleEditor: null, circleEditor: null,
areaCodeMap:"", areaCodeMap: "",
polygons:[], polygons: [],
polygonEditor:null, polygonEditor: null,
autoCenterMarker:null, autoCenterMarker: null,
marke:null, marke: null,
fenceMapModalVisible:false, fenceMapModalVisible: false,
polygon:null, polygon: null,
mapDot:true, mapDot: true,
circle: null, circle: null,
tableData:[], tableData: [],
transferTimeoutId: undefined, transferTimeoutId: undefined,
geocoder: null, geocoder: null,
transferFlag: null, transferFlag: null,
opts : { opts: {
subdistrict: 1, //返回下一级行政区 subdistrict: 1, //返回下一级行政区
showbiz:false //最后一级返回街道信息 showbiz: false, //最后一级返回街道信息
}, },
mapObj: null, mapObj: null,
fenceType: 'polygon', //'area' 'polygon' fenceType: "polygon", //'area' 'polygon'
lng: '', lng: "",
lat: '', lat: "",
radius: '', radius: "",
fenceCircle: null, fenceCircle: null,
fenceCenter: null, fenceCenter: null,
areaCode: '', areaCode: "",
isFenceInit: false, isFenceInit: false,
mapLoading: false, mapLoading: false,
polygonPath: [ polygonPath: [
/* [116.403322, 39.920255], /* [116.403322, 39.920255],
[116.410703, 39.897555], [116.410703, 39.897555],
[116.402292, 39.892353], [116.402292, 39.892353],
[116.389846, 39.891365] */ [116.389846, 39.891365] */
] ],
} };
}, },
mounted(){ mounted() {},
watch: {
}, lng(newVal) {
watch: { //this.transfer()
lng(newVal){ },
//this.transfer() lat(newVal) {
}, //this.transfer()
lat(newVal){ },
//this.transfer() /* mapData(newVal){
},
/* mapData(newVal){
const fenceData = newVal; const fenceData = newVal;
this.initMapPromise.then(()=>{console.log(fenceData) this.initMapPromise.then(()=>{console.log(fenceData)
if(fenceData.fenceType === 'circle'){ if(fenceData.fenceType === 'circle'){
...@@ -116,509 +112,486 @@ export default{ ...@@ -116,509 +112,486 @@ export default{
} }
}) })
} */ } */
}, },
async created () { async created() {
if(window.AMap){ if (window.AMap) {
this.initMap() this.initMap();
}else{ } else {
await remoteLoad(`${Constants.AMAP_URL}`, true); await remoteLoad(`${Constants.AMAP_URL}`, true);
this.initMap() this.initMap();
} }
}, },
methods: { methods: {
initMap(){ initMap() {
this.initMapPromise = new Promise((resolve, reject)=>{ this.initMapPromise = new Promise((resolve, reject) => {
let check = ()=>{ let check = () => {
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded); this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);
return setTimeout(()=>{ return setTimeout(() => {
if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){ if (
window.AMap = AMap; "AMap" in window &&
this.mapObj = mapService.init('mapContainer'); typeof AMap.Map == "function" &&
!this.mapObj
this.bindContextMenu(); ) {
this.bindSearch(); window.AMap = AMap;
resolve() this.mapObj = mapService.init("mapContainer");
}else{
this.checkMapLoaded = check() this.bindContextMenu();
} this.bindSearch();
}, 100) resolve();
} } else {
this.checkMapLoaded = check(); this.checkMapLoaded = check();
}) }
}, }, 100);
bindSearch(){ };
const self = this; this.checkMapLoaded = check();
this.auto = new AMap.Autocomplete({ });
input: 'fenceMapSearch' },
}); bindSearch() {
const self = this;
this.autoCenterMarker = new AMap.Marker({ this.auto = new AMap.Autocomplete({
icon: require('@/assets/images/auto-center-marker.gif'), input: "fenceMapSearch",
map: this.mapObj, });
offset: new AMap.Pixel(-12,-12),
visible: false this.autoCenterMarker = new AMap.Marker({
}); icon: require("@/assets/images/auto-center-marker.gif"),
map: this.mapObj,
this.autoCenterMarker.on('rightclick', (e)=> { offset: new AMap.Pixel(-12, -12),
if(self.mapObj.getAllOverlays('circle').length){ visible: false,
window.mapMenu.contextMenu.open(self.mapObj, e.lnglat); });
self.contextMenuPositon = e.lnglat; //右键菜单位置
} this.autoCenterMarker.on("rightclick", (e) => {
}); if (self.mapObj.getAllOverlays("circle").length) {
window.mapMenu.contextMenu.open(self.mapObj, e.lnglat);
AMap.event.addListener(this.auto, 'select', (e)=>{ self.contextMenuPositon = e.lnglat; //右键菜单位置
if(e.poi && e.poi.location){ }
this.mapObj.setCenter(e.poi.location); });
this.autoCenterMarker.setPosition(e.poi.location);
/*for(var i = 0, l = this.polygons.length; i < l; i++) { AMap.event.addListener(this.auto, "select", (e) => {
if (e.poi && e.poi.location) {
this.mapObj.setCenter(e.poi.location);
this.autoCenterMarker.setPosition(e.poi.location);
/*for(var i = 0, l = this.polygons.length; i < l; i++) {
this.polygons[i].setMap(null); this.polygons[i].setMap(null);
}*/ }*/
this.autoCenterMarker.show(); this.autoCenterMarker.show();
this.mapObj.add(this.autoCenterMarker); this.mapObj.add(this.autoCenterMarker);
//this.form.lng = e.poi.location.lng; //this.form.lng = e.poi.location.lng;
//this.form.lat = e.poi.location.lat; //this.form.lat = e.poi.location.lat;
//this.contextMenuPositon = e.poi.location //this.contextMenuPositon = e.poi.location
//window.mapMenu.contextMenu.open(this.mapObj, mapService.getLngLat(e.poi.location.lng, e.poi.location.lat)) //window.mapMenu.contextMenu.open(this.mapObj, mapService.getLngLat(e.poi.location.lng, e.poi.location.lat))
}
}
this.mapObj.setZoom(14);
this.mapObj.setZoom(14); });
},
}); bindContextMenu() {
const self = this;
window.mapMenu = new ContextMenu(this.mapObj); //暴露mapMenu onclick要用
}, function ContextMenu(map) {
bindContextMenu(){ var me = this;
const self = this; this.contextMenuPositon = null;
window.mapMenu = new ContextMenu(this.mapObj);//暴露mapMenu onclick要用 const click = window.proxy ? `window.proxy.mapMenu` : `mapMenu`;
function ContextMenu(map) { this.contextMenu = new AMap.ContextMenu({
var me = this; isCustom: true,
this.contextMenuPositon = null; content: `<div class="context_menu" >
const click = window.proxy ? `window.proxy.mapMenu`: `mapMenu`
this.contextMenu = new AMap.ContextMenu({
isCustom: true,
content: `<div class="context_menu" >
<p onclick="${click}.moveCenter()"><span>设置围栏中心</span></p> <p onclick="${click}.moveCenter()"><span>设置围栏中心</span></p>
</div>` </div>`,
}); });
map.on('rightclick', (e)=> { map.on("rightclick", (e) => {
if(self.mapObj.getAllOverlays('circle').length){ if (self.mapObj.getAllOverlays("circle").length) {
this.contextMenu.open(map, e.lnglat); this.contextMenu.open(map, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置 self.contextMenuPositon = e.lnglat; //右键菜单位置
} }
}); });
} }
ContextMenu.prototype.moveCenter = function addPOI() { ContextMenu.prototype.moveCenter = function addPOI() {
self.moveCenter() self.moveCenter();
this.contextMenu.close(); this.contextMenu.close();
}; };
}, },
drawFence(){ drawFence() {
if(!this.lng && !this.lat){ if (!this.lng && !this.lat) {
this.mapLoading = true; this.mapLoading = true;
this.getCurrentPosition().then((pos)=>{ this.getCurrentPosition().then((pos) => {
this.lng = pos.lng; this.lng = pos.lng;
this.lat = pos.lat; this.lat = pos.lat;
this.radius = 150; this.radius = 150;
this.drawFenceCircle(pos) this.drawFenceCircle(pos);
this.$emit('onUpdateMapData',{ this.$emit("onUpdateMapData", {
lng: this.lng, lng: this.lng,
lat: this.lat, lat: this.lat,
radius: this.radius radius: this.radius,
}); });
this.mapLoading = false; this.mapLoading = false;
}) });
}else{ } else {
this.drawFenceCircle(mapService.getLngLat(this.lng, this.lat)) this.drawFenceCircle(mapService.getLngLat(this.lng, this.lat));
} }
},
drawFenceCircle(fenceCenter) {
}, const mapObj = this.mapObj;
drawFenceCircle(fenceCenter){
const mapObj = this.mapObj; if (this.fenceCircle) {
this.fenceCircle.setCenter(mapService.getLngLat(this.lng, this.lat));
if(this.fenceCircle){ } else {
this.fenceCircle.setCenter(mapService.getLngLat(this.lng, this.lat)) this.fenceCircle = new AMap.Circle({
}else{ map: mapObj,
this.fenceCircle = new AMap.Circle({ center: fenceCenter,
map: mapObj, radius: this.radius * 1,
center: fenceCenter, strokeColor: "#F33",
radius: this.radius*1, strokeOpacity: 1,
strokeColor: "#F33", strokeWeight: 3,
strokeOpacity: 1, fillColor: "ee2200",
strokeWeight: 3, fillOpacity: 0.35,
fillColor: "ee2200", });
fillOpacity: 0.35 mapObj.plugin(["AMap.CircleEditor"], () => {
}); this.circleEditor = new AMap.CircleEditor(mapObj, this.fenceCircle);
mapObj.plugin(["AMap.CircleEditor"],()=>{
this.circleEditor = new AMap.CircleEditor(mapObj, this.fenceCircle); AMap.event.addListener(this.circleEditor, "adjust", (e) => {
this.radius = e.radius / 1;
AMap.event.addListener(this.circleEditor, 'adjust', (e)=>{ this.$emit("onUpdateMapData", {
this.radius = e.radius/1; lng: this.lng,
this.$emit('onUpdateMapData',{ lat: this.lat,
lng: this.lng, radius: this.radius,
lat: this.lat, });
radius: this.radius });
});
}); AMap.event.addListener(this.circleEditor, "move", (e) => {
this.lng = e.lnglat.lng;
AMap.event.addListener(this.circleEditor, 'move', (e)=>{ this.lat = e.lnglat.lat;
this.lng = e.lnglat.lng; this.$emit("onUpdateMapData", {
this.lat = e.lnglat.lat; lng: this.lng,
this.$emit('onUpdateMapData',{ lat: this.lat,
lng: this.lng, });
lat: this.lat, });
}); //this.circleEditor.open();
}); this.circleEditor.close();
this.circleEditor.open(); });
}); }
}
mapService.setFitView();
mapService.setFitView() mapObj.setZoom(14);
mapObj.setZoom(14); },
}, initFence(data) {
initFence(data){ this._mapPromiseTimeout && clearTimeout(this._mapPromiseTimeout);
this._mapPromiseTimeout && clearTimeout(this._mapPromiseTimeout) if (this.initMapPromise) {
if(this.initMapPromise){ if (data) {
if(data){ this.fenceType = data.fenceType;
this.fenceType = data.fenceType if (this.fenceType === "circle") {
if(this.fenceType === 'circle'){ this.lng = data.lng;
this.lng = data.lng; this.lat = data.lat;
this.lat = data.lat; this.radius = data.radius;
this.radius = data.radius; } else if (this.fenceType === "area") {
}else if(this.fenceType === 'area'){ this.areaCode = data.areaCode;
this.areaCode = data.areaCode } else if (this.fenceType === "polygon") {
}else if(this.fenceType === 'polygon'){ if (data.polygonPath && data.polygonPath.length) {
if(data.polygonPath && data.polygonPath.length){ this.polygonPath = data.polygonPath;
this.polygonPath = data.polygonPath }
} }
} }
}
this.initMapPromise.then(()=>{
if(this.fenceType === 'circle'){
this.drawFence()
}else if(this.fenceType === 'area'){
this.drawArea()
}else if(this.fenceType === 'polygon'){
this.drawPolygon()
}
})
}else{
this._mapPromiseTimeout = setTimeout(() => {console.log('timeout')
this.initFence(data)
}, 100);
}
},
updateFence(data){
this.mapObj.clearMap()
this.fenceType = data.fenceType
this.polyEditor && this.polyEditor.close()
this.mouseTool && this.mouseTool.close()
if(this.fenceType === 'circle'){
this.fenceCircle = null;
if(data.lng){
this.lng = data.lng;
}
if(data.lat){
this.lat = data.lat;
}
if(data.radius){
this.radius = data.radius;
}
this.drawFence()
}else if(this.fenceType === 'area'){
if(data.areaCode){
this.areaCode = data.areaCode
}
if(this.areaCode){
this.drawArea()
}
}else if(this.fenceType === 'polygon'){
this.drawPolygon()
}
},
drawArea(){
let _this = this;
let areaCode = this.areaCode?this.areaCode.toString():'中国'
this.mapObj.clearMap()
for (var i = 0, l =this.polygons.length; i < l; i++) {
this.polygons[i].setMap(null);
}
let district,lng,lat
this.mapLoading = true;
AMap.service('AMap.DistrictSearch', function() {
var opts = {
subdistrict: 1, //返回下一级行政区
extensions: 'all',
showbiz:false //最后一级返回街道信息
};
areaCode === "中国"?delete opts.extensions :delete opts.showbiz
district = new AMap.DistrictSearch(opts);
district.setLevel('district');
district.search(areaCode, function(status, result) {
var bounds = result.districtList[0].boundaries;
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
let polygon = new AMap.Polygon({
map: _this.mapObj,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: '#CCF3FF',
strokeColor: '#CC66CC',
});
_this.polygons.push(polygon);
}
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
let center = mapService.getLngLat(lng,lat);
mapService.setFitView();
//map.setZoom(10);
_this.mapLoading = false;
}
});
});
},
moveCenter(){
this.lng = this.contextMenuPositon.lng;
this.lat = this.contextMenuPositon.lat;
let center = mapService.getLngLat(this.lng, this.lat);
this.fenceCircle.setCenter(center);
this.$emit('onUpdateMapData', {
lng: this.lng,
lat: this.lat
})
},
getCurrentPosition(){
const mapObj = this.mapObj;
const self = this;
return new Promise((resolve, reject)=>{
mapObj.plugin('AMap.Geolocation', function(){
self.geolocation = new AMap.Geolocation();
self.geolocation.getCurrentPosition();
AMap.event.addListener(self.geolocation, 'complete', function(e){//返回定位信息
var lnglatXY = mapService.getLngLat(e.position.lng, e.position.lat);
resolve(lnglatXY)
});
AMap.event.addListener(self.geolocation, 'error', function(e){//返回定位出错信息
resolve(mapObj.getCenter())
});
});
})
},
drawPolygon(){
const mapObj = this.mapObj;
const self = this;
if(this.polygonPath.length){
self.polygon = new AMap.Polygon({
path: this.polygonPath,
strokeColor: "#FF33FF",
strokeWeight: 6,
strokeOpacity: 0.2,
fillOpacity: 0.4,
fillColor: '#1791fc',
zIndex: 50,
})
mapObj.add(self.polygon)
mapObj.setFitView([ self.polygon ])
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon)
self.polyEditor.open()
self.bindPolyEvent(self.polyEditor)
}else{
self.mouseTool = new AMap.MouseTool(mapObj)
self.mouseTool.polygon({
strokeColor: "#FF33FF",
strokeOpacity: 1,
strokeWeight: 6,
strokeOpacity: 0.2,
fillColor: '#1791fc',
fillOpacity: 0.4,
// 线样式还支持 'dashed'
strokeStyle: "solid",
// strokeStyle是dashed时有效
// strokeDasharray: [30,10],
})
self.mouseTool.on('draw', function(event) {
// event.obj 为绘制出来的覆盖物对象
self.polygon = event.obj;
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon)
self.polyEditor.open()
self.bindPolyEvent(self.polyEditor)
self.mouseTool.close()
self.emitPolyEvent()
})
}
},
emitPolyEvent(){
let pathArr = this.polygon.getPath()
let resultArr = pathArr.map((item)=>{
return [item.lng, item.lat]
})
this.polygonPath = resultArr this.initMapPromise.then(() => {
this.$emit('onUpdateMapData',{ if (this.fenceType === "circle") {
polygonPath: this.polygonPath this.drawFence();
}); } else if (this.fenceType === "area") {
console.log(resultArr.join('|')) this.drawArea();
}, } else if (this.fenceType === "polygon") {
bindPolyEvent(polyEditor){ this.drawPolygon();
const self = this }
polyEditor.on('addnode', function(event) { });
console.log('触发事件:addnode') } else {
self.emitPolyEvent() this._mapPromiseTimeout = setTimeout(() => {
}) console.log("timeout");
this.initFence(data);
}, 100);
}
},
updateFence(data) {
this.mapObj.clearMap();
polyEditor.on('adjust', function(event) { this.fenceType = data.fenceType;
console.log('触发事件:adjust')
self.emitPolyEvent()
})
polyEditor.on('removenode', function(event) { this.polyEditor && this.polyEditor.close();
console.log('触发事件:removenode') this.mouseTool && this.mouseTool.close();
self.emitPolyEvent()
})
polyEditor.on('end', function(event) { if (this.fenceType === "circle") {
console.log('触发事件: end') this.fenceCircle = null;
self.emitPolyEvent() if (data.lng) {
// event.target 即为编辑后的多边形对象 this.lng = data.lng;
}) }
}, if (data.lat) {
transfer(){ this.lat = data.lat;
this.transferTimeoutId && window.clearTimeout(this.transferTimeoutId); }
this.transferTimeoutId = window.setTimeout(()=>{ if (data.radius) {
const flag = new Date(); this.radius = data.radius;
this.transferFlag = flag; }
if(!this.geocoder){
mapService.getGeocoder().then((gc)=>{ this.drawFence();
this.geocoder = gc; } else if (this.fenceType === "area") {
this.getAddress(flag); if (data.areaCode) {
}); this.areaCode = data.areaCode;
}else{ }
this.getAddress(flag); if (this.areaCode) {
} this.drawArea();
}, 500) }
}, } else if (this.fenceType === "polygon") {
getAddress(flag){ this.drawPolygon();
}
const lnglatXY = [this.form.lng, this.form.lat]; },
this.transferAddr = ''; drawArea() {
let _this = this;
this.geocoder.getAddress(lnglatXY, (status, result)=>{ let areaCode = this.areaCode ? this.areaCode.toString() : "中国";
if(flag == this.transferFlag){
if (status === 'complete' && result.info === 'OK') {//获取地址成功 this.mapObj.clearMap();
this.form.transferAddr = result.regeocode.formattedAddress;
this.$emit('onUpdateMapData',{ for (var i = 0, l = this.polygons.length; i < l; i++) {
lng: this.form.lng, this.polygons[i].setMap(null);
lat: this.form.lat, }
address: this.form.transferAddr,
radius: this.form.radius let district, lng, lat;
}); this.mapLoading = true;
AMap.service("AMap.DistrictSearch", function () {
}else{ var opts = {
this.form.transferAddr = ''; subdistrict: 1, //返回下一级行政区
extensions: "all",
} showbiz: false, //最后一级返回街道信息
} };
areaCode === "中国" ? delete opts.extensions : delete opts.showbiz;
district = new AMap.DistrictSearch(opts);
district.setLevel("district");
district.search(areaCode, function (status, result) {
var bounds = result.districtList[0].boundaries;
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
let polygon = new AMap.Polygon({
map: _this.mapObj,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: "#CCF3FF",
strokeColor: "#CC66CC",
});
_this.polygons.push(polygon);
}
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
let center = mapService.getLngLat(lng, lat);
mapService.setFitView();
//map.setZoom(10);
_this.mapLoading = false;
}
});
});
},
moveCenter() {
this.lng = this.contextMenuPositon.lng;
this.lat = this.contextMenuPositon.lat;
let center = mapService.getLngLat(this.lng, this.lat);
this.fenceCircle.setCenter(center);
this.$emit("onUpdateMapData", {
lng: this.lng,
lat: this.lat,
});
},
getCurrentPosition() {
const mapObj = this.mapObj;
const self = this;
return new Promise((resolve, reject) => {
mapObj.plugin("AMap.Geolocation", function () {
self.geolocation = new AMap.Geolocation();
self.geolocation.getCurrentPosition();
AMap.event.addListener(self.geolocation, "complete", function (e) {
//返回定位信息
var lnglatXY = mapService.getLngLat(e.position.lng, e.position.lat);
resolve(lnglatXY);
});
AMap.event.addListener(self.geolocation, "error", function (e) {
//返回定位出错信息
resolve(mapObj.getCenter());
});
});
});
},
drawPolygon() {
const mapObj = this.mapObj;
const self = this;
if (this.polygonPath.length) {
self.polygon = new AMap.Polygon({
path: this.polygonPath,
strokeColor: "#FF33FF",
strokeWeight: 6,
strokeOpacity: 0.2,
fillOpacity: 0.4,
fillColor: "#1791fc",
zIndex: 50,
});
mapObj.add(self.polygon);
mapObj.setFitView([self.polygon]);
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon);
self.polyEditor.open();
self.bindPolyEvent(self.polyEditor);
} else {
self.mouseTool = new AMap.MouseTool(mapObj);
self.mouseTool.polygon({
strokeColor: "#FF33FF",
strokeOpacity: 1,
strokeWeight: 6,
strokeOpacity: 0.2,
fillColor: "#1791fc",
fillOpacity: 0.4,
// 线样式还支持 'dashed'
strokeStyle: "solid",
// strokeStyle是dashed时有效
// strokeDasharray: [30,10],
});
self.mouseTool.on("draw", function (event) {
// event.obj 为绘制出来的覆盖物对象
self.polygon = event.obj;
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon);
self.polyEditor.open();
self.bindPolyEvent(self.polyEditor);
self.mouseTool.close();
self.emitPolyEvent();
});
}
},
emitPolyEvent() {
let pathArr = this.polygon.getPath();
let resultArr = pathArr.map((item) => {
return [item.lng, item.lat];
});
this.polygonPath = resultArr;
this.$emit("onUpdateMapData", {
polygonPath: this.polygonPath,
});
console.log(resultArr.join("|"));
},
bindPolyEvent(polyEditor) {
const self = this;
polyEditor.on("addnode", function (event) {
console.log("触发事件:addnode");
self.emitPolyEvent();
});
polyEditor.on("adjust", function (event) {
console.log("触发事件:adjust");
self.emitPolyEvent();
});
polyEditor.on("removenode", function (event) {
console.log("触发事件:removenode");
self.emitPolyEvent();
});
polyEditor.on("end", function (event) {
console.log("触发事件: end");
self.emitPolyEvent();
// event.target 即为编辑后的多边形对象
});
},
transfer() {
this.transferTimeoutId && window.clearTimeout(this.transferTimeoutId);
this.transferTimeoutId = window.setTimeout(() => {
const flag = new Date();
this.transferFlag = flag;
if (!this.geocoder) {
mapService.getGeocoder().then((gc) => {
this.geocoder = gc;
this.getAddress(flag);
});
} else {
this.getAddress(flag);
}
}, 500);
},
getAddress(flag) {
const lnglatXY = [this.form.lng, this.form.lat];
this.transferAddr = "";
this.geocoder.getAddress(lnglatXY, (status, result) => {
if (flag == this.transferFlag) {
if (status === "complete" && result.info === "OK") {
//获取地址成功
this.form.transferAddr = result.regeocode.formattedAddress;
this.$emit("onUpdateMapData", {
lng: this.form.lng,
lat: this.form.lat,
address: this.form.transferAddr,
radius: this.form.radius,
}); });
}, } else {
refreshMap() { this.form.transferAddr = "";
}
} }
});
}, },
components:{ refreshMap() {},
FenceMapControll },
} components: {
} FenceMapControll,
},
};
</script> </script>
<style scoped> <style scoped>
.fence-map{ .fence-map {
position: relative; position: relative;
} }
.fence-map .map-container{ .fence-map .map-container {
width: 100%; width: 100%;
height: 500px; height: 500px;
} }
.fence-map .map-seacrh-wrap{ .fence-map .map-seacrh-wrap {
position: absolute; position: absolute;
top: 40px; top: 40px;
left: 10px; left: 10px;
z-index: 1000; z-index: 1000;
} }
.el-form-item{ .el-form-item {
margin: -20px 0 20px 10px; margin: -20px 0 20px 10px;
} }
</style> </style>
<style lang="scss"> <style lang="scss">
.context_menu{ .context_menu {
min-width: 10em; min-width: 10em;
background-color: #fff; background-color: #fff;
padding: 10px; padding: 10px;
border: 1px solid #efefef; border: 1px solid #efefef;
border-radius: 2px; border-radius: 2px;
cursor: pointer; cursor: pointer;
&>p{ & > p {
margin: 0; margin: 0;
i{ i {
font-size: 18px; font-size: 18px;
color: #094; color: #094;
margin-right: 5px; margin-right: 5px;
} }
i,span{ i,
vertical-align: middle; span {
} vertical-align: middle;
} }
} }
}
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -2,18 +2,8 @@ ...@@ -2,18 +2,8 @@
<div> <div>
<h2>基础信息</h2> <h2>基础信息</h2>
<el-divider></el-divider> <el-divider></el-divider>
<el-form <el-form ref="shopForm" :model="form" :rules="rules" label-width="135px" :inline="true">
ref="shopForm" <el-form-item class="special-shop-input" label="特约店名称:" prop="specialShopName">
:model="form"
:rules="rules"
label-width="135px"
:inline="true"
>
<el-form-item
class="special-shop-input"
label="特约店名称:"
prop="specialShopName"
>
<!-- <el-cascader <!-- <el-cascader
:key="refresh" :key="refresh"
ref="specialShopCascader" ref="specialShopCascader"
...@@ -28,53 +18,24 @@ ...@@ -28,53 +18,24 @@
clearable clearable
:disabled="readonlyStatus" :disabled="readonlyStatus"
></el-cascader> --> ></el-cascader> -->
<el-popover <el-popover v-model="filterVisible" placement="bottom-start" width="400" @show="selectStore" trigger="click">
v-model="filterVisible"
placement="bottom-start"
width="400"
@show="selectStore"
trigger="click"
>
<div v-loading="loading"> <div v-loading="loading">
<el-input <el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small">
placeholder="输入关键字进行过滤"
v-model="filterText"
size="small"
>
</el-input> </el-input>
<el-tree <el-tree style="max-height:50vh;overflow:auto" class="filter-tree" :data="filterTextData" :filter-node-method="filterNode" highlight-current ref="tree" node-key="id" check-on-click-node>
style="max-height:50vh;overflow:auto"
class="filter-tree"
:data="filterTextData"
:filter-node-method="filterNode"
highlight-current
ref="tree"
node-key="id"
check-on-click-node
>
</el-tree> </el-tree>
<p style="text-align: right; margin-top: 10px"> <p style="text-align: right; margin-top: 10px">
<el-button @click="filterConfirm" type="primary">确定</el-button> <el-button @click="filterConfirm" type="primary">确定</el-button>
<el-button @click="closeFilter">取消</el-button> <el-button @click="closeFilter">取消</el-button>
</p> </p>
</div> </div>
<el-input <el-input v-model="form.specialShopName" :placeholder="form.specialShopName || '请选择特约店名称'" slot="reference">
v-model="form.specialShopName"
:placeholder="form.specialShopName || '请选择特约店名称'"
slot="reference"
>
</el-input> </el-input>
</el-popover> </el-popover>
</el-form-item> </el-form-item>
<el-form-item label="特约店编码:"> <el-form-item label="特约店编码:">
<el-input <el-input v-model="form.specialShopCode" :size="btn_size" readonly disabled Placeholder="特约店编码"></el-input>
v-model="form.specialShopCode"
:size="btn_size"
readonly
disabled
Placeholder="特约店编码"
></el-input>
</el-form-item> </el-form-item>
<el-form-item label="特约店级别:"> <el-form-item label="特约店级别:">
<el-radio-group v-model="form.shopLevel"> <el-radio-group v-model="form.shopLevel">
...@@ -85,82 +46,34 @@ ...@@ -85,82 +46,34 @@
<h2>特约店围栏配置</h2> <h2>特约店围栏配置</h2>
<el-divider></el-divider> <el-divider></el-divider>
<el-form-item label="特约店线路名称:" prop="fenceName"> <el-form-item label="特约店线路名称:" prop="fenceName">
<el-input <el-input v-model.trim="form.fenceName" :size="btn_size" maxlength="200" placeholder="请输入特约店线路名称" :disabled="readonlyStatus"></el-input>
v-model.trim="form.fenceName"
:size="btn_size"
maxlength="200"
placeholder="请输入特约店线路名称"
:disabled="readonlyStatus"
></el-input>
</el-form-item> </el-form-item>
<el-form-item label="监控范围:" prop="radius"> <el-form-item label="监控范围:" prop="radius">
<el-input <el-input v-model="form.radius" :size="btn_size" Placeholder="请输入半径" style="width:140px" maxlength="10" :disabled="true">
v-model="form.radius"
:size="btn_size"
Placeholder="请输入半径"
style="width:140px"
maxlength="10"
:disabled="readonlyStatus"
>
<template slot="append">M</template> <template slot="append">M</template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button <el-button type="primary" :size="btn_size" @click="updateFence" :disabled="readonlyStatus">更新线路</el-button>
type="primary"
:size="btn_size"
@click="updateFence"
:disabled="readonlyStatus"
>更新线路</el-button
>
</el-form-item> </el-form-item>
<div> <div>
<el-form-item label="经度:" prop="lng"> <el-form-item label="经度:" prop="lng">
<el-input <el-input v-model="form.lng" size="small" :disabled="readonlyStatus"></el-input>
v-model="form.lng"
size="small"
:disabled="readonlyStatus"
></el-input>
</el-form-item> </el-form-item>
<el-form-item label="纬度:" prop="lat"> <el-form-item label="纬度:" prop="lat">
<el-input <el-input v-model="form.lat" size="small" :disabled="readonlyStatus"></el-input>
v-model="form.lat"
size="small"
:disabled="readonlyStatus"
></el-input>
</el-form-item> </el-form-item>
<el-form-item label="特约店详细地址:" prop="analysisAddress"> <el-form-item label="特约店详细地址:" prop="analysisAddress">
<el-input <el-input v-model="form.analysisAddress" size="medium" placeholder="自动生成" readonly disabled style="width:350px"></el-input>
v-model="form.analysisAddress"
size="medium"
placeholder="自动生成"
readonly
disabled
style="width:350px"
></el-input>
</el-form-item> </el-form-item>
</div> </div>
</el-form> </el-form>
<div <div class="ibox-content" style="height: 500px; padding:0 20px;z-index: 100">
class="ibox-content" <fence-map :mapData="mapData" @onUpdateMapData="updateMapData" ref="fenceMap">
style="height: 500px; padding:0 20px;z-index: 100"
>
<fence-map
:mapData="mapData"
@onUpdateMapData="updateMapData"
ref="fenceMap"
>
</fence-map> </fence-map>
</div> </div>
<div class="fenceModalfooter"> <div class="fenceModalfooter">
<el-button <el-button v-if="!readonlyStatus" type="primary" @click="saveFence" size="small" :loading="submitting">{{ btnText }}</el-button>
v-if="!readonlyStatus"
type="primary"
@click="saveFence"
size="small"
:loading="submitting"
>{{ btnText }}</el-button
>
<el-button @click="cancel" size="small">取消</el-button> <el-button @click="cancel" size="small">取消</el-button>
</div> </div>
</div> </div>
...@@ -330,13 +243,11 @@ export default { ...@@ -330,13 +243,11 @@ export default {
}, },
watch: { watch: {
filterText(val) { filterText(val) {
this._timeout && clearTimeout(this._timeout);
this._timeout && clearTimeout(this._timeout) this._timeout = setTimeout(() => {
this._timeout = setTimeout(()=>{ this.$refs.tree.filter(val);
this.$refs.tree.filter(val) }, 500);
},500) },
}
}, },
methods: { methods: {
selectStore() { selectStore() {
...@@ -381,7 +292,7 @@ export default { ...@@ -381,7 +292,7 @@ export default {
}, },
filterNode(value, data) { filterNode(value, data) {
console.log(value, data); console.log(value, data);
this.loading = false this.loading = false;
if (!value) return true; if (!value) return true;
return data.label.indexOf(value) !== -1; return data.label.indexOf(value) !== -1;
}, },
...@@ -479,9 +390,8 @@ export default { ...@@ -479,9 +390,8 @@ export default {
if (val && val.length > 1) { if (val && val.length > 1) {
this.$nextTick(() => { this.$nextTick(() => {
this.refresh = new Date().getTime(); this.refresh = new Date().getTime();
const thisNodes = this.$refs[ const thisNodes =
"specialShopCascader" this.$refs["specialShopCascader"].getCheckedNodes()[0];
].getCheckedNodes()[0];
if (thisNodes && thisNodes.data) { if (thisNodes && thisNodes.data) {
const { data } = thisNodes; const { data } = thisNodes;
this.form.specialShopId = data.id; this.form.specialShopId = data.id;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!