Commit 045f3542 by jack

围栏范围不让编辑

1 parent 2f4b861b
<template>
<!-- 围栏调用地图弹框 -->
<!-- <el-dialog id="fenceMapModal1" :visible="fenceMapModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="1200px" top="10vh"> -->
<!-- <div class="dialog-header" slot="title">
<!-- 围栏调用地图弹框 -->
<!-- <el-dialog id="fenceMapModal1" :visible="fenceMapModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="1200px" top="10vh"> -->
<!-- <div class="dialog-header" slot="title">
<h2 class="header-title">地图引用</h2>
</div> -->
<div class="fence-map" :visible="fenceMapModalVisible" v-loading="mapLoading">
<!-- <el-form :model="form" ref="fenceMapForm" :rules="rules" :inline="true" size="mini" >
<div class="fence-map" :visible="fenceMapModalVisible" v-loading="mapLoading">
<!-- <el-form :model="form" ref="fenceMapForm" :rules="rules" :inline="true" size="mini" >
<el-form-item label="经度" prop="lng">
<el-input v-model="form.lng" style="width:100px" @change="transfer"></el-input>
</el-form-item>
......@@ -24,91 +23,88 @@
</el-form-item>
<el-form-item><el-button type="primary" @click="updateFence">更新围栏</el-button></el-form-item>
</el-form>-->
<div id="mapContainer" class="map-container"></div>
<fence-map-controll @onRefreshMap="refreshMap" :isModalMap="true"></fence-map-controll>
<div class="map-seacrh-wrap">
<!-- <input type="text" id="fenceMapSearch"> -->
<el-input placeholder="请输入位置" id="fenceMapSearch" size="small" v-model="fenceMapSearch">
<template slot="prepend">搜索</template>
<!-- <el-button slot="append" icon="el-icon-search" @click="search"></el-button> -->
</el-input>
</div>
</div>
<!-- <div slot="footer" class="dialog-footer">
<div id="mapContainer" class="map-container"></div>
<fence-map-controll @onRefreshMap="refreshMap" :isModalMap="true"></fence-map-controll>
<div class="map-seacrh-wrap">
<!-- <input type="text" id="fenceMapSearch"> -->
<el-input placeholder="请输入位置" id="fenceMapSearch" size="small" v-model="fenceMapSearch">
<template slot="prepend">搜索</template>
<!-- <el-button slot="append" icon="el-icon-search" @click="search"></el-button> -->
</el-input>
</div>
</div>
<!-- <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="sure" size="small">确认</el-button>
<el-button @click="$emit('onFenceMapModalChange', false)" size="small">关闭</el-button>
</div> -->
<!-- </el-dialog> -->
<!-- 围栏调用地图弹框 /-->
<!-- </el-dialog> -->
<!-- 围栏调用地图弹框 /-->
</template>
<script>
import remoteLoad from '@/utils/remoteLoad.js'
import mapService from '@/utils/mapService.js'
import FenceMapControll from './fenceMapControll'
import Constants from '@/utils/constants'
export default{
props: ['init'],
data(){
return {
fenceMapSearch: '',
geolocation: null,
circleEditor: null,
areaCodeMap:"",
polygons:[],
polygonEditor:null,
autoCenterMarker:null,
marke:null,
fenceMapModalVisible:false,
polygon:null,
mapDot:true,
circle: null,
tableData:[],
transferTimeoutId: undefined,
geocoder: null,
transferFlag: null,
opts : {
subdistrict: 1, //返回下一级行政区
showbiz:false //最后一级返回街道信息
},
mapObj: null,
fenceType: 'polygon', //'area' 'polygon'
lng: '',
lat: '',
radius: '',
fenceCircle: null,
fenceCenter: null,
areaCode: '',
isFenceInit: false,
mapLoading: false,
polygonPath: [
/* [116.403322, 39.920255],
import remoteLoad from "@/utils/remoteLoad.js";
import mapService from "@/utils/mapService.js";
import FenceMapControll from "./fenceMapControll";
import Constants from "@/utils/constants";
export default {
props: ["init"],
data() {
return {
fenceMapSearch: "",
geolocation: null,
circleEditor: null,
areaCodeMap: "",
polygons: [],
polygonEditor: null,
autoCenterMarker: null,
marke: null,
fenceMapModalVisible: false,
polygon: null,
mapDot: true,
circle: null,
tableData: [],
transferTimeoutId: undefined,
geocoder: null,
transferFlag: null,
opts: {
subdistrict: 1, //返回下一级行政区
showbiz: false, //最后一级返回街道信息
},
mapObj: null,
fenceType: "polygon", //'area' 'polygon'
lng: "",
lat: "",
radius: "",
fenceCircle: null,
fenceCenter: null,
areaCode: "",
isFenceInit: false,
mapLoading: false,
polygonPath: [
/* [116.403322, 39.920255],
[116.410703, 39.897555],
[116.402292, 39.892353],
[116.389846, 39.891365] */
]
}
},
mounted(){
},
watch: {
lng(newVal){
//this.transfer()
},
lat(newVal){
//this.transfer()
},
/* mapData(newVal){
],
};
},
mounted() {},
watch: {
lng(newVal) {
//this.transfer()
},
lat(newVal) {
//this.transfer()
},
/* mapData(newVal){
const fenceData = newVal;
this.initMapPromise.then(()=>{console.log(fenceData)
if(fenceData.fenceType === 'circle'){
......@@ -116,509 +112,486 @@ export default{
}
})
} */
},
async created () {
if(window.AMap){
this.initMap()
}else{
await remoteLoad(`${Constants.AMAP_URL}`, true);
this.initMap()
}
},
methods: {
initMap(){
this.initMapPromise = new Promise((resolve, reject)=>{
let check = ()=>{
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);
return setTimeout(()=>{
if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){
window.AMap = AMap;
this.mapObj = mapService.init('mapContainer');
this.bindContextMenu();
this.bindSearch();
resolve()
}else{
this.checkMapLoaded = check()
}
}, 100)
}
this.checkMapLoaded = check();
})
},
bindSearch(){
const self = this;
this.auto = new AMap.Autocomplete({
input: 'fenceMapSearch'
});
this.autoCenterMarker = new AMap.Marker({
icon: require('@/assets/images/auto-center-marker.gif'),
map: this.mapObj,
offset: new AMap.Pixel(-12,-12),
visible: false
});
this.autoCenterMarker.on('rightclick', (e)=> {
if(self.mapObj.getAllOverlays('circle').length){
window.mapMenu.contextMenu.open(self.mapObj, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
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++) {
},
async created() {
if (window.AMap) {
this.initMap();
} else {
await remoteLoad(`${Constants.AMAP_URL}`, true);
this.initMap();
}
},
methods: {
initMap() {
this.initMapPromise = new Promise((resolve, reject) => {
let check = () => {
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);
return setTimeout(() => {
if (
"AMap" in window &&
typeof AMap.Map == "function" &&
!this.mapObj
) {
window.AMap = AMap;
this.mapObj = mapService.init("mapContainer");
this.bindContextMenu();
this.bindSearch();
resolve();
} else {
this.checkMapLoaded = check();
}
}, 100);
};
this.checkMapLoaded = check();
});
},
bindSearch() {
const self = this;
this.auto = new AMap.Autocomplete({
input: "fenceMapSearch",
});
this.autoCenterMarker = new AMap.Marker({
icon: require("@/assets/images/auto-center-marker.gif"),
map: this.mapObj,
offset: new AMap.Pixel(-12, -12),
visible: false,
});
this.autoCenterMarker.on("rightclick", (e) => {
if (self.mapObj.getAllOverlays("circle").length) {
window.mapMenu.contextMenu.open(self.mapObj, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
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.autoCenterMarker.show();
this.mapObj.add(this.autoCenterMarker);
//this.form.lng = e.poi.location.lng;
//this.form.lat = e.poi.location.lat;
//this.contextMenuPositon = e.poi.location
//window.mapMenu.contextMenu.open(this.mapObj, mapService.getLngLat(e.poi.location.lng, e.poi.location.lat))
}
this.mapObj.setZoom(14);
});
},
bindContextMenu(){
const self = this;
window.mapMenu = new ContextMenu(this.mapObj);//暴露mapMenu onclick要用
function ContextMenu(map) {
var me = this;
this.contextMenuPositon = null;
const click = window.proxy ? `window.proxy.mapMenu`: `mapMenu`
this.contextMenu = new AMap.ContextMenu({
isCustom: true,
content: `<div class="context_menu" >
this.autoCenterMarker.show();
this.mapObj.add(this.autoCenterMarker);
//this.form.lng = e.poi.location.lng;
//this.form.lat = e.poi.location.lat;
//this.contextMenuPositon = e.poi.location
//window.mapMenu.contextMenu.open(this.mapObj, mapService.getLngLat(e.poi.location.lng, e.poi.location.lat))
}
this.mapObj.setZoom(14);
});
},
bindContextMenu() {
const self = this;
window.mapMenu = new ContextMenu(this.mapObj); //暴露mapMenu onclick要用
function ContextMenu(map) {
var me = this;
this.contextMenuPositon = null;
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>
</div>`
});
map.on('rightclick', (e)=> {
if(self.mapObj.getAllOverlays('circle').length){
this.contextMenu.open(map, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
}
ContextMenu.prototype.moveCenter = function addPOI() {
self.moveCenter()
this.contextMenu.close();
};
},
drawFence(){
if(!this.lng && !this.lat){
this.mapLoading = true;
this.getCurrentPosition().then((pos)=>{
this.lng = pos.lng;
this.lat = pos.lat;
this.radius = 150;
this.drawFenceCircle(pos)
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
radius: this.radius
});
this.mapLoading = false;
})
}else{
this.drawFenceCircle(mapService.getLngLat(this.lng, this.lat))
}
},
drawFenceCircle(fenceCenter){
const mapObj = this.mapObj;
if(this.fenceCircle){
this.fenceCircle.setCenter(mapService.getLngLat(this.lng, this.lat))
}else{
this.fenceCircle = new AMap.Circle({
map: mapObj,
center: fenceCenter,
radius: this.radius*1,
strokeColor: "#F33",
strokeOpacity: 1,
strokeWeight: 3,
fillColor: "ee2200",
fillOpacity: 0.35
});
mapObj.plugin(["AMap.CircleEditor"],()=>{
this.circleEditor = new AMap.CircleEditor(mapObj, this.fenceCircle);
AMap.event.addListener(this.circleEditor, 'adjust', (e)=>{
this.radius = e.radius/1;
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
radius: this.radius
});
});
AMap.event.addListener(this.circleEditor, 'move', (e)=>{
this.lng = e.lnglat.lng;
this.lat = e.lnglat.lat;
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
});
});
this.circleEditor.open();
});
}
mapService.setFitView()
mapObj.setZoom(14);
},
initFence(data){
this._mapPromiseTimeout && clearTimeout(this._mapPromiseTimeout)
if(this.initMapPromise){
if(data){
this.fenceType = data.fenceType
if(this.fenceType === 'circle'){
this.lng = data.lng;
this.lat = data.lat;
this.radius = data.radius;
}else if(this.fenceType === 'area'){
this.areaCode = data.areaCode
}else if(this.fenceType === 'polygon'){
if(data.polygonPath && data.polygonPath.length){
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]
})
</div>`,
});
map.on("rightclick", (e) => {
if (self.mapObj.getAllOverlays("circle").length) {
this.contextMenu.open(map, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
}
ContextMenu.prototype.moveCenter = function addPOI() {
self.moveCenter();
this.contextMenu.close();
};
},
drawFence() {
if (!this.lng && !this.lat) {
this.mapLoading = true;
this.getCurrentPosition().then((pos) => {
this.lng = pos.lng;
this.lat = pos.lat;
this.radius = 150;
this.drawFenceCircle(pos);
this.$emit("onUpdateMapData", {
lng: this.lng,
lat: this.lat,
radius: this.radius,
});
this.mapLoading = false;
});
} else {
this.drawFenceCircle(mapService.getLngLat(this.lng, this.lat));
}
},
drawFenceCircle(fenceCenter) {
const mapObj = this.mapObj;
if (this.fenceCircle) {
this.fenceCircle.setCenter(mapService.getLngLat(this.lng, this.lat));
} else {
this.fenceCircle = new AMap.Circle({
map: mapObj,
center: fenceCenter,
radius: this.radius * 1,
strokeColor: "#F33",
strokeOpacity: 1,
strokeWeight: 3,
fillColor: "ee2200",
fillOpacity: 0.35,
});
mapObj.plugin(["AMap.CircleEditor"], () => {
this.circleEditor = new AMap.CircleEditor(mapObj, this.fenceCircle);
AMap.event.addListener(this.circleEditor, "adjust", (e) => {
this.radius = e.radius / 1;
this.$emit("onUpdateMapData", {
lng: this.lng,
lat: this.lat,
radius: this.radius,
});
});
AMap.event.addListener(this.circleEditor, "move", (e) => {
this.lng = e.lnglat.lng;
this.lat = e.lnglat.lat;
this.$emit("onUpdateMapData", {
lng: this.lng,
lat: this.lat,
});
});
//this.circleEditor.open();
this.circleEditor.close();
});
}
mapService.setFitView();
mapObj.setZoom(14);
},
initFence(data) {
this._mapPromiseTimeout && clearTimeout(this._mapPromiseTimeout);
if (this.initMapPromise) {
if (data) {
this.fenceType = data.fenceType;
if (this.fenceType === "circle") {
this.lng = data.lng;
this.lat = data.lat;
this.radius = data.radius;
} else if (this.fenceType === "area") {
this.areaCode = data.areaCode;
} else if (this.fenceType === "polygon") {
if (data.polygonPath && data.polygonPath.length) {
this.polygonPath = data.polygonPath;
}
}
}
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()
})
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();
polyEditor.on('adjust', function(event) {
console.log('触发事件:adjust')
self.emitPolyEvent()
})
this.fenceType = data.fenceType;
polyEditor.on('removenode', function(event) {
console.log('触发事件:removenode')
self.emitPolyEvent()
})
this.polyEditor && this.polyEditor.close();
this.mouseTool && this.mouseTool.close();
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{
this.form.transferAddr = '';
}
}
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.$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,
});
},
refreshMap() {
} else {
this.form.transferAddr = "";
}
}
});
},
components:{
FenceMapControll
}
}
refreshMap() {},
},
components: {
FenceMapControll,
},
};
</script>
<style scoped>
.fence-map{
position: relative;
}
.fence-map .map-container{
width: 100%;
height: 500px;
}
.fence-map .map-seacrh-wrap{
position: absolute;
top: 40px;
left: 10px;
z-index: 1000;
}
.el-form-item{
margin: -20px 0 20px 10px;
}
.fence-map {
position: relative;
}
.fence-map .map-container {
width: 100%;
height: 500px;
}
.fence-map .map-seacrh-wrap {
position: absolute;
top: 40px;
left: 10px;
z-index: 1000;
}
.el-form-item {
margin: -20px 0 20px 10px;
}
</style>
<style lang="scss">
.context_menu{
min-width: 10em;
background-color: #fff;
padding: 10px;
border: 1px solid #efefef;
border-radius: 2px;
cursor: pointer;
&>p{
margin: 0;
i{
font-size: 18px;
color: #094;
margin-right: 5px;
}
i,span{
vertical-align: middle;
}
}
}
.context_menu {
min-width: 10em;
background-color: #fff;
padding: 10px;
border: 1px solid #efefef;
border-radius: 2px;
cursor: pointer;
& > p {
margin: 0;
i {
font-size: 18px;
color: #094;
margin-right: 5px;
}
i,
span {
vertical-align: middle;
}
}
}
</style>
\ No newline at end of file
......@@ -2,18 +2,8 @@
<div>
<h2>基础信息</h2>
<el-divider></el-divider>
<el-form
ref="shopForm"
:model="form"
:rules="rules"
label-width="135px"
:inline="true"
>
<el-form-item
class="special-shop-input"
label="特约店名称:"
prop="specialShopName"
>
<el-form ref="shopForm" :model="form" :rules="rules" label-width="135px" :inline="true">
<el-form-item class="special-shop-input" label="特约店名称:" prop="specialShopName">
<!-- <el-cascader
:key="refresh"
ref="specialShopCascader"
......@@ -28,53 +18,24 @@
clearable
:disabled="readonlyStatus"
></el-cascader> -->
<el-popover
v-model="filterVisible"
placement="bottom-start"
width="400"
@show="selectStore"
trigger="click"
>
<el-popover v-model="filterVisible" placement="bottom-start" width="400" @show="selectStore" trigger="click">
<div v-loading="loading">
<el-input
placeholder="输入关键字进行过滤"
v-model="filterText"
size="small"
>
<el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small">
</el-input>
<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
>
<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>
</el-tree>
<p style="text-align: right; margin-top: 10px">
<el-button @click="filterConfirm" type="primary">确定</el-button>
<el-button @click="closeFilter">取消</el-button>
</p>
</div>
<el-input
v-model="form.specialShopName"
:placeholder="form.specialShopName || '请选择特约店名称'"
slot="reference"
>
<el-input v-model="form.specialShopName" :placeholder="form.specialShopName || '请选择特约店名称'" slot="reference">
</el-input>
</el-popover>
</el-form-item>
<el-form-item label="特约店编码:">
<el-input
v-model="form.specialShopCode"
:size="btn_size"
readonly
disabled
Placeholder="特约店编码"
></el-input>
<el-input v-model="form.specialShopCode" :size="btn_size" readonly disabled Placeholder="特约店编码"></el-input>
</el-form-item>
<el-form-item label="特约店级别:">
<el-radio-group v-model="form.shopLevel">
......@@ -85,82 +46,34 @@
<h2>特约店围栏配置</h2>
<el-divider></el-divider>
<el-form-item label="特约店线路名称:" prop="fenceName">
<el-input
v-model.trim="form.fenceName"
:size="btn_size"
maxlength="200"
placeholder="请输入特约店线路名称"
:disabled="readonlyStatus"
></el-input>
<el-input v-model.trim="form.fenceName" :size="btn_size" maxlength="200" placeholder="请输入特约店线路名称" :disabled="readonlyStatus"></el-input>
</el-form-item>
<el-form-item label="监控范围:" prop="radius">
<el-input
v-model="form.radius"
:size="btn_size"
Placeholder="请输入半径"
style="width:140px"
maxlength="10"
:disabled="readonlyStatus"
>
<el-input v-model="form.radius" :size="btn_size" Placeholder="请输入半径" style="width:140px" maxlength="10" :disabled="true">
<template slot="append">M</template>
</el-input>
</el-form-item>
<el-form-item>
<el-button
type="primary"
:size="btn_size"
@click="updateFence"
:disabled="readonlyStatus"
>更新线路</el-button
>
<el-button type="primary" :size="btn_size" @click="updateFence" :disabled="readonlyStatus">更新线路</el-button>
</el-form-item>
<div>
<el-form-item label="经度:" prop="lng">
<el-input
v-model="form.lng"
size="small"
:disabled="readonlyStatus"
></el-input>
<el-input v-model="form.lng" size="small" :disabled="readonlyStatus"></el-input>
</el-form-item>
<el-form-item label="纬度:" prop="lat">
<el-input
v-model="form.lat"
size="small"
:disabled="readonlyStatus"
></el-input>
<el-input v-model="form.lat" size="small" :disabled="readonlyStatus"></el-input>
</el-form-item>
<el-form-item label="特约店详细地址:" prop="analysisAddress">
<el-input
v-model="form.analysisAddress"
size="medium"
placeholder="自动生成"
readonly
disabled
style="width:350px"
></el-input>
<el-input v-model="form.analysisAddress" size="medium" placeholder="自动生成" readonly disabled style="width:350px"></el-input>
</el-form-item>
</div>
</el-form>
<div
class="ibox-content"
style="height: 500px; padding:0 20px;z-index: 100"
>
<fence-map
:mapData="mapData"
@onUpdateMapData="updateMapData"
ref="fenceMap"
>
<div class="ibox-content" style="height: 500px; padding:0 20px;z-index: 100">
<fence-map :mapData="mapData" @onUpdateMapData="updateMapData" ref="fenceMap">
</fence-map>
</div>
<div class="fenceModalfooter">
<el-button
v-if="!readonlyStatus"
type="primary"
@click="saveFence"
size="small"
:loading="submitting"
>{{ btnText }}</el-button
>
<el-button v-if="!readonlyStatus" type="primary" @click="saveFence" size="small" :loading="submitting">{{ btnText }}</el-button>
<el-button @click="cancel" size="small">取消</el-button>
</div>
</div>
......@@ -330,13 +243,11 @@ export default {
},
watch: {
filterText(val) {
this._timeout && clearTimeout(this._timeout)
this._timeout = setTimeout(()=>{
this.$refs.tree.filter(val)
},500)
}
this._timeout && clearTimeout(this._timeout);
this._timeout = setTimeout(() => {
this.$refs.tree.filter(val);
}, 500);
},
},
methods: {
selectStore() {
......@@ -381,7 +292,7 @@ export default {
},
filterNode(value, data) {
console.log(value, data);
this.loading = false
this.loading = false;
if (!value) return true;
return data.label.indexOf(value) !== -1;
},
......@@ -479,9 +390,8 @@ export default {
if (val && val.length > 1) {
this.$nextTick(() => {
this.refresh = new Date().getTime();
const thisNodes = this.$refs[
"specialShopCascader"
].getCheckedNodes()[0];
const thisNodes =
this.$refs["specialShopCascader"].getCheckedNodes()[0];
if (thisNodes && thisNodes.data) {
const { data } = thisNodes;
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!