| | |
| | | import calculate from '@/utils/map/calculate'; |
| | | import gridMapUtil from '@/utils/map/grid'; |
| | | import { map, onMapMounted } from '@/utils/map/index_old'; |
| | | import { useCloned } from '@vueuse/core'; |
| | | import { getGridDataDetailFactorValue } from '@/model/GridDataDetail'; |
| | | import { useGridStore } from '@/stores/grid-info'; |
| | | |
| | | const gridStore = useGridStore(); |
| | | |
| | | /** |
| | | * 卫星遥测网格管理 |
| | |
| | | this.name = name; |
| | | } |
| | | |
| | | // 地图网格相关对象 |
| | | gridGroupId; |
| | | |
| | | // 默认地图网格相关对象 |
| | | mapViews; |
| | | |
| | | mapViewsList = []; |
| | | gridDataDetail; |
| | | |
| | | infoMap = new Map(); |
| | | |
| | | // 地图网格对象Map结构,存储对应key下的网格对象、网格坐标信息 |
| | | mapViewsMap = new Map(); |
| | | |
| | | // 网格数据Map结构,存储对应key下的网格监测数据信息 |
| | | gridDataDetailMap = new Map(); |
| | | |
| | | districtPolygon; |
| | | |
| | | firstEvent; |
| | | |
| | | events = new Map(); |
| | | |
| | | selectedFactorType; |
| | | |
| | | setShowFactorType(e) { |
| | | this.selectedFactorType = e; |
| | | this.changeGridColor({ factorName: e.name }); |
| | | this.changeText({ factorName: e.name }); |
| | | } |
| | | |
| | | // 绘制区县边界 |
| | | drawDistrict(districtName, isNew) { |
| | |
| | | } |
| | | } |
| | | |
| | | firstEvent; |
| | | |
| | | // 绘制网格线 |
| | | drawPolyline(gridInfo, event) { |
| | | this.firstEvent = event; |
| | |
| | | const data = gridDataDetail.map((v, i) => { |
| | | return { |
| | | lnglat_GD: points[i], |
| | | // data: v.pm25 ? (v.pm25 + 'μg/m³') : '' |
| | | data: v.pm25 ? v.pm25 : '' |
| | | data: getGridDataDetailFactorValue(v, this.selectedFactorType.name) |
| | | }; |
| | | }); |
| | | // return gridMapUtil.drawGridTextLabel(data, textViews, labelsLayer, 'bottom'); |
| | |
| | | anchor: 'top-center', |
| | | type: 'data', |
| | | isCustomColor, |
| | | useColor |
| | | useColor, |
| | | factorName: this.selectedFactorType.name |
| | | }); |
| | | } |
| | | |
| | | changeText({ tags = [], factorName, isCustomColor, useColor, type }) { |
| | | let { _mapViewsList, _gridDataDetailList } = this._getMapViews(...tags); |
| | | if (_mapViewsList.length == _gridDataDetailList.length) { |
| | | _mapViewsList.forEach((v, i) => { |
| | | if (v.dataTxt) { |
| | | let dataList = []; |
| | | if (type == 'data' || type == undefined) { |
| | | dataList.push({ |
| | | type: 'data', |
| | | data: _gridDataDetailList[i].map((v) => { |
| | | return { |
| | | data: getGridDataDetailFactorValue( |
| | | v, |
| | | factorName ? factorName : this.selectedFactorType.name |
| | | ) |
| | | }; |
| | | }) |
| | | }); |
| | | } |
| | | if (type == 'rank' || type == undefined) { |
| | | dataList.push({ |
| | | type: 'rank', |
| | | data: _gridDataDetailList[i].map((v) => { |
| | | return { |
| | | data: v.rank ? v.rank : '' |
| | | }; |
| | | }) |
| | | }); |
| | | } |
| | | |
| | | dataList.forEach((d) => { |
| | | gridMapUtil.changeGridText({ |
| | | points: d.data, |
| | | textViews: d.type == 'data' ? v.dataTxt : v.rankTxt, |
| | | type: d.type, |
| | | isCustomColor, |
| | | useColor, |
| | | factorName: factorName ? factorName : this.selectedFactorType.name |
| | | }); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 绘制监测数据排名文本 |
| | |
| | | const data = gridDataDetail.map((v, i) => { |
| | | return { |
| | | lnglat_GD: points[i], |
| | | // data: v.pm25 ? ('排名: ' + v.rank) : '' |
| | | data: v.pm25 ? v.rank : '' |
| | | data: v.rank ? v.rank : '' |
| | | }; |
| | | }); |
| | | // return gridMapUtil.drawGridTextLabel(data, textViews, labelsLayer, 'top'); |
| | |
| | | points: data, |
| | | textViews, |
| | | anchor: 'bottom-center', |
| | | type: 'rank' |
| | | type: 'rank', |
| | | factorName: this.selectedFactorType.name |
| | | }); |
| | | } |
| | | |
| | |
| | | points, |
| | | gridDataDetail, |
| | | lastGridViews, |
| | | opacity, |
| | | zIndex, |
| | | customColor |
| | | customColor, |
| | | style |
| | | }) { |
| | | // 根据数据筛选有数据的网格 |
| | | const res = []; |
| | | // 以及对应的中心点坐标 |
| | | const pointsRes = []; |
| | | // 网格按照其编号升序排列,然后计算编号和下表的偏差值 |
| | | const offset = gridViews[0].getExtData().gridCell.cellIndex - 0; |
| | | |
| | | gridDataDetail.forEach((d) => { |
| | | // 根据数据关联的网格编号,找到对应网格 |
| | | const cellId = d.cellId; |
| | |
| | | '遥测数据的网格索引编号超出网格组范围,数据和网格组可能不对应' |
| | | ); |
| | | } |
| | | res.push(gridViews[cellId - 1]); |
| | | pointsRes.push(points[cellId - 1]); |
| | | res.push(gridViews[cellId - offset]); |
| | | pointsRes.push(points[cellId - offset]); |
| | | }); |
| | | |
| | | // 根据绘制颜色方式绘制网格 |
| | |
| | | resGridViews = gridMapUtil.drawGridColorCustom( |
| | | res, |
| | | gridDataDetail, |
| | | opacity, |
| | | zIndex |
| | | this.selectedFactorType.name |
| | | ); |
| | | } else { |
| | | resGridViews = gridMapUtil.drawGridColor( |
| | | res, |
| | | gridDataDetail, |
| | | 'PM25', |
| | | opacity, |
| | | zIndex |
| | | this.selectedFactorType.name, |
| | | style |
| | | ); |
| | | } |
| | | |
| | |
| | | |
| | | // 绘制网格遥感数据值和网格颜色 |
| | | drawGrid({ |
| | | gridDataDetail, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt, |
| | | useDataTxtColor, |
| | | mapViews |
| | | mapViews, |
| | | data, |
| | | grid = { useCustomColor: false, style: { opacity: 1, zIndex: 11 } }, |
| | | dataTxt = { isShow: false, useCustomColor: false, useColor: false }, |
| | | rankTxt = { isShow: false } |
| | | }) { |
| | | const _mapViews = mapViews ? mapViews : this.mapViews; |
| | | // SatelliteProxy.clearText(mapViews); |
| | | this.gridDataDetail = data; |
| | | const { resGridViews, pointsRes } = this.drawColor({ |
| | | gridViews: _mapViews.gridViews, |
| | | points: _mapViews.points, |
| | | gridDataDetail: gridDataDetail, |
| | | gridDataDetail: data, |
| | | lastGridViews: _mapViews.lastGridViews, |
| | | customColor: useCustomColor, |
| | | opacity: opacity, |
| | | zIndex: zIndex |
| | | customColor: grid.useCustomColor, |
| | | style: grid.style |
| | | }); |
| | | _mapViews.lastGridViews = resGridViews; |
| | | _mapViews.lastPoints = pointsRes; |
| | | |
| | | // 数据标记 |
| | | const { textViews: dataTxt, labelsLayer: dataLayer } = this.drawDataText( |
| | | const { textViews: dtv } = this.drawDataText( |
| | | _mapViews.lastPoints, |
| | | gridDataDetail, |
| | | data, |
| | | _mapViews.dataTxt, |
| | | useCustomColor, |
| | | useDataTxtColor |
| | | dataTxt.useCustomColor, |
| | | dataTxt.useColor |
| | | ); |
| | | _mapViews.dataTxt = dataTxt; |
| | | _mapViews.dataLayer = dataLayer; |
| | | _mapViews.dataTxt = dtv; |
| | | |
| | | const { textViews: rankTxt, labelsLayer: rankLayer } = this.drawRankText( |
| | | const { textViews: rtv } = this.drawRankText( |
| | | _mapViews.lastPoints, |
| | | gridDataDetail, |
| | | data, |
| | | _mapViews.rankTxt, |
| | | _mapViews.rankLayer |
| | | ); |
| | | _mapViews.rankTxt = rankTxt; |
| | | _mapViews.rankLayer = rankLayer; |
| | | _mapViews.rankTxt = rtv; |
| | | |
| | | if (showDataTxt) { |
| | | if (dataTxt.isShow) { |
| | | map.add(_mapViews.dataTxt); |
| | | } |
| | | |
| | | if (showRankTxt) { |
| | | if (rankTxt.isShow) { |
| | | map.add(_mapViews.rankTxt); |
| | | } |
| | | } |
| | | |
| | | // |
| | | drawGrids({ |
| | | gridDataDetailList, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt |
| | | }) { |
| | | if (this.mapViewsList.length < gridDataDetailList.length) { |
| | | let index = this.mapViewsList.length; |
| | | while (index < gridDataDetailList.length) { |
| | | const newMapViews = { |
| | | gridViews: gridMapUtil.drawPolylines({ |
| | | points: this.mapViews.gridPoints, |
| | | event: this.firstEvent |
| | | }), |
| | | gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)), |
| | | points: JSON.parse(JSON.stringify(this.mapViews.points)) |
| | | }; |
| | | this.mapViewsList.push(newMapViews); |
| | | } |
| | | } |
| | | |
| | | this.mapViewsList.forEach((m, i) => { |
| | | this.drawGrid({ |
| | | gridDataDetail: gridDataDetailList[i], |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt, |
| | | mapViews: m |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | drawNewGrid({ |
| | | gridDataDetail, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt |
| | | }) { |
| | | const newMapViews = { |
| | | gridViews: gridMapUtil.drawPolylines({ |
| | | points: this.mapViews.gridPoints, |
| | | event: this.firstEvent |
| | | }), |
| | | gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)), |
| | | points: JSON.parse(JSON.stringify(this.mapViews.points)) |
| | | }; |
| | | this.mapViewsList.push(newMapViews); |
| | | this.drawGrid({ |
| | | gridDataDetail, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt, |
| | | mapViews: newMapViews |
| | | }); |
| | | } |
| | | drawTagGrid({ |
| | | tag, |
| | | gridDataDetail, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt |
| | | }) { |
| | | /** |
| | | * 根据tag标签,展示已有的网格或绘制一组新的网格 |
| | | * @param {Object} param0 { |
| | | * tag, 标签 |
| | | * gridDataDetail, 网格数据数组 |
| | | * useCustomColor, 是否使用对比色 |
| | | * opacity, 透明度,取值[0, 1] |
| | | * zIndex, 地图显示层级 |
| | | * showDataTxt, 是否显示数据文本 |
| | | * showRankTxt, 是否显示排名文本 |
| | | * extData, 自定义额外信息对象 |
| | | * } |
| | | */ |
| | | drawTagGrid({ tag, data, grid, dataTxt, rankTxt, extData }) { |
| | | if (!this.mapViewsMap.has(tag)) { |
| | | const newMapViews = { |
| | | gridViews: gridMapUtil.drawPolylines({ |
| | | points: this.mapViews.gridPoints, |
| | | event: this.firstEvent |
| | | }), |
| | | gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)), |
| | | points: JSON.parse(JSON.stringify(this.mapViews.points)) |
| | | }; |
| | | const newMapViews = this._createNewMapViews({ extData }); |
| | | this.infoMap.set(tag, extData); |
| | | this.mapViewsMap.set(tag, newMapViews); |
| | | this.gridDataDetailMap.set(tag, data); |
| | | } |
| | | const _mapViews = this.mapViewsMap.get(tag); |
| | | this.drawGrid({ |
| | | gridDataDetail, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | showDataTxt, |
| | | showRankTxt, |
| | | mapViews: _mapViews |
| | | mapViews: _mapViews, |
| | | data, |
| | | grid, |
| | | dataTxt, |
| | | rankTxt |
| | | }); |
| | | } |
| | | |
| | | deleteTagGrid(tags) { |
| | | this.changeVisibility({ |
| | | tags, |
| | | showGridViews: false, |
| | | showDataTxt: false, |
| | | showRankTxt: false |
| | | }); |
| | | tags.forEach((t) => { |
| | | this.mapViewsMap.delete(t); |
| | | this.gridDataDetailMap.delete(t); |
| | | }); |
| | | } |
| | | |
| | | // 调整各类地图覆盖物的可见性 |
| | | changeVisibility({ tag, showGridViews, showDataTxt, showRankTxt }) { |
| | | let _mapViewsList = []; |
| | | if (this.mapViews) { |
| | | _mapViewsList.push(this.mapViews); |
| | | } |
| | | if (tag && this.mapViewsMap.has(tag)) { |
| | | _mapViewsList.push(this.mapViewsMap.get(tag)); |
| | | } else { |
| | | this.mapViewsMap.forEach((v) => { |
| | | _mapViewsList.push(v); |
| | | }); |
| | | } |
| | | changeVisibility({ tags = [], showGridViews, showDataTxt, showRankTxt }) { |
| | | let { _mapViewsList } = this._getMapViews(...tags); |
| | | |
| | | if (showGridViews != undefined) { |
| | | if (showGridViews) { |
| | | // map.add(this.mapViews.lastGridViews); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.lastGridViews) map.add(v.lastGridViews); |
| | | if (v.lastGridViews) { |
| | | map.add(v.lastGridViews); |
| | | v.show = true; |
| | | } |
| | | }); |
| | | } else { |
| | | // map.remove(this.mapViews.lastGridViews); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.lastGridViews) map.remove(v.lastGridViews); |
| | | if (v.lastGridViews) { |
| | | map.remove(v.lastGridViews); |
| | | v.show = false; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | |
| | | if (showDataTxt) { |
| | | // map.add(this.mapViews.dataTxt); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.dataTxt) map.add(v.dataTxt); |
| | | if (v.dataTxt) { |
| | | map.add(v.dataTxt); |
| | | v.show = true; |
| | | } |
| | | }); |
| | | } else { |
| | | // map.remove(this.mapViews.dataTxt); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.dataTxt) map.remove(v.dataTxt); |
| | | if (v.dataTxt) { |
| | | map.remove(v.dataTxt); |
| | | v.show = false; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | |
| | | if (showRankTxt) { |
| | | // map.add(this.mapViews.rankTxt); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.rankTxt) map.add(v.rankTxt); |
| | | if (v.rankTxt) { |
| | | map.add(v.rankTxt); |
| | | v.show = true; |
| | | } |
| | | }); |
| | | } else { |
| | | // map.remove(this.mapViews.rankTxt); |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.rankTxt) map.remove(v.rankTxt); |
| | | if (v.rankTxt) { |
| | | map.remove(v.rankTxt); |
| | | v.show = false; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | changeGridOpacity({ tag, isOpacity, opacityValue }) { |
| | | let _mapViewsList = []; |
| | | if (this.mapViews) { |
| | | _mapViewsList.push(this.mapViews); |
| | | } |
| | | if (tag && this.mapViewsMap.has(tag)) { |
| | | _mapViewsList.push(this.mapViewsMap.get(tag)); |
| | | } else { |
| | | this.mapViewsMap.forEach((v) => { |
| | | _mapViewsList.push(v); |
| | | }); |
| | | } |
| | | let { _mapViewsList } = tag ? this._getMapViews(tag) : this._getMapViews(); |
| | | |
| | | _mapViewsList.forEach((v) => { |
| | | if (v.lastGridViews) { |
| | | v.lastGridViews.forEach((e) => { |
| | |
| | | }); |
| | | } |
| | | |
| | | setGridEvent(name, event) { |
| | | changeGridColor({ |
| | | tags = [], |
| | | factorName, |
| | | useCustomColor, |
| | | opacity, |
| | | zIndex, |
| | | isMixGridHighlight |
| | | }) { |
| | | let { _mapViewsList, _gridDataDetailList } = this._getMapViews(...tags); |
| | | if (_mapViewsList.length == _gridDataDetailList.length) { |
| | | _mapViewsList.forEach((v, i) => { |
| | | if (v.lastGridViews) { |
| | | if (useCustomColor != undefined) v.useCustomColor = useCustomColor; |
| | | const lastGridDataDetail = _gridDataDetailList[i]; |
| | | if (v.useCustomColor) { |
| | | gridMapUtil.drawGridColorCustom( |
| | | v.lastGridViews, |
| | | lastGridDataDetail, |
| | | factorName ? factorName : this.selectedFactorType.name |
| | | ); |
| | | } else { |
| | | gridMapUtil.drawGridColor( |
| | | v.lastGridViews, |
| | | lastGridDataDetail, |
| | | factorName ? factorName : this.selectedFactorType.name, |
| | | { opacity, zIndex, isMixGridHighlight } |
| | | ); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | setGridEvent(tags, name, event) { |
| | | const { _mapViewsList, _gridDataDetailList } = this._getMapViews(...tags); |
| | | |
| | | if (!this.events.has(name)) { |
| | | this.events.set(name, []); |
| | | } |
| | | const list = this.events.get(name); |
| | | if (list.length > 0) { |
| | | const lastEvent = list[list.length - 1]; |
| | | this.mapViews.gridViews.forEach((polygon) => { |
| | | polygon.off(name, lastEvent); |
| | | _mapViewsList.forEach((v) => { |
| | | v.gridViews.forEach((polygon) => { |
| | | polygon.off(name, lastEvent); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | this.events.get(name).push(event); |
| | | this.mapViews.gridViews.forEach((polygon) => { |
| | | polygon.on(name, event); |
| | | _mapViewsList.forEach((v, i) => { |
| | | const gridDataDetailList = _gridDataDetailList[i]; |
| | | v.gridViews.forEach((polygon) => { |
| | | const { gridCell } = polygon.getExtData(); |
| | | const cellIndex = gridCell.cellIndex; |
| | | const gridDataDetail = gridDataDetailList.find( |
| | | (v) => v.cellId == cellIndex |
| | | ); |
| | | polygon.on(name, (e) => { |
| | | event({ gridCell, gridDataDetail, polygon, extData: v.extData }); |
| | | }); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | setDefaultGridClickEvent(tags) { |
| | | this.setGridEvent( |
| | | tags, |
| | | 'click', |
| | | ({ gridCell, gridDataDetail, extData }) => { |
| | | gridStore.selectedGridCellAndDataDetail = { |
| | | gridCell, |
| | | gridDataDetail, |
| | | extData |
| | | }; |
| | | } |
| | | ); |
| | | |
| | | //鼠标移入事件 |
| | | this.setGridEvent(tags, 'mouseover', ({ polygon }) => { |
| | | const ext = polygon.getExtData(); |
| | | const originOption = polygon.getOptions(); |
| | | ext.originOption = originOption; |
| | | polygon.setOptions({ |
| | | strokeWeight: 2, |
| | | strokeColor: 'red' |
| | | }); |
| | | polygon.setExtData(ext); |
| | | }); |
| | | |
| | | //鼠标移出事件 |
| | | this.setGridEvent(tags, 'mouseout', ({ polygon }) => { |
| | | const ext = polygon.getExtData(); |
| | | polygon.setOptions(ext.originOption); |
| | | }); |
| | | } |
| | | |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 将多组网格进行融合 |
| | | * 重叠的网格进行监测数据均值计算并重新计算对应颜色,形成新的一组融合网格 |
| | | * @param {Array} tags 需要融合的网格标签,当为空时,默认融合所有网格 |
| | | */ |
| | | mixGrid({ tags, isMixGridHighlight = true }) { |
| | | tags.sort((a, b) => { |
| | | return a < b ? -1 : 1; |
| | | }); |
| | | const mixTag = tags.join('-'); |
| | | if (this.mapViewsMap.has(mixTag)) { |
| | | this.changeVisibility({ |
| | | tags: [mixTag], |
| | | showGridViews: true |
| | | }); |
| | | this.changeGridColor({ tags: [mixTag], isMixGridHighlight }); |
| | | } else { |
| | | // const mixMapViews = this._createNewMapViews(); |
| | | // 根据标签tag,获取对应多组网格数据 |
| | | let { _gridDataDetailList } = this._getMapViews(...tags); |
| | | const _dataMap = new Map(); |
| | | // 将每组每个网格数据按照网格编号进行分类,相同网格的数组归集至一起 |
| | | _gridDataDetailList.forEach((list) => { |
| | | list.forEach((gdd) => { |
| | | if (!_dataMap.has(gdd.cellId)) { |
| | | _dataMap.set(gdd.cellId, { |
| | | source: [], |
| | | res: {} |
| | | }); |
| | | } |
| | | _dataMap.get(gdd.cellId).source.push(gdd); |
| | | }); |
| | | }); |
| | | // 计算每个网格下的数据均值 |
| | | const resGridDataDetail = []; |
| | | _dataMap.forEach((v, k) => { |
| | | let total = 0, |
| | | count = v.source.length; |
| | | v.source.forEach((s) => { |
| | | total += s.pm25; |
| | | }); |
| | | v.res = { |
| | | isMixData: true, |
| | | groupId: v.source[0].groupId, |
| | | cellId: v.source[0].cellId, |
| | | pm25: count == 0 ? null : Math.round((total / count) * 10) / 10, |
| | | originData: v.source |
| | | }; |
| | | // 数据量超过1个时,表明该网格数据是融合的,展示高亮的样式 |
| | | if (count > 1) { |
| | | v.res.gridStyle = { |
| | | strokeWeight: 2, |
| | | strokeColor: '#23dad1' |
| | | }; |
| | | } |
| | | resGridDataDetail.push(v.res); |
| | | }); |
| | | // 重新按照监测数据排序并标记排名 |
| | | resGridDataDetail.sort((a, b) => { |
| | | return b.pm25 - a.pm25; |
| | | }); |
| | | resGridDataDetail.forEach((gdd, i) => { |
| | | gdd.rank = i + 1; |
| | | }); |
| | | |
| | | this.drawTagGrid({ |
| | | tag: mixTag, |
| | | data: resGridDataDetail, |
| | | grid: { |
| | | style: { |
| | | isMixGridHighlight |
| | | } |
| | | }, |
| | | extData: { |
| | | name: `走航融合 - ${mixTag}`, |
| | | type: 1 |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return mixTag; |
| | | } |
| | | |
| | | mixGrid2({ tags, isMixGridHighlight = true, gridDataDetailList }) { |
| | | tags.sort((a, b) => { |
| | | return a < b ? -1 : 1; |
| | | }); |
| | | const mixTag = tags.join('-'); |
| | | if (this.mapViewsMap.has(mixTag)) { |
| | | this.changeVisibility({ |
| | | tags: [mixTag], |
| | | showGridViews: true |
| | | }); |
| | | this.changeGridColor({ tags: [mixTag], isMixGridHighlight }); |
| | | } else { |
| | | gridDataDetailList.forEach((gdd) => { |
| | | // 网格数据是融合的,展示高亮的样式 |
| | | if (gdd.mixData) { |
| | | gdd.gridStyle = { |
| | | strokeWeight: 2, |
| | | strokeColor: '#23dad1' |
| | | }; |
| | | } |
| | | }); |
| | | this.drawTagGrid({ |
| | | tag: mixTag, |
| | | data: gridDataDetailList, |
| | | grid: { |
| | | style: { |
| | | isMixGridHighlight |
| | | } |
| | | }, |
| | | extData: { |
| | | name: `走航融合 - ${mixTag}`, |
| | | type: 1 |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return mixTag; |
| | | } |
| | | |
| | | /** |
| | | * 绘制热力图网格 |
| | | * @param {string} tag |
| | | */ |
| | | drawHeatGrid(tag) { |
| | | if (!this.mapViewsMap.has(tag) || !this.gridDataDetailMap.has(tag)) { |
| | | return; |
| | | } |
| | | |
| | | const heatTag = `heat-${tag}`; |
| | | if (this.mapViewsMap.has(heatTag)) { |
| | | this.changeVisibility({ |
| | | tags: [heatTag], |
| | | showGridViews: true |
| | | }); |
| | | } else { |
| | | const _mapViews = this.mapViewsMap.get(tag); |
| | | const _gridDataDetail = this.gridDataDetailMap.get(tag); |
| | | // const groupId = _gridDataDetail[0].groupId; |
| | | // const cellId = _gridDataDetail.cellId; |
| | | |
| | | const originCellIdList = _gridDataDetail.map((v) => v.cellId); |
| | | let headGridDataDetailList = []; |
| | | |
| | | const width = 120; |
| | | const height = 90; |
| | | const eachwidth = 10; |
| | | const eachheight = 10; |
| | | |
| | | const searchLength = 3; |
| | | |
| | | const _dataMap = new Map(); |
| | | |
| | | _gridDataDetail.forEach((gdd) => { |
| | | const searchRes = this.search( |
| | | gdd, |
| | | width, |
| | | height, |
| | | eachwidth, |
| | | eachheight, |
| | | searchLength |
| | | ); |
| | | if (searchRes.find((v) => v.cellId == 1670)) { |
| | | console.log(); |
| | | } |
| | | searchRes.forEach((e) => { |
| | | if (originCellIdList.indexOf(e.cellId) == -1) { |
| | | if (!_dataMap.has(e.cellId)) { |
| | | _dataMap.set(e.cellId, { |
| | | source: [], |
| | | res: {} |
| | | }); |
| | | } |
| | | _dataMap.get(e.cellId).source.push(e); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | _dataMap.forEach((v, k) => { |
| | | let total = 0, |
| | | count = v.source.length; |
| | | v.source.forEach((s) => { |
| | | total += s.pm25; |
| | | }); |
| | | v.res = { |
| | | isHeatData: true, |
| | | groupId: v.source[0].groupId, |
| | | cellId: v.source[0].cellId, |
| | | pm25: count == 0 ? null : Math.round((total / count) * 10) / 10, |
| | | originData: v.source |
| | | }; |
| | | headGridDataDetailList.push(v.res); |
| | | }); |
| | | headGridDataDetailList = headGridDataDetailList.concat(_gridDataDetail); |
| | | |
| | | // 重新按照监测数据排序并标记排名 |
| | | headGridDataDetailList.sort((a, b) => { |
| | | return b.pm25 - a.pm25; |
| | | }); |
| | | headGridDataDetailList.forEach((gdd, i) => { |
| | | gdd.rank = i + 1; |
| | | }); |
| | | |
| | | this.drawTagGrid({ |
| | | tag: heatTag, |
| | | data: headGridDataDetailList, |
| | | // grid: { |
| | | // style: { |
| | | // isMixGridHighlight: |
| | | // isMixGridHighlight == undefined ? true : isMixGridHighlight |
| | | // } |
| | | // }, |
| | | extData: { |
| | | name: `走航热力图 - ${heatTag}`, |
| | | type: 2 |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return heatTag; |
| | | } |
| | | |
| | | drawHeatGrid2(tag, headGridDataDetailList) { |
| | | const heatTag = `heat-${tag}`; |
| | | if (this.mapViewsMap.has(heatTag)) { |
| | | this.changeVisibility({ |
| | | tags: [heatTag], |
| | | showGridViews: true |
| | | }); |
| | | } else { |
| | | this.drawTagGrid({ |
| | | tag: heatTag, |
| | | data: headGridDataDetailList, |
| | | extData: { |
| | | name: `走航热力图 - ${heatTag}`, |
| | | type: 2 |
| | | } |
| | | }); |
| | | } |
| | | return heatTag; |
| | | } |
| | | |
| | | search(gdd, width, height, eachwidth, eachheight, searchLength) { |
| | | function getCellWidthRange(cellId, width, height) { |
| | | const total = width * height; |
| | | const x = Math.ceil(cellId / total) - 1; |
| | | let first = 1 + x * total, |
| | | last = width + x * total; |
| | | |
| | | let scale = 0; |
| | | while (scale < height) { |
| | | const min = first + scale * width; |
| | | const max = last + scale * width; |
| | | if (cellId >= min && cellId <= max) { |
| | | return [min, max]; |
| | | } |
| | | scale++; |
| | | } |
| | | } |
| | | |
| | | const cellId = gdd.cellId; |
| | | // const minData = gdd.pm25 / 2 |
| | | const dataOffset = (gdd.pm25 - gdd.pm25 / 2) / 3; |
| | | |
| | | const hOffset = eachwidth; |
| | | const wOffset = 1; |
| | | |
| | | const cellIdMin = 1; |
| | | const cellIdMax = width * height; |
| | | |
| | | let searchWidth = 0 - searchLength, |
| | | searchHeight = 0 - searchLength; |
| | | |
| | | const result = []; |
| | | |
| | | const eachRange = getCellWidthRange(cellId, eachwidth, eachheight); |
| | | const groupRange = getCellWidthRange( |
| | | Math.ceil(cellId / (eachwidth * eachheight)), |
| | | width / eachwidth, |
| | | height / eachheight |
| | | ); |
| | | |
| | | for (let w = searchWidth; w <= searchLength; w++) { |
| | | // 先进行横向的坐标变换 |
| | | let _cellId = cellId + w * wOffset; |
| | | if (_cellId < eachRange[0] || _cellId > eachRange[1]) { |
| | | const cellOffset = |
| | | _cellId < eachRange[0] |
| | | ? _cellId - eachRange[0] |
| | | : _cellId - eachRange[1]; |
| | | |
| | | const groupOffset = Math[cellOffset / eachwidth > 0 ? 'ceil' : 'floor']( |
| | | cellOffset / eachwidth |
| | | ); |
| | | |
| | | const newEachRange = eachRange.map( |
| | | (r) => r + groupOffset * eachwidth * eachheight |
| | | ); |
| | | |
| | | _cellId = |
| | | groupOffset > 0 |
| | | ? newEachRange[0] + cellOffset - wOffset |
| | | : newEachRange[1] + cellOffset + wOffset; |
| | | |
| | | const _groupId = Math.ceil(_cellId / (eachwidth * eachheight)); |
| | | |
| | | if (_groupId < groupRange[0] || _groupId > groupRange[1]) { |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | for (let h = searchHeight; h <= searchLength; h++) { |
| | | if (w == 0 && h == 0) continue; |
| | | |
| | | const _eachRange = getCellWidthRange(_cellId, eachwidth, eachheight); |
| | | // if (_eachRange == undefined) { |
| | | // console.log(); |
| | | |
| | | // } |
| | | const wOffset = _cellId - _eachRange[0]; |
| | | let _resCellId = _cellId + h * hOffset; |
| | | if (_resCellId < cellIdMin || _resCellId > cellIdMax) continue; |
| | | |
| | | const total = eachwidth * eachheight; |
| | | const x = Math.ceil(_cellId / total) - 1; |
| | | const eachCellIdMin = 1 + x * total; |
| | | const eachCellIdMax = total + x * total; |
| | | const topCell = eachCellIdMin + wOffset; |
| | | const bottomCell = eachCellIdMax - eachwidth + 1 + wOffset; |
| | | if (_resCellId < eachCellIdMin || _resCellId > eachCellIdMax) { |
| | | const cellOffset = |
| | | _resCellId < eachCellIdMin |
| | | ? _resCellId - topCell |
| | | : _resCellId - bottomCell; |
| | | |
| | | const newTopCell = |
| | | cellOffset > 0 |
| | | ? topCell + width * eachheight |
| | | : topCell - width * eachheight; |
| | | const newBottomCell = |
| | | cellOffset > 0 |
| | | ? bottomCell + width * eachheight |
| | | : bottomCell - width * eachheight; |
| | | |
| | | _resCellId = |
| | | cellOffset > 0 |
| | | ? newTopCell + cellOffset - hOffset |
| | | : newBottomCell + cellOffset + hOffset; |
| | | } |
| | | result.push({ |
| | | groupId: gdd.groupId, |
| | | cellId: _resCellId, |
| | | pm25: gdd.pm25 - Math.max(Math.abs(w), Math.abs(h)) * dataOffset |
| | | }); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | _getMapViews(...tags) { |
| | | let _mapViewsList = [], |
| | | _gridDataDetailList = []; |
| | | if (tags.length > 0) { |
| | | tags.forEach((tag) => { |
| | | if (this.mapViewsMap.has(tag) && this.gridDataDetailMap.has(tag)) { |
| | | _mapViewsList.push(this.mapViewsMap.get(tag)); |
| | | _gridDataDetailList.push(this.gridDataDetailMap.get(tag)); |
| | | } |
| | | }); |
| | | } else { |
| | | this.mapViewsMap.forEach((v) => { |
| | | _mapViewsList.push(v); |
| | | }); |
| | | this.gridDataDetailMap.forEach((v) => { |
| | | _gridDataDetailList.push(v); |
| | | }); |
| | | if (this.mapViews && this.gridDataDetail) { |
| | | _mapViewsList.push(this.mapViews); |
| | | _gridDataDetailList.push(this.gridDataDetail); |
| | | } |
| | | } |
| | | |
| | | return { _mapViewsList, _gridDataDetailList }; |
| | | } |
| | | |
| | | _createNewMapViews({ extData }) { |
| | | return { |
| | | gridViews: gridMapUtil.drawPolylines({ |
| | | points: this.mapViews.gridPoints, |
| | | event: this.firstEvent |
| | | }), |
| | | gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)), |
| | | points: JSON.parse(JSON.stringify(this.mapViews.points)), |
| | | extData, |
| | | show: true |
| | | }; |
| | | } |
| | | } |