This commit is contained in:
李想 2025-04-21 16:08:52 +08:00
commit 3338c77760

View File

@ -23,10 +23,11 @@ const mapMixinLand = {
}, },
{ {
id: '03', id: '03',
landPath: landPath:
["99.853174,24.424073|99.850256,24.426105|99.855749,24.426731|99.880812,24.421885", [
"99.853174,24.424073|99.850256,24.426105|99.855749,24.426731|99.880812,24.421885",
], "99.8587581,24.4150345|99.8603841,24.4127477|99.8581922,24.4129616"
],
fillColor: '#ba8ae3', fillOpacity: 0.8, strokeColor: "#ba8ae3", strokeWeight: 1, strokeOpacity: 0.8, fillColor: '#ba8ae3', fillOpacity: 0.8, strokeColor: "#ba8ae3", strokeWeight: 1, strokeOpacity: 0.8,
}, },
{ {
@ -46,7 +47,7 @@ const mapMixinLand = {
} }
], ],
overlayGroup:[], overlayGroup: [],
}; };
}, },
watch: { watch: {
@ -94,7 +95,7 @@ const mapMixinLand = {
// await this.createDevicePoint(); // await this.createDevicePoint();
}, },
/** 绘制地块 */ /** 绘制地块 */
createAreaPolygon(type, ids,options) { createAreaPolygon(type, ids, options) {
const label = []; const label = [];
let overlayGroupNew = []; let overlayGroupNew = [];
// console.info('this.area', this.area) // console.info('this.area', this.area)
@ -105,78 +106,87 @@ const mapMixinLand = {
areaList = this.staticArea.filter((m) => { areaList = this.staticArea.filter((m) => {
return ids.includes(m.id) return ids.includes(m.id)
}) || [] }) || []
} else {areaList = [] } } else { areaList = [] }
} else { areaList = this.staticArea } } else { areaList = this.staticArea }
if(areaList.length>0){
areaList.forEach((item) => {
if (item.landPath) {
const path = [];
const pointList = [];
if( item.landPath && item.landPath.length && item.landPath.length>0){
item.landPath.forEach((k)=>{
k.split('|').forEach((point) => {
path.push(new this.AMap.LngLat(point.split(',')[0], point.split(',')[1]));
pointList.push([Number(point.split(',')[0]), Number(point.split(',')[1])]);
});
})
}
let colorVal='';
if(options && options.length>0){
let indexF=options.findIndex((m)=>{
return m.id==item.id
})
colorVal=indexF>-1 ? options[indexF].color : ''
}
const polygon = new this.AMap.Polygon({
path: path,
fillColor:colorVal|| item.fillColor,
fillOpacity: item.fillOpacity,
strokeColor:colorVal || '',
strokeWeight: colorVal|| item.fillColor,
strokeOpacity: item.strokeOpacity,
extData: {
...item,
},
});
polygon.on('click', (e) => {
this.createInfoWindow(e);
});
this.overlayGroup.push(polygon); if (areaList.length > 0) {
if(type==false){ areaList.forEach((item) => {
overlayGroupNew.push(polygon) if (item.landPath) {
if (item.landPath && item.landPath.length && item.landPath.length > 0) {
item.landPath.forEach((k) => {
const path = [];
const pointList = [];
k.split('|').forEach((point) => {
path.push(new this.AMap.LngLat(point.split(',')[0], point.split(',')[1]));
pointList.push([Number(point.split(',')[0]), Number(point.split(',')[1])]);
});
const polygon = new this.AMap.Polygon({
path: path,
fillColor: colorVal || item.fillColor,
fillOpacity: item.fillOpacity,
strokeColor: colorVal || '',
strokeWeight: colorVal || item.fillColor,
strokeOpacity: item.strokeOpacity,
extData: {
...item,
},
});
polygon.on('click', (e) => {
this.createInfoWindow(e);
});
this.overlayGroup.push(polygon);
if (type == false) {
overlayGroupNew.push(polygon)
}
})
}
let colorVal = '';
if (options && options.length > 0) {
let indexF = options.findIndex((m) => {
return m.id == item.id
})
colorVal = indexF > -1 ? options[indexF].color : ''
}
// const polygon = new this.AMap.Polygon({
// path: path,
// fillColor:colorVal|| item.fillColor,
// fillOpacity: item.fillOpacity,
// strokeColor:colorVal || '',
// strokeWeight: colorVal|| item.fillColor,
// strokeOpacity: item.strokeOpacity,
// extData: {
// ...item,
// },
// });
// polygon.on('click', (e) => {
// this.createInfoWindow(e);
// });
// this.overlayGroup.push(polygon);
// if(type==false){
// overlayGroupNew.push(polygon)
// }
} }
// 添加地块名称 });
label.push( }
new this.AMap.Text({
text: item.landName ? item.landName : '名称',
anchor: 'center',
position: this.getAreaCenter(pointList),
style: {
background: 'transparent',
color: '#fff',
border: 'none',
fontSize: '16px',
},
})
);
}
});
}
// this.map.add(new this.AMap.OverlayGroup(label));
if (type) { if (type) {
if(this.overlayGroup.length>0){ if (this.overlayGroup.length > 0) {
this.map.add(new this.AMap.OverlayGroup(this.overlayGroup)); this.map.add(new this.AMap.OverlayGroup(this.overlayGroup));
this.map.setFitView(this.overlayGroup); this.map.setFitView(this.overlayGroup);
this.map.setZoom(13) this.map.setZoom(13)
// this.map.moveCamera(CameraUpdateFactory.zoomTo(15)) // this.map.moveCamera(CameraUpdateFactory.zoomTo(15))
this.loading = false; this.loading = false;
} }
}else{ } else {
this.map.remove(this.overlayGroup) this.map.remove(this.overlayGroup)
this.map.add(new this.AMap.OverlayGroup(overlayGroupNew)); this.map.add(new this.AMap.OverlayGroup(overlayGroupNew));
} }
@ -213,9 +223,9 @@ const mapMixinLand = {
this.map.add(new this.AMap.OverlayGroup(devicePointList)); this.map.add(new this.AMap.OverlayGroup(devicePointList));
this.loading = false; this.loading = false;
}, },
upLayersIds(ids,options) { upLayersIds(ids, options) {
console.info('upLayersIds**********', ids) console.info('upLayersIds**********', ids)
this.createAreaPolygon(false, ids,options) this.createAreaPolygon(false, ids, options)
}, },
/** 获取地块中心点 */ /** 获取地块中心点 */
getAreaCenter(location) { getAreaCenter(location) {