|
@@ -0,0 +1,457 @@
|
|
|
+import React, { PureComponent } from "react";
|
|
|
+import { Map, MapvglView, MapvglLayer } from "react-bmapgl";
|
|
|
+
|
|
|
+import { styleJson } from "../centerPage/charts/BMapConfig";
|
|
|
+import Point from "./Point";
|
|
|
+import Legend from "../Map/Legend";
|
|
|
+import InfoBox from "./InfoBox";
|
|
|
+
|
|
|
+// 浊度,余氯和 PH 值
|
|
|
+const data = [
|
|
|
+ {
|
|
|
+ name: "监测点1",
|
|
|
+ position: { lng: 120.76320738823746, lat: 31.741432990607994 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "余氯",
|
|
|
+ value: "",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_2nd_Stage_DP",
|
|
|
+ deviceName: "RO1二段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "PH",
|
|
|
+ value: "",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_2_2nd_Stage_DP",
|
|
|
+ deviceName: "RO2二段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 0,
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ name: "监测点2",
|
|
|
+ position: { lng: 120.63814859657909, lat: 31.78603808271634 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 50,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "监测点3",
|
|
|
+ position: { lng: 120.67528441284294, lat: 31.776567069187767 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 20,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "监测点4",
|
|
|
+ position: { lng: 120.61788229509295, lat: 31.792679949152973 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 90,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "监测点5",
|
|
|
+ position: { lng: 120.64299239870044, lat: 31.771555311429843 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 80,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "监测点6",
|
|
|
+ position: { lng: 120.67377745218297, lat: 31.787739083321107 },
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ value: 60,
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+const pipeData = [
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.76320738823746, 31.741432990607994],
|
|
|
+ [120.67528441284294, 31.776567069187767],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ start: "监测点1",
|
|
|
+ end: "监测点3",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.67528441284294, 31.776567069187767],
|
|
|
+ [120.63814859657909, 31.78603808271634],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ start: "监测点3",
|
|
|
+ end: "监测点2",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.63814859657909, 31.78603808271634],
|
|
|
+ [120.61788229509295, 31.792679949152973],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ start: "监测点2",
|
|
|
+ end: "监测点4",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.63804095653205, 31.786635735178557],
|
|
|
+ [120.63265895417499, 31.799277469243197],
|
|
|
+ [120.63874061683849, 31.800472597396833],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.63814859657909, 31.78603808271634],
|
|
|
+ [120.64299239870044, 31.771555311429843],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ start: "监测点2",
|
|
|
+ end: "监测点5",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.67528441284294, 31.776567069187767],
|
|
|
+ [120.67377745218297, 31.787739083321107],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ start: "监测点3",
|
|
|
+ end: "监测点6",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.67523059281936, 31.775785436942982],
|
|
|
+ [120.67458475253653, 31.761944843898444],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.63954791719192, 31.781624528379645],
|
|
|
+ [120.61979596854141, 31.780567082731945],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [
|
|
|
+ [120.64310003874758, 31.771509330731554],
|
|
|
+ [120.63201311389199, 31.77242894031243],
|
|
|
+ [120.62786897207705, 31.77311864144008],
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+class BMap extends PureComponent {
|
|
|
+ constructor(props) {
|
|
|
+ super(props);
|
|
|
+ this.state = {
|
|
|
+ position: {},
|
|
|
+ active: 1,
|
|
|
+ visible: false,
|
|
|
+ currentData: {},
|
|
|
+ pipe: [],
|
|
|
+ pointData: [...data],
|
|
|
+ layer: getLayer(pipeData, data),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ lineLayer = null;
|
|
|
+
|
|
|
+ componentDidMount() {}
|
|
|
+
|
|
|
+ onClickLine(e, index) {
|
|
|
+ console.log(e, index);
|
|
|
+ e.cancelBubble = true;
|
|
|
+ this.setState({
|
|
|
+ active: index,
|
|
|
+ visible: true,
|
|
|
+ position: { top: e.pixel.y + "px", left: e.pixel.x + "px" },
|
|
|
+ currentData: {
|
|
|
+ name: `管道${index}`,
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: "浊度",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_1st_Stage_DP",
|
|
|
+ deviceName: "RO1一段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "余氯",
|
|
|
+ value: "11",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_1_2nd_Stage_DP",
|
|
|
+ deviceName: "RO1二段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "PH",
|
|
|
+ value: "1",
|
|
|
+ deviceId: "1436022785",
|
|
|
+ deviceItems: "Skid_2_2nd_Stage_DP",
|
|
|
+ deviceName: "RO2二段压差",
|
|
|
+ project_id: 46,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ showInfo(e, item) {
|
|
|
+ const { currentData } = this.state;
|
|
|
+ e.stopPropagation();
|
|
|
+ if (currentData == item) {
|
|
|
+ this.setState({
|
|
|
+ visible: false,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ visible: true,
|
|
|
+ currentData: item,
|
|
|
+ position: { top: e.pageY - 20 + "px", left: e.pageX + 20 + "px" },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ setPipe() {
|
|
|
+ const { pipe } = this.state;
|
|
|
+ this.setState({
|
|
|
+ edit: 1,
|
|
|
+ pipe: [
|
|
|
+ ...pipe,
|
|
|
+ {
|
|
|
+ geometry: {
|
|
|
+ type: "LineString",
|
|
|
+ coordinates: [],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+ }
|
|
|
+ setPoint() {}
|
|
|
+
|
|
|
+ save() {
|
|
|
+ const { pipe } = this.state;
|
|
|
+ console.log(JSON.stringify(pipe));
|
|
|
+ }
|
|
|
+
|
|
|
+ mapOnClick(e) {
|
|
|
+ const { edit, pipe } = this.state;
|
|
|
+ if (edit == 1) {
|
|
|
+ var current = pipe[pipe.length - 1];
|
|
|
+ const { lat, lng } = e.latlng;
|
|
|
+ current.geometry.coordinates.push([lng, lat]);
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ pipe: [...pipe],
|
|
|
+ visible: false,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.setState({
|
|
|
+ visible: false,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ render() {
|
|
|
+ const { visible, position, currentData, active, layer, pointData } =
|
|
|
+ this.state;
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ position: "absolute",
|
|
|
+ left: 0,
|
|
|
+ top: 0,
|
|
|
+ height: "100vh",
|
|
|
+ width: "100vw",
|
|
|
+ zIndex: 0,
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Map
|
|
|
+ style={{
|
|
|
+ width: "100%",
|
|
|
+ height: "100%",
|
|
|
+ }}
|
|
|
+ center={new window.BMapGL.Point(120.60315172059, 31.7329254736496)}
|
|
|
+ minZoom={12}
|
|
|
+ zoom={11}
|
|
|
+ mapStyleV2={{
|
|
|
+ styleJson,
|
|
|
+ }}
|
|
|
+ enableScrollWheelZoom
|
|
|
+ onClick={(e) => this.mapOnClick(e)}
|
|
|
+ >
|
|
|
+ {pointData.map((item, index) => (
|
|
|
+ <Point
|
|
|
+ key={`${item}_${index}`}
|
|
|
+ title={item.value}
|
|
|
+ position={item.position}
|
|
|
+ data={item.data}
|
|
|
+ onClick={(e) => this.showInfo(e, item)}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ <MapvglView>
|
|
|
+ {layer.map((item) => (
|
|
|
+ <MapvglLayer
|
|
|
+ type="LineRainbowLayer"
|
|
|
+ data={[item]}
|
|
|
+ options={{
|
|
|
+ color: item.color,
|
|
|
+ style: "road", // road, arrow, normal
|
|
|
+ width: 4,
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ </MapvglView>
|
|
|
+ </Map>
|
|
|
+ {visible && (
|
|
|
+ <InfoBox
|
|
|
+ position={position}
|
|
|
+ title={currentData.name}
|
|
|
+ dataPump={currentData.data}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ <Legend
|
|
|
+ list={[
|
|
|
+ { type: 1, name: "COD" },
|
|
|
+ { type: 2, name: "PH" },
|
|
|
+ ]}
|
|
|
+ active={active}
|
|
|
+ onClick={(active) => this.setState({ active: active })}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getLayer(pipeData, pointData) {
|
|
|
+ var pointMap = new window.Map();
|
|
|
+
|
|
|
+ pointData.forEach((point) => {
|
|
|
+ pointMap.set(point.name, point);
|
|
|
+ });
|
|
|
+ pipeData.forEach((pipe) => {
|
|
|
+ let start = pointMap.get(pipe.properties?.start),
|
|
|
+ end = pointMap.get(pipe.properties?.end);
|
|
|
+
|
|
|
+ if (start) {
|
|
|
+ // 根据监测点数据设置渐变色
|
|
|
+ pipe.color = [
|
|
|
+ getGradientColor(start.value),
|
|
|
+ getGradientColor(end?.value || start.value),
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ // 默认蓝色
|
|
|
+ pipe.color = ["#0000ff", "#0000ff"];
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return pipeData;
|
|
|
+}
|
|
|
+function getGradientColor(percent) {
|
|
|
+ var startColor = [0, 0, 255]; // 蓝色 渐变开始的颜色
|
|
|
+ var maxEndColor = [255, 0, 0]; // 红色 渐变最大结束的颜色
|
|
|
+
|
|
|
+ var r = Math.round(
|
|
|
+ startColor[0] + (maxEndColor[0] - startColor[0]) * (percent / 100)
|
|
|
+ );
|
|
|
+ var g = Math.round(
|
|
|
+ startColor[1] + (maxEndColor[1] - startColor[1]) * (percent / 100)
|
|
|
+ );
|
|
|
+ var b = Math.round(
|
|
|
+ startColor[2] + (maxEndColor[2] - startColor[2]) * (percent / 100)
|
|
|
+ );
|
|
|
+
|
|
|
+ var endColor =
|
|
|
+ "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
|
|
|
+ return endColor;
|
|
|
+}
|
|
|
+
|
|
|
+function componentToHex(c) {
|
|
|
+ var hex = c.toString(16);
|
|
|
+ return hex.length === 1 ? "0" + hex : hex;
|
|
|
+}
|
|
|
+
|
|
|
+export default BMap;
|