Commit 3cb8a57b by 晁文轩

合并分支 'develop_cd' 到 'master'

Develop cd

查看合并请求 !35
parents b6f6f8cd 3ea3b0a2
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
<script> <script>
import { lazyAMapApiLoaderInstance } from 'vue-amap' import { lazyAMapApiLoaderInstance } from 'vue-amap'
import { uuid } from 'vue-uuid' import { uuid } from 'vue-uuid'
import { baseAMapData, hazardLevel } from './aMap/aMap' import { baseAMapData, hazardLevel, calculateCenter } from './aMap/aMap'
import { log } from '@antv/g2plot/lib/utils'
export default { export default {
props: { props: {
...@@ -22,6 +23,8 @@ export default { ...@@ -22,6 +23,8 @@ export default {
map: {}, map: {},
AMap: {}, AMap: {},
layers: [], layers: [],
text: [],
allParkList: [], allParkList: [],
center: [116.400586, 39.903475], center: [116.400586, 39.903475],
mapStyle: 'amap://styles/6ee1c8252c951da095d5e4eaf9c65a1f', mapStyle: 'amap://styles/6ee1c8252c951da095d5e4eaf9c65a1f',
...@@ -33,6 +36,7 @@ export default { ...@@ -33,6 +36,7 @@ export default {
chart: { chart: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
// this.drawLayer() // this.drawLayer()
console.log(9999)
this.initMap() this.initMap()
}, },
deep: true deep: true
...@@ -67,8 +71,14 @@ export default { ...@@ -67,8 +71,14 @@ export default {
this.allParkList = JSON.parse(JSON.stringify(data)) this.allParkList = JSON.parse(JSON.stringify(data))
this.layers = [] this.layers = []
data.map((item) => { data.map((item) => {
const color = hazardLevel[item.hazardLevel]?.color const color = item.hazardLevel.includes('#')
? item.hazardLevel
: hazardLevel[item.hazardLevel]?.color
let layer = null let layer = null
let text = null
let center = []
const path = item.path ? JSON.parse(item.path) : []
if (item.areaType === '1') { if (item.areaType === '1') {
layer = new AMap.Marker({ layer = new AMap.Marker({
position: new AMap.LngLat(item.longitude, item.latitude), position: new AMap.LngLat(item.longitude, item.latitude),
...@@ -79,9 +89,10 @@ export default { ...@@ -79,9 +89,10 @@ export default {
...item ...item
} }
}) })
center = [item.longitude, item.latitude]
} else if (item.areaType === '2') { } else if (item.areaType === '2') {
layer = new AMap.Polygon({ layer = new AMap.Polygon({
path: JSON.parse(item.path), path: path,
fillColor: color, fillColor: color,
strokeColor: 'transparent', strokeColor: 'transparent',
fillOpacity: 0.6, fillOpacity: 0.6,
...@@ -90,9 +101,10 @@ export default { ...@@ -90,9 +101,10 @@ export default {
...item ...item
} }
}) })
center = calculateCenter(path)
} else if (item.areaType === '3') { } else if (item.areaType === '3') {
layer = new AMap.Polyline({ layer = new AMap.Polyline({
path: JSON.parse(item.path), path: path,
borderWeight: 3, borderWeight: 3,
strokeColor: color, strokeColor: color,
strokeOpacity: 1, strokeOpacity: 1,
...@@ -102,26 +114,48 @@ export default { ...@@ -102,26 +114,48 @@ export default {
...item ...item
} }
}) })
center = calculateCenter(path)
}
if (center && center.length === 2) {
text = new AMap.Text({
position: center,
anchor: 'bottom-center',
text: item.name,
offset: [0, 26],
style: { 'background-color': '#fff', 'font-size': '12px' },
extData: {
...item
}
})
} }
if (layer) { if (layer) {
this.layers.push(layer) this.layers.push(layer)
this.text.push(text)
const extData = layer.getExtData() const extData = layer.getExtData()
const extTextData = text.getExtData()
layer.on('click', (obj) => { layer.on('click', (obj) => {
this.parkClick(extData) this.parkClick(extData)
}) })
text.on('click', (obj) => {
this.parkClick(extTextData)
})
} }
}) })
this.map.add(this.layers) this.map.add([...this.layers, ...this.text])
this.map.setFitView() this.map.setFitView()
}, },
parkClick(item) { parkClick(item) {
console.log(item)
const id = item.id const id = item.id
const highLightColor = '#AF24FF' const highLightColor = '#AF24FF'
const allPolyline = this.layers const allPolyline = this.layers
this.allParkList.forEach((it, index) => { this.allParkList.forEach((it, index) => {
if (allPolyline[index]) { if (allPolyline[index]) {
const color = hazardLevel[it.hazardLevel]?.color const color = item.hazardLevel.includes('#')
? item.hazardLevel
: hazardLevel[item.hazardLevel]?.color
if (it.areaType === '1') { if (it.areaType === '1') {
allPolyline[index].setContent(this.renderMarker(color)) allPolyline[index].setContent(this.renderMarker(color))
if (it.id === id) { if (it.id === id) {
...@@ -133,6 +167,7 @@ export default { ...@@ -133,6 +167,7 @@ export default {
allPolyline[index].setOptions({ allPolyline[index].setOptions({
[it.areaType === '3' ? 'strokeColor' : 'fillColor']: color [it.areaType === '3' ? 'strokeColor' : 'fillColor']: color
}) })
if (it.id === id) { if (it.id === id) {
if (item.path && typeof item.path === 'string') { if (item.path && typeof item.path === 'string') {
const path = JSON.parse(item.path) const path = JSON.parse(item.path)
......
...@@ -39,3 +39,18 @@ export const hazardLevel = { ...@@ -39,3 +39,18 @@ export const hazardLevel = {
color: "#1890FF", color: "#1890FF",
}, },
}; };
// 多边形中心点
export const calculateCenter = (lnglatarr) => {
var x = lnglatarr.map(function (a) {
return a[0];
});
var y = lnglatarr.map(function (a) {
return a[1];
});
var minX = Math.min.apply(null, x);
var maxX = Math.max.apply(null, x);
var minY = Math.min.apply(null, y);
var maxY = Math.max.apply(null, y);
const arr = [(minX + maxX) / 2, (minY + maxY) / 2];
return arr;
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论