diff --git a/src/views/sponeScreen/gisMF/legendKF.vue b/src/views/sponeScreen/gisMF/legendKF.vue index 1517821..8176b6d 100644 --- a/src/views/sponeScreen/gisMF/legendKF.vue +++ b/src/views/sponeScreen/gisMF/legendKF.vue @@ -235,6 +235,22 @@ item.name = item.stName + '/' + item.rainCumulative + 'mm'; }); console.log('雨量站历史数据---', datas, localStorage.getItem('setRainDateKF')); + item.rainData = newfiberMapBoxVectorLayer.getGeojsonData(datas); + item.dataArea = newfiberMapBoxVectorLayer.getPolygonGeojson(datas); + newfiberMapBoxVectorLayer.addGeojsonSymbol(item.layername, item.rainData, rainStation_icon); + item.dataArea.features.forEach(feature => { + console.log(Number(feature.properties.rainCumulative)); + // 实时降雨量范围不同颜色 小-中-大 + if (Number(feature.properties.rainCumulative) <= 0.3) { + feature.properties.fillcolor = 'rgba(41, 184, 219,0.7)'; + } else if (Number(feature.properties.rainCumulative) > 0.3 && Number(feature.properties.rainCumulative) <= 0.8) { + feature.properties.fillcolor = 'rgba(255, 237, 82,0.7)'; + } else if (Number(feature.properties.rainCumulative) > 0.8) { + feature.properties.fillcolor = 'rgba(255, 69, 69,0.7)'; + } + }); + console.log('item.dataArea---', item.dataArea); + newfiberMapBoxVectorLayer.addGeojsonPolygon(item.layername + '_area', item.dataArea); } else { // 实时降雨数据 // 渲染文字和降雨量 @@ -254,17 +270,16 @@ } }); newfiberMapBoxVectorLayer.addGeojsonPolygon(item.layername + '_area', item.dataArea); + setTimeout(() => { + newfiberMapbox.map.moveLayer(item.layername + '_area', item.layername); + }, 1000); + rainDataTimer.value = setInterval(() => { + item.rainData.features.forEach(feature => { + feature.properties.name = feature.properties.stName + '/' + feature.properties.pn05 + 'mm'; + }); + newfiberMapbox.map.getSource(item.layername).setData(item.rainData); + }, 5 * 60 * 1000); } - - setTimeout(() => { - newfiberMapbox.map.moveLayer(item.layername + '_area', item.layername); - }, 1000); - rainDataTimer.value = setInterval(() => { - item.rainData.features.forEach(feature => { - feature.properties.name = feature.properties.stName + '/' + feature.properties.pn05 + 'mm'; - }); - newfiberMapbox.map.getSource(item.layername).setData(item.rainData); - }, 5 * 60 * 1000); } else { newfiberMapBoxVectorLayer.removeByIds([item.layername + '_area']); clearInterval(rainDataTimer.value); diff --git a/src/views/sponeScreen/gisMF/legendKF.vue b/src/views/sponeScreen/gisMF/legendKF.vue index 1517821..8176b6d 100644 --- a/src/views/sponeScreen/gisMF/legendKF.vue +++ b/src/views/sponeScreen/gisMF/legendKF.vue @@ -235,6 +235,22 @@ item.name = item.stName + '/' + item.rainCumulative + 'mm'; }); console.log('雨量站历史数据---', datas, localStorage.getItem('setRainDateKF')); + item.rainData = newfiberMapBoxVectorLayer.getGeojsonData(datas); + item.dataArea = newfiberMapBoxVectorLayer.getPolygonGeojson(datas); + newfiberMapBoxVectorLayer.addGeojsonSymbol(item.layername, item.rainData, rainStation_icon); + item.dataArea.features.forEach(feature => { + console.log(Number(feature.properties.rainCumulative)); + // 实时降雨量范围不同颜色 小-中-大 + if (Number(feature.properties.rainCumulative) <= 0.3) { + feature.properties.fillcolor = 'rgba(41, 184, 219,0.7)'; + } else if (Number(feature.properties.rainCumulative) > 0.3 && Number(feature.properties.rainCumulative) <= 0.8) { + feature.properties.fillcolor = 'rgba(255, 237, 82,0.7)'; + } else if (Number(feature.properties.rainCumulative) > 0.8) { + feature.properties.fillcolor = 'rgba(255, 69, 69,0.7)'; + } + }); + console.log('item.dataArea---', item.dataArea); + newfiberMapBoxVectorLayer.addGeojsonPolygon(item.layername + '_area', item.dataArea); } else { // 实时降雨数据 // 渲染文字和降雨量 @@ -254,17 +270,16 @@ } }); newfiberMapBoxVectorLayer.addGeojsonPolygon(item.layername + '_area', item.dataArea); + setTimeout(() => { + newfiberMapbox.map.moveLayer(item.layername + '_area', item.layername); + }, 1000); + rainDataTimer.value = setInterval(() => { + item.rainData.features.forEach(feature => { + feature.properties.name = feature.properties.stName + '/' + feature.properties.pn05 + 'mm'; + }); + newfiberMapbox.map.getSource(item.layername).setData(item.rainData); + }, 5 * 60 * 1000); } - - setTimeout(() => { - newfiberMapbox.map.moveLayer(item.layername + '_area', item.layername); - }, 1000); - rainDataTimer.value = setInterval(() => { - item.rainData.features.forEach(feature => { - feature.properties.name = feature.properties.stName + '/' + feature.properties.pn05 + 'mm'; - }); - newfiberMapbox.map.getSource(item.layername).setData(item.rainData); - }, 5 * 60 * 1000); } else { newfiberMapBoxVectorLayer.removeByIds([item.layername + '_area']); clearInterval(rainDataTimer.value); diff --git a/src/views/sponeScreen/gisMF/mapboxVectorLayer.js b/src/views/sponeScreen/gisMF/mapboxVectorLayer.js index 9dfd788..6d5e17b 100644 --- a/src/views/sponeScreen/gisMF/mapboxVectorLayer.js +++ b/src/views/sponeScreen/gisMF/mapboxVectorLayer.js @@ -192,6 +192,80 @@ }); } } + //构建geojson格式 + static getGeojsonData(dataList) { + let features = []; + let feature = {}; + dataList.forEach(data => { + if (data.lonLat) { + let lonlat = data.lonLat.split(','); + feature = { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [Number(lonlat[0]), Number(lonlat[1])], + }, + properties: data, + }; + } else if (data.lonlat) { + let lonlat = data.lonlat.split(','); + feature = { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [Number(lonlat[0]), Number(lonlat[1])], + }, + properties: data, + }; + } else if (data.lon && data.lat) { + feature = { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [Number(data.lon), Number(data.lat)], + }, + properties: data, + }; + } else if (data.originalX && data.originalY) { + feature = { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [Number(data.originalX), Number(data.originalY)], + }, + properties: data, + }; + } else if (data.longitude && data.latitude) { + feature = { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [Number(data.longitude), Number(data.latitude)], + }, + properties: data, + }; + } + features.push(feature); + }); + return { + type: 'FeatureCollection', + features: features, + }; + } + //汇水范围json + static getPolygonGeojson(dataList) { + let features = []; + let feature = {}; + dataList.forEach(data => { + if (!data.geometrys) return; + feature = turf.feature(Terraformer.WKT.parse(data.geometrys), data); + features.push(feature); + }); + return { + type: 'FeatureCollection', + features: features, + }; + } //添加geojson面 static addGeojsonPolygon(layerId, geojson) { if (!newfiberMapbox.map.getLayer(layerId)) {