204 lines
5.3 KiB
JavaScript
204 lines
5.3 KiB
JavaScript
import React, { useEffect } from 'react';
|
|
import { zindexmarker } from '../zindex';
|
|
import { DRP_COLORS } from "../../../../utils/renutils";
|
|
import {useSelector} from "react-redux";
|
|
|
|
const {
|
|
css,
|
|
physics,
|
|
} = window.popmotionXL;
|
|
|
|
function renderMarker({ h24 }, { width, highlight }) {
|
|
|
|
let color1;
|
|
// if (h24 === 0 || h24 === null) {
|
|
// color1 = "#ADB6D9";
|
|
// } else if (h24 >= 0.1 && h24 < 10) {
|
|
// color1 = "#BDEF9A";
|
|
// } else if (h24 >= 10 && h24 < 25) {
|
|
// color1 = "#59B666";
|
|
// } else if (h24 >= 25 && h24 < 50) {
|
|
// color1 = "#6EC2FA";
|
|
// } else if (h24 >= 50 && h24 < 100) {
|
|
// color1 = "#1E1ACA";
|
|
// } else if (h24 >= 100 && h24 < 250) {
|
|
// color1 = "#EB20F7";
|
|
// } else if (h24 >= 250) {
|
|
// color1 = "#781D4F";
|
|
// }
|
|
color1 = "#1E1ACA";
|
|
|
|
return `
|
|
<div style="cursor:pointer">
|
|
<svg t="1619076397355" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4205" width="${12}" height="${12}">
|
|
<div style="width:10px;height:10px;background:${color1};border-radius: 50%;"></div>
|
|
</svg>
|
|
</div>
|
|
`
|
|
}
|
|
|
|
const dist1 = 22000 * 22000;
|
|
const dist2 = 8000 * 8000;
|
|
|
|
|
|
function RealDrpMarker({ data, dispatch, setting, zoom, distSq }) {
|
|
const highlight = setting;
|
|
|
|
let zindexOffset = 1;
|
|
if (!data.status) {
|
|
zindexOffset = 0;
|
|
} else if (data.alarm) {
|
|
zindexOffset = 2;
|
|
}
|
|
|
|
useEffect(() => {
|
|
const width = 12;
|
|
|
|
const placeholder = document.getElementById(`marker_drp_${data.id}`);
|
|
if (!placeholder) {
|
|
return;
|
|
}
|
|
|
|
const ratio = highlight ? 1.2 : 1.0;
|
|
|
|
const svgMarker = renderMarker(data, { width: width * ratio, highlight });
|
|
|
|
placeholder.innerHTML = svgMarker;
|
|
|
|
if (!highlight) {
|
|
|
|
const el = placeholder.firstChild;
|
|
const marker = el.nextSibling;
|
|
|
|
const markerSVG = marker.querySelector('svg');
|
|
|
|
const markerRenderer = css(markerSVG, {
|
|
enableHardwareAcceleration: false
|
|
});
|
|
|
|
const markerGrowSize = 1.2;
|
|
|
|
const markerScale = physics({
|
|
from: 1,
|
|
to: markerGrowSize,
|
|
velocity: 20,
|
|
spring: 300,
|
|
friction: 0.8,
|
|
onUpdate: (x) => markerRenderer.set('scale', x),
|
|
});
|
|
|
|
|
|
const zindex = zindexmarker.drp + zindexOffset;
|
|
|
|
marker.addEventListener('mouseenter', () => {
|
|
if (placeholder.parentNode.style.zIndex); {
|
|
placeholder.parentNode.style.zIndex = zindex + zindexmarker.hilightPlus;
|
|
}
|
|
markerScale.props.from = 1;
|
|
markerScale.props.to = markerGrowSize;
|
|
markerScale.start();
|
|
});
|
|
|
|
marker.addEventListener('mouseleave', () => {
|
|
if (placeholder.parentNode.style.zIndex); {
|
|
placeholder.parentNode.style.zIndex = zindex;
|
|
}
|
|
markerScale.props.from = markerGrowSize;
|
|
markerScale.props.to = 1;
|
|
markerScale.start();
|
|
});
|
|
}
|
|
|
|
return () => {
|
|
placeholder.innerHTML = '';
|
|
}
|
|
}, [highlight]);
|
|
|
|
const showPop = () => {
|
|
dispatch.runtime.setFeaturePop({
|
|
id: data.id,
|
|
type: 'drp',
|
|
data,
|
|
lgtd: data.lgtd,
|
|
lttd: data.lttd,
|
|
elev: data.elev,
|
|
})
|
|
}
|
|
|
|
let markerZoom;
|
|
if (highlight) {
|
|
markerZoom = 2;
|
|
} else if (zoom) {
|
|
markerZoom = (zoom - 10) * 0.5;
|
|
} else {
|
|
markerZoom = (dist1 - distSq) / (dist1 - dist2) * 2 + 1;
|
|
}
|
|
if (markerZoom < 1) {
|
|
markerZoom = 1;
|
|
} else if (markerZoom > 2.5) {
|
|
markerZoom = 2.5;
|
|
} else {
|
|
markerZoom = parseFloat(markerZoom.toFixed(1));
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
id={`marker_drp_${data.id}`}
|
|
style={{
|
|
position: 'absolute',
|
|
bottom: 0,
|
|
left: 0,
|
|
transformOrigin: 'bottom center',
|
|
transform: `translateX(-50%)${markerZoom > 1 ? ' scale(' + markerZoom + ')' : ''}`,
|
|
lineHeight: 1,
|
|
zIndex: zindexmarker.drp + zindexOffset + (highlight ? zindexmarker.hilightPlus : 0)
|
|
}}
|
|
onClick={showPop}
|
|
></div>
|
|
{/* {
|
|
(zoom > 12 || distSq < dist1 || highlight) && (
|
|
<div
|
|
className="markerLabel2"
|
|
style={{
|
|
backgroundColor: '#0008',
|
|
fontSize: 12,
|
|
fontWeight:"bold",
|
|
lineHeight: 1,
|
|
bottom: -14 * markerZoom,
|
|
left: 0,
|
|
transform: `translateX(-50%)`,
|
|
zIndex: zindexmarker.drpLabel + zindexOffset + (highlight ? zindexmarker.hilightPlus : 0),
|
|
color: `#fff`,
|
|
textShadow: '2px 2px 4px #000000'
|
|
}}>
|
|
{data.h24 || '-'}m
|
|
</div>
|
|
)
|
|
}*/}
|
|
{
|
|
(zoom > 14 || distSq < dist2 || highlight) && (
|
|
<div
|
|
className="markerLabel"
|
|
style={{
|
|
backgroundColor: '#0008',
|
|
padding: 4,
|
|
borderRadius: 4,
|
|
fontSize: 10,
|
|
lineHeight: 1,
|
|
top: 0,
|
|
left: 0,
|
|
transform: 'translateX(-50%)',
|
|
zIndex: zindexmarker.drpLabel + zindexOffset + (highlight ? zindexmarker.hilightPlus : 0), color: '#fff'
|
|
}}>
|
|
<div style={{textAlign:"center"}}>{data.name}</div>
|
|
{/* <div style={{textAlign:"center"}}>{data.h24 || '-'}m</div> */}
|
|
</div>
|
|
)
|
|
}
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default React.memo(RealDrpMarker);
|