UNPKG

ol-plot-tool

Version:
1,939 lines 170 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; import { Overlay, Map as Map$1, Observable, Feature } from "ol"; import Draw, { createBox } from "ol/interaction/Draw"; import DoubleClickZoom from "ol/interaction/DoubleClickZoom"; import { Style, Fill, Stroke, Circle as Circle$2, Icon, RegularShape, Text } from "ol/style"; import Overlay$1 from "ol/Overlay"; import { Group, Vector } from "ol/layer"; import { Vector as Vector$1 } from "ol/source"; import DragPan from "ol/interaction/DragPan"; import BaseEvent from "ol/events/Event"; import { Point as Point$2, LineString, Polygon as Polygon$2, Geometry as Geometry$1 } from "ol/geom"; import { fromExtent } from "ol/geom/Polygon"; import { boundingExtent, getSize, getBottomLeft, getTopRight, buffer } from "ol/extent"; import { asArray, asString } from "ol/color"; const index = ""; const FITTING_COUNT = 100; const HALF_PI = Math.PI / 2; const ZERO_TOLERANCE = 1e-4; const BASE_LAYERNAME = "ol-plot-vector-layer"; const BASE_HELP_CONTROL_POINT_ID = "plot-helper-control-point-div"; const BASE_HELP_HIDDEN = "plot-helper-hidden-div"; const DEF_TEXT_STYEL = { // 默认文本框样式 borderRadius: "2px", fontSize: "12px", outline: 0, overflow: "hidden", boxSizing: "border-box", border: "1px solid #eeeeee", fontFamily: "Helvetica Neue,Helvetica,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Noto Sans CJK SC,WenQuanYi Micro Hei,Arial,sans-serif", color: "#010500", fontWeight: 400, padding: "3px", fontStretch: "normal", lineHeight: "normal", textAlign: "left", marginLeft: "auto", marginRight: "auto", width: "auto", height: "auto", background: "rgb(255, 255, 255)", fontStyle: "", fontVariant: "" }; const MathDistance = (pnt1, pnt2) => Math.sqrt((pnt1[0] - pnt2[0]) ** 2 + (pnt1[1] - pnt2[1]) ** 2); const wholeDistance = (points) => { let distance = 0; if (points && Array.isArray(points) && points.length > 0) { points.forEach((item, index2) => { if (index2 < points.length - 1) { distance += MathDistance(item, points[index2 + 1]); } }); } return distance; }; const getBaseLength = (points) => wholeDistance(points) ** 0.99; const Mid = (point1, point2) => [(point1[0] + point2[0]) / 2, (point1[1] + point2[1]) / 2]; const getCircleCenterOfThreePoints = (point1, point2, point3) => { const pntA = [(point1[0] + point2[0]) / 2, (point1[1] + point2[1]) / 2]; const pntB = [pntA[0] - point1[1] + point2[1], pntA[1] + point1[0] - point2[0]]; const pntC = [(point1[0] + point3[0]) / 2, (point1[1] + point3[1]) / 2]; const pntD = [pntC[0] - point1[1] + point3[1], pntC[1] + point1[0] - point3[0]]; return getIntersectPoint(pntA, pntB, pntC, pntD); }; const getIntersectPoint = (pntA, pntB, pntC, pntD) => { if (pntA[1] === pntB[1]) { const f2 = (pntD[0] - pntC[0]) / (pntD[1] - pntC[1]); const x2 = f2 * (pntA[1] - pntC[1]) + pntC[0]; const y2 = pntA[1]; return [x2, y2]; } if (pntC[1] === pntD[1]) { const e22 = (pntB[0] - pntA[0]) / (pntB[1] - pntA[1]); const x2 = e22 * (pntC[1] - pntA[1]) + pntA[0]; const y2 = pntC[1]; return [x2, y2]; } const e2 = (pntB[0] - pntA[0]) / (pntB[1] - pntA[1]); const f = (pntD[0] - pntC[0]) / (pntD[1] - pntC[1]); const y = (e2 * pntA[1] - pntA[0] - f * pntC[1] + pntC[0]) / (e2 - f); const x = e2 * y - e2 * pntA[1] + pntA[0]; return [x, y]; }; const getAzimuth = (startPoint, endPoint) => { let azimuth = 0; const angle = Math.asin(Math.abs(endPoint[1] - startPoint[1]) / MathDistance(startPoint, endPoint)); if (endPoint[1] >= startPoint[1] && endPoint[0] >= startPoint[0]) { azimuth = angle + Math.PI; } else if (endPoint[1] >= startPoint[1] && endPoint[0] < startPoint[0]) { azimuth = Math.PI * 2 - angle; } else if (endPoint[1] < startPoint[1] && endPoint[0] < startPoint[0]) { azimuth = angle; } else if (endPoint[1] < startPoint[1] && endPoint[0] >= startPoint[0]) { azimuth = Math.PI - angle; } return azimuth; }; const getAngleOfThreePoints = (pntA, pntB, pntC) => { const angle = getAzimuth(pntB, pntA) - getAzimuth(pntB, pntC); return angle < 0 ? angle + Math.PI * 2 : angle; }; const isClockWise = (pnt1, pnt2, pnt3) => (pnt3[1] - pnt1[1]) * (pnt2[0] - pnt1[0]) > (pnt2[1] - pnt1[1]) * (pnt3[0] - pnt1[0]); const getCubicValue = (t2, startPnt, cPnt1, cPnt2, endPnt) => { t2 = Math.max(Math.min(t2, 1), 0); const [tp, t22] = [1 - t2, t2 * t2]; const t3 = t22 * t2; const tp2 = tp * tp; const tp3 = tp2 * tp; const x = tp3 * startPnt[0] + 3 * tp2 * t2 * cPnt1[0] + 3 * tp * t22 * cPnt2[0] + t3 * endPnt[0]; const y = tp3 * startPnt[1] + 3 * tp2 * t2 * cPnt1[1] + 3 * tp * t22 * cPnt2[1] + t3 * endPnt[1]; return [x, y]; }; const getThirdPoint = (startPnt, endPnt, angle, distance, clockWise) => { const azimuth = getAzimuth(startPnt, endPnt); const alpha = clockWise ? azimuth + angle : azimuth - angle; const dx = distance * Math.cos(alpha); const dy = distance * Math.sin(alpha); return [endPnt[0] + dx, endPnt[1] + dy]; }; const getArcPoints = (center, radius, startAngle, endAngle) => { let [x, y, pnts, angleDiff] = [0, 0, [], endAngle - startAngle]; angleDiff = angleDiff < 0 ? angleDiff + Math.PI * 2 : angleDiff; for (let i = 0; i <= 100; i++) { const angle = startAngle + angleDiff * i / 100; x = center[0] + radius * Math.cos(angle); y = center[1] + radius * Math.sin(angle); pnts.push([x, y]); } return pnts; }; const getBisectorNormals = (t2, pnt1, pnt2, pnt3) => { const normal = getNormal(pnt1, pnt2, pnt3); let [bisectorNormalRight, bisectorNormalLeft, dt, x, y] = [ [0, 0], [0, 0], 0, 0, 0 ]; const dist = Math.sqrt(normal[0] * normal[0] + normal[1] * normal[1]); const uX = normal[0] / dist; const uY = normal[1] / dist; const d1 = MathDistance(pnt1, pnt2); const d2 = MathDistance(pnt2, pnt3); if (dist > ZERO_TOLERANCE) { if (isClockWise(pnt1, pnt2, pnt3)) { dt = t2 * d1; x = pnt2[0] - dt * uY; y = pnt2[1] + dt * uX; bisectorNormalRight = [x, y]; dt = t2 * d2; x = pnt2[0] + dt * uY; y = pnt2[1] - dt * uX; bisectorNormalLeft = [x, y]; } else { dt = t2 * d1; x = pnt2[0] + dt * uY; y = pnt2[1] - dt * uX; bisectorNormalRight = [x, y]; dt = t2 * d2; x = pnt2[0] - dt * uY; y = pnt2[1] + dt * uX; bisectorNormalLeft = [x, y]; } } else { x = pnt2[0] + t2 * (pnt1[0] - pnt2[0]); y = pnt2[1] + t2 * (pnt1[1] - pnt2[1]); bisectorNormalRight = [x, y]; x = pnt2[0] + t2 * (pnt3[0] - pnt2[0]); y = pnt2[1] + t2 * (pnt3[1] - pnt2[1]); bisectorNormalLeft = [x, y]; } return [bisectorNormalRight, bisectorNormalLeft]; }; const getNormal = (pnt1, pnt2, pnt3) => { let dX1 = pnt1[0] - pnt2[0]; let dY1 = pnt1[1] - pnt2[1]; const d1 = Math.sqrt(dX1 * dX1 + dY1 * dY1); dX1 /= d1; dY1 /= d1; let dX2 = pnt3[0] - pnt2[0]; let dY2 = pnt3[1] - pnt2[1]; const d2 = Math.sqrt(dX2 * dX2 + dY2 * dY2); dX2 /= d2; dY2 /= d2; const uX = dX1 + dX2; const uY = dY1 + dY2; return [uX, uY]; }; const getLeftMostControlPoint = (controlPoints, t2) => { let [pnt1, pnt2, pnt3, controlX, controlY] = [ controlPoints[0], controlPoints[1], controlPoints[2], 0, 0 ]; const pnts = getBisectorNormals(0, pnt1, pnt2, pnt3); const normalRight = pnts[0]; const normal = getNormal(pnt1, pnt2, pnt3); const dist = Math.sqrt(normal[0] * normal[0] + normal[1] * normal[1]); if (dist > ZERO_TOLERANCE) { const mid = Mid(pnt1, pnt2); const pX = pnt1[0] - mid[0]; const pY = pnt1[1] - mid[1]; const d1 = MathDistance(pnt1, pnt2); const n2 = 2 / d1; const nX = -n2 * pY; const nY = n2 * pX; const a11 = nX * nX - nY * nY; const a12 = 2 * nX * nY; const a22 = nY * nY - nX * nX; const dX = normalRight[0] - mid[0]; const dY = normalRight[1] - mid[1]; controlX = mid[0] + a11 * dX + a12 * dY; controlY = mid[1] + a12 * dX + a22 * dY; } else { controlX = pnt1[0] + t2 * (pnt2[0] - pnt1[0]); controlY = pnt1[1] + t2 * (pnt2[1] - pnt1[1]); } return [controlX, controlY]; }; const getRightMostControlPoint = (controlPoints, t2) => { const count = controlPoints.length; const pnt1 = controlPoints[count - 3]; const pnt2 = controlPoints[count - 2]; const pnt3 = controlPoints[count - 1]; const pnts = getBisectorNormals(0, pnt1, pnt2, pnt3); const normalLeft = pnts[1]; const normal = getNormal(pnt1, pnt2, pnt3); const dist = Math.sqrt(normal[0] * normal[0] + normal[1] * normal[1]); let [controlX, controlY] = [0, 0]; if (dist > ZERO_TOLERANCE) { const mid = Mid(pnt2, pnt3); const pX = pnt3[0] - mid[0]; const pY = pnt3[1] - mid[1]; const d1 = MathDistance(pnt2, pnt3); const n2 = 2 / d1; const nX = -n2 * pY; const nY = n2 * pX; const a11 = nX * nX - nY * nY; const a12 = 2 * nX * nY; const a22 = nY * nY - nX * nX; const dX = normalLeft[0] - mid[0]; const dY = normalLeft[1] - mid[1]; controlX = mid[0] + a11 * dX + a12 * dY; controlY = mid[1] + a12 * dX + a22 * dY; } else { controlX = pnt3[0] + t2 * (pnt2[0] - pnt3[0]); controlY = pnt3[1] + t2 * (pnt2[1] - pnt3[1]); } return [controlX, controlY]; }; const getCurvePoints = (t2, controlPoints) => { const leftControl = getLeftMostControlPoint(controlPoints, t2); let [pnt1, pnt2, pnt3, normals] = [null, null, null, [leftControl]]; const points = []; for (let i = 0; i < controlPoints.length - 2; i++) { [pnt1, pnt2, pnt3] = [controlPoints[i], controlPoints[i + 1], controlPoints[i + 2]]; const normalPoints = getBisectorNormals(t2, pnt1, pnt2, pnt3); normals = normals.concat(normalPoints); } const rightControl = getRightMostControlPoint(controlPoints, t2); if (rightControl) { normals.push(rightControl); } for (let i = 0; i < controlPoints.length - 1; i++) { pnt1 = controlPoints[i]; pnt2 = controlPoints[i + 1]; points.push(pnt1); for (let j = 0; j < FITTING_COUNT; j++) { const pnt = getCubicValue(j / FITTING_COUNT, pnt1, normals[i * 2], normals[i * 2 + 1], pnt2); points.push(pnt); } points.push(pnt2); } return points; }; const getBezierPoints = function(points) { if (points.length <= 2) { return points; } const bezierPoints = []; const n2 = points.length - 1; for (let t2 = 0; t2 <= 1; t2 += 0.01) { let [x, y] = [0, 0]; for (let index2 = 0; index2 <= n2; index2++) { const factor = getBinomialFactor(n2, index2); const a = t2 ** index2; const b = (1 - t2) ** (n2 - index2); x += factor * a * b * points[index2][0]; y += factor * a * b * points[index2][1]; } bezierPoints.push([x, y]); } bezierPoints.push(points[n2]); return bezierPoints; }; const getFactorial = (n2) => { let result = 1; switch (true) { case n2 <= 1: result = 1; break; case n2 === 2: result = 2; break; case n2 === 3: result = 6; break; case n2 === 24: result = 24; break; case n2 === 5: result = 120; break; default: for (let i = 1; i <= n2; i++) { result *= i; } break; } return result; }; const getBinomialFactor = (n2, index2) => getFactorial(n2) / (getFactorial(index2) * getFactorial(n2 - index2)); const getQBSplinePoints = (points) => { if (points.length <= 2) { return points; } const [n2, bSplinePoints] = [2, []]; const m = points.length - n2 - 1; bSplinePoints.push(points[0]); for (let i = 0; i <= m; i++) { for (let t2 = 0; t2 <= 1; t2 += 0.05) { let [x, y] = [0, 0]; for (let k = 0; k <= n2; k++) { const factor = getQuadricBSplineFactor(k, t2); x += factor * points[i + k][0]; y += factor * points[i + k][1]; } bSplinePoints.push([x, y]); } } bSplinePoints.push(points[points.length - 1]); return bSplinePoints; }; const getQuadricBSplineFactor = (k, t2) => { let res = 0; if (k === 0) { res = (t2 - 1) ** 2 / 2; } else if (k === 1) { res = (-2 * t2 ** 2 + 2 * t2 + 1) / 2; } else if (k === 2) { res = t2 ** 2 / 2; } return res; }; function getuuid(noBit = false) { function b(a) { return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e7] + -[1e3] + -4e3 + -8e3 + -1e11).replace(/[018]/g, b); } return noBit ? b().replace(/-/g, "") : b(); } const isObject = (value) => { const type = typeof value; return value !== null && (type === "object" || type === "function"); }; const merge = (a, b) => { for (const key in b) { if (isObject(b[key]) && isObject(a[key])) { merge(a[key], b[key]); } else { a[key] = b[key]; } } return a; }; function bindAll(fns, context) { fns.forEach((fn) => { if (!context[fn]) { return; } context[fn] = context[fn].bind(context); }); } const getLayerByLayerName = function(map, layerName) { try { let targetLayer = null; if (map) { const layers = map.getLayers().getArray(); targetLayer = getLayerInternal(layers, "layerName", layerName); } return targetLayer; } catch (e2) { console.log(e2); return null; } }; const getLayerInternal = function(layers, key, value) { let _target = null; if (layers.length > 0) { layers.every((layer) => { if (layer instanceof Group) { const ly = layer.getLayers().getArray(); _target = getLayerInternal(ly, key, value); return !_target; } if (layer.get(key) === value) { _target = layer; return false; } return true; }); } return _target; }; const createVectorLayer = function(map, layerName, params) { try { if (map) { let vectorLayer = getLayerByLayerName(map, layerName); if (!(vectorLayer instanceof Vector)) { vectorLayer = null; } if (!vectorLayer) { if (params && params.create) { vectorLayer = new Vector({ // @ts-ignore this is unsafe layerName, params, layerType: "vector", source: new Vector$1({ wrapX: false }), style: new Style({ fill: new Fill({ color: "rgba(67, 110, 238, 0.4)" }), stroke: new Stroke({ color: "#4781d9", width: 2 }), image: new Circle$2({ radius: 7, fill: new Fill({ color: "#ffcc33" }) }) }) }); } } if (map && vectorLayer) { if (params && params.hasOwnProperty("selectable")) { vectorLayer.set("selectable", params.selectable); } const _vectorLayer = getLayerByLayerName(map, layerName); if (!_vectorLayer || !(_vectorLayer instanceof Vector)) { map.addLayer(vectorLayer); } } return vectorLayer; } } catch (e2) { console.error(e2); } }; var PlotTypes = /* @__PURE__ */ ((PlotTypes2) => { PlotTypes2["TEXTAREA"] = "TextArea"; PlotTypes2["ARC"] = "Arc"; PlotTypes2["CURVE"] = "Curve"; PlotTypes2["GATHERING_PLACE"] = "GatheringPlace"; PlotTypes2["POLYLINE"] = "Polyline"; PlotTypes2["FREEHANDLINE"] = "FreeHandLine"; PlotTypes2["POINT"] = "Point"; PlotTypes2["PENNANT"] = "Pennant"; PlotTypes2["RECTANGLE"] = "RectAngle"; PlotTypes2["CIRCLE"] = "Circle"; PlotTypes2["ELLIPSE"] = "Ellipse"; PlotTypes2["LUNE"] = "Lune"; PlotTypes2["SECTOR"] = "Sector"; PlotTypes2["CLOSED_CURVE"] = "ClosedCurve"; PlotTypes2["POLYGON"] = "Polygon"; PlotTypes2["FREE_POLYGON"] = "FreePolygon"; PlotTypes2["ATTACK_ARROW"] = "AttackArrow"; PlotTypes2["DOUBLE_ARROW"] = "DoubleArrow"; PlotTypes2["STRAIGHT_ARROW"] = "StraightArrow"; PlotTypes2["FINE_ARROW"] = "FineArrow"; PlotTypes2["ASSAULT_DIRECTION"] = "AssaultDirection"; PlotTypes2["TAILED_SQUAD_COMBAT"] = "TailedSquadCombat"; PlotTypes2["TAILED_ATTACK_ARROW"] = "TailedAttackArrow"; PlotTypes2["SQUAD_COMBAT"] = "SquadCombat"; PlotTypes2["RECTFLAG"] = "RectFlag"; PlotTypes2["TRIANGLEFLAG"] = "TriangleFlag"; PlotTypes2["CURVEFLAG"] = "CurveFlag"; PlotTypes2["RECTINCLINED1"] = "RectInclined1"; PlotTypes2["RECTINCLINED2"] = "RectInclined2"; return PlotTypes2; })(PlotTypes || {}); var e = /* @__PURE__ */ new Map(); function t(t2) { var o2 = e.get(t2); o2 && o2.destroy(); } function o(t2) { var o2 = e.get(t2); o2 && o2.update(); } var r = null; "undefined" == typeof window ? ((r = function(e2) { return e2; }).destroy = function(e2) { return e2; }, r.update = function(e2) { return e2; }) : ((r = function(t2, o2) { return t2 && Array.prototype.forEach.call(t2.length ? t2 : [t2], function(t3) { return function(t4) { if (t4 && t4.nodeName && "TEXTAREA" === t4.nodeName && !e.has(t4)) { var o3, r2 = null, n2 = window.getComputedStyle(t4), i = (o3 = t4.value, function() { a({ testForHeightReduction: "" === o3 || !t4.value.startsWith(o3), restoreTextAlign: null }), o3 = t4.value; }), l = (function(o4) { t4.removeEventListener("autosize:destroy", l), t4.removeEventListener("autosize:update", s), t4.removeEventListener("input", i), window.removeEventListener("resize", s), Object.keys(o4).forEach(function(e2) { return t4.style[e2] = o4[e2]; }), e.delete(t4); }).bind(t4, { height: t4.style.height, resize: t4.style.resize, textAlign: t4.style.textAlign, overflowY: t4.style.overflowY, overflowX: t4.style.overflowX, wordWrap: t4.style.wordWrap }); t4.addEventListener("autosize:destroy", l), t4.addEventListener("autosize:update", s), t4.addEventListener("input", i), window.addEventListener("resize", s), t4.style.overflowX = "hidden", t4.style.wordWrap = "break-word", e.set(t4, { destroy: l, update: s }), s(); } function a(e2) { var o4, i2, l2 = e2.restoreTextAlign, s2 = void 0 === l2 ? null : l2, d = e2.testForHeightReduction, u = void 0 === d || d, c = n2.overflowY; if (0 !== t4.scrollHeight && ("vertical" === n2.resize ? t4.style.resize = "none" : "both" === n2.resize && (t4.style.resize = "horizontal"), u && (o4 = function(e3) { for (var t5 = []; e3 && e3.parentNode && e3.parentNode instanceof Element; ) e3.parentNode.scrollTop && t5.push([e3.parentNode, e3.parentNode.scrollTop]), e3 = e3.parentNode; return function() { return t5.forEach(function(e4) { var t6 = e4[0], o5 = e4[1]; t6.style.scrollBehavior = "auto", t6.scrollTop = o5, t6.style.scrollBehavior = null; }); }; }(t4), t4.style.height = ""), i2 = "content-box" === n2.boxSizing ? t4.scrollHeight - (parseFloat(n2.paddingTop) + parseFloat(n2.paddingBottom)) : t4.scrollHeight + parseFloat(n2.borderTopWidth) + parseFloat(n2.borderBottomWidth), "none" !== n2.maxHeight && i2 > parseFloat(n2.maxHeight) ? ("hidden" === n2.overflowY && (t4.style.overflow = "scroll"), i2 = parseFloat(n2.maxHeight)) : "hidden" !== n2.overflowY && (t4.style.overflow = "hidden"), t4.style.height = i2 + "px", s2 && (t4.style.textAlign = s2), o4 && o4(), r2 !== i2 && (t4.dispatchEvent(new Event("autosize:resized", { bubbles: true })), r2 = i2), c !== n2.overflow && !s2)) { var v = n2.textAlign; "hidden" === n2.overflow && (t4.style.textAlign = "start" === v ? "end" : "start"), a({ restoreTextAlign: v, testForHeightReduction: true }); } } function s() { a({ testForHeightReduction: true, restoreTextAlign: null }); } }(t3); }), t2; }).destroy = function(e2) { return e2 && Array.prototype.forEach.call(e2.length ? e2 : [e2], t), e2; }, r.update = function(e2) { return e2 && Array.prototype.forEach.call(e2.length ? e2 : [e2], o), e2; }); var n = r; const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g; const MOZ_HACK_REGEXP = /^moz([A-Z])/; const create = function(tagName, className, container, id) { const el = document.createElement(tagName); el.className = className || ""; if (id) { el.id = id; } if (container) { container.appendChild(el); } return el; }; const getElement = function(id) { return typeof id === "string" ? document.getElementById(id) : id; }; const remove = function(el, p) { const parent = el.parentNode; if (parent) { parent.removeChild(el); } }; const createHidden = function(tagName, parent, id) { const element = document.createElement(tagName); element.style.display = "none"; if (id) { element.id = id; } if (parent) { parent.appendChild(element); } return element; }; const camelCase = function(name) { return name.replace(SPECIAL_CHARS_REGEXP, (_, separator, letter, offset) => offset ? letter.toUpperCase() : letter).replace(MOZ_HACK_REGEXP, "Moz$1"); }; const on = function() { if (document) { return function(element, event, handler) { if (element && event && handler) { element.addEventListener(event, handler, false); } }; } }(); const off = function() { if (document) { return function(element, event, handler) { if (element && event) { element.removeEventListener(event, handler, false); } }; } }(); function hasClass(el, cls) { if (!el || !cls) return false; if (cls.indexOf(" ") !== -1) throw new Error("className should not contain space."); if (el.classList) { return el.classList.contains(cls); } return ` ${el.className} `.indexOf(` ${cls} `) > -1; } function getStyle(element, styleName) { var _a; if (!element || !styleName) return null; styleName = camelCase(styleName); if (styleName === "float") { styleName = "cssFloat"; } try { const computed = (_a = document.defaultView) == null ? void 0 : _a.getComputedStyle(element, ""); return element.style[styleName] || computed ? computed == null ? void 0 : computed[styleName] : null; } catch (e2) { return element.style[styleName]; } } function setStyle(element, styleName, value) { if (!element || !styleName) return; if (typeof styleName === "object") { for (const prop in styleName) { if (styleName.hasOwnProperty(prop)) { setStyle(element, prop, styleName[prop]); } } } else { styleName = camelCase(styleName); if (styleName === "opacity") { element.style.filter = isNaN(value) ? "" : `alpha(opacity=${value * 100})`; } else { element.style[styleName] = value; } } } class PlotEvent extends BaseEvent { constructor(type, params = {}) { super(type); Object.keys(params).forEach((key) => { this[key] = params[key]; }); } } class PlotTextBox extends Overlay { // eslint-disable-next-line default-param-last constructor(options = {}, parent) { const [ id, element, offset, stopEvent, positioning, insertFirst, autoPan, autoPanAnimation, autoPanMargin, className ] = [ options.id, options.element, options.offset, options.stopEvent, options.positioning, options.insertFirst, options.autoPan, options.autoPanAnimation, options.autoPanMargin, options.className ? options.className : "ol-plot-text-editor" ]; super({ id, element, stopEvent, insertFirst, autoPan, autoPanAnimation, autoPanMargin, className }); this.parent = parent; this.setOffset(offset !== void 0 ? offset : [0, 0]); this.setPositioning(positioning !== void 0 ? positioning : "center-center"); this.mapDragPan = void 0; this.isClick_ = false; this.dragging_ = false; this.isFocus_ = false; this.options_ = options; this._position = options.position && options.position.length > 0 ? options.position : []; this.handleTimer_ = null; this.currentPixel_ = []; this.freehand = false; bindAll( [ "handleFocus_", "handleBlur_", "handleClick_", "handleDragStart_", "handleDragEnd_", "handleDragDrag_", "closeCurrentPlotText", "handleResizeMouseDown_", "handleResizeMouseMove_", "handleResizeMouseUp_", "resizeButtonMoveHandler_" ], this ); this.createTextContent(options); } /** * 创建文本框父容器 * @param options */ createTextContent(options) { const _className = options.className || "ol-plot-text-editor"; const content = document.createElement("textarea"); content.className = _className; content.style.width = `${options.width}px`; content.style.height = `${options.height}px`; content.style.minHeight = `${options.minHeight}px`; content.setAttribute("id", options.id); content.setAttribute("autofocus", true); n(content); on(content, "focus", this.handleFocus_); on(content, "blur", this.handleBlur_); on(content, "click", this.handleClick_); on(content, "mousedown", this.handleDragStart_); on(window, "mouseup", this.handleDragEnd_); this.set("isPlotText", true); this.setElement(content); this.createCloseButton(options); this.createResizeButton(options); this.setPosition(this._position); this.dispatchEvent( new PlotEvent("textBoxDrawEnd", { overlay: this, element: content, uuid: options.id }) ); } /** * 获取文本框 * @returns {string} * @private */ getTextAreaFromContent_() { let _node = ""; const childrens_ = Array.prototype.slice.call(this.element && this.element.children, 0); if (childrens_.length > 0) { childrens_.every((ele) => { if (ele.nodeType === 1 && ele.nodeName.toLowerCase() === "textarea") { _node = ele; return false; } return true; }); } return _node; } /** * 创建关闭按钮 * @param options */ createCloseButton(options) { const _closeSpan = document.createElement("span"); _closeSpan.className = "ol-plot-text-editor-close"; _closeSpan.setAttribute("data-id", options.id); off(_closeSpan, "click", this.closeCurrentPlotText); on(_closeSpan, "click", this.closeCurrentPlotText); this.element.appendChild(_closeSpan); } /** * 创建文本框大小调整按钮 * @param options */ createResizeButton(options) { const _resizeSpan = document.createElement("span"); _resizeSpan.className = "ol-plot-text-editor-resize"; _resizeSpan.setAttribute("data-id", options.id); off(_resizeSpan, "mousedown", this.handleResizeMouseDown_); off(_resizeSpan, "mousemove", this.handleResizeMouseMove_); on(_resizeSpan, "mousedown", this.handleResizeMouseDown_); on(_resizeSpan, "mousemove", this.handleResizeMouseMove_); this.element.appendChild(_resizeSpan); } /** * 调整大小 * @param event * @private */ resizeButtonMoveHandler_(event) { const pixel_ = event.pixel; const element_ = this.getTextAreaFromContent_(); if (pixel_.length < 1 || this.currentPixel_.length < 1 || !element_) return; const _offset = [pixel_[0] - this.currentPixel_[0], pixel_[1] - this.currentPixel_[1]]; const _size = [element_.offsetWidth, element_.offsetHeight]; const _width = _size[0] + _offset[0] * 2; const _height = _size[1] + _offset[1] * 2; setStyle(element_, "width", `${_width}px`); setStyle(element_, "height", `${_height}px`); this.currentPixel_ = pixel_; this.getMap().render(); } /** * 处理移动事件 * @param event * @private */ handleResizeMouseMove_(event) { event.stopImmediatePropagation(); } /** * 处理鼠标按下事件 * @param event * @private */ handleResizeMouseDown_(event) { if (!this.getMap()) return; this.currentPixel_ = [event.x, event.y]; this.getMap().on("pointermove", this.resizeButtonMoveHandler_); on(this.getMap().getViewport(), "mouseup", this.handleResizeMouseUp_); } /** * 处理鼠标抬起事件,移除所有事件监听 * @private */ handleResizeMouseUp_() { if (!this.getMap()) return; this.getMap().un("pointermove", this.resizeButtonMoveHandler_); off(this.getMap().getViewport(), "mouseup", this.handleResizeMouseUp_); this.currentPixel_ = []; } /** * 处理关闭事件 * @param event */ closeCurrentPlotText(event) { if (!this.getMap()) return; if (event && hasClass(event.target, "ol-plot-text-editor-close")) { const _id = event.target.getAttribute("data-id"); if (_id) { const _overlay = this.getMap().getOverlayById(_id); if (_overlay) { this.getMap().removeOverlay(_overlay); } } } } /** * 处理获取焦点事件 * @private */ handleFocus_() { this.isFocus_ = true; if (this.parent) { this.parent.dispatchEvent( new PlotEvent("activeTextArea", { overlay: this }) ); } } /** * 处理失去焦点事件 * @private */ handleBlur_() { this.isFocus_ = false; if (this.parent) { this.parent.dispatchEvent( new PlotEvent("deactivateTextArea", { overlay: this }) ); } } /** * 处理拖拽开始 * @private */ handleDragStart_() { if (!this.getMap()) return; if (!this.dragging_ && this.isMoveModel() && this.isFocus_) { this.handleTimer_ = window.setTimeout(() => { window.clearTimeout(this.handleTimer_); this.handleTimer_ = null; if (!this.isClick_) { this.dragging_ = true; this.disableMapDragPan(); this.preCursor_ = this.element.style.cursor; on(this.getMap().getViewport(), "mousemove", this.handleDragDrag_); on(this.element, "mouseup", this.handleDragEnd_); } }, 300); } } /** * 处理拖拽 * @param event * @private */ handleDragDrag_(event) { if (this.dragging_) { this.element.style.cursor = "move"; this._position = this.getMap().getCoordinateFromPixel([event.clientX, event.clientY]); this.setPosition(this._position); } } /** * 处理拖拽 * @private */ handleDragEnd_() { this.isClick_ = false; window.clearTimeout(this.handleTimer_); this.handleTimer_ = null; if (this.dragging_ && this.isFocus_) { this.dragging_ = false; this.enableMapDragPan(); this.element.style.cursor = this.preCursor_; off(this.getMap().getViewport(), "mousemove", this.handleDragDrag_); off(this.element, "mouseup", this.handleDragEnd_); } } /** * 处理点击事件 * @param event * @private */ handleClick_(event) { if (event.target === this.element) { this.isClick_ = true; } else { this.isClick_ = false; } } /** * 是否处于选择模式 * @returns {boolean} */ isMoveModel() { if (!window) return false; try { const selection = window.getSelection(); if (selection) { const range = window.getSelection().getRangeAt(0); return range.collapsed; } return false; } catch (e2) { console.error("[ol-plot]: PlotTextBox check move error", e2); } } /** * 设置样式 * @param style */ setStyle(style = {}) { const _element = this.getTextAreaFromContent_(); if (_element) { for (const key in style) { if (style[key]) { setStyle(_element, key, style[key]); } } } } /** * 获取当前样式 * @returns {CSSStyleDeclaration} */ getStyle() { const _style = {}; const _element = this.getTextAreaFromContent_(); if (_element) { for (const key in DEF_TEXT_STYEL) { _style[key] = getStyle(_element, key); } } return _style; } /** * set value * @param value */ setValue(value) { const _element = this.getTextAreaFromContent_(); if (_element) { _element.value = value; if (value) { n.update(_element); } this.getMap().render(); } } /** * get value * @returns {*} */ getValue() { const _element = this.getTextAreaFromContent_(); if (_element) { return _element.value; } return ""; } /** * 获取宽度 * @returns {number} */ getWidth() { const element_ = this.getTextAreaFromContent_(); if (element_ && element_.offsetWidth) { return element_.offsetWidth; } return 0; } /** * 获取高度 * @returns {number} */ getHeight() { const element_ = this.getTextAreaFromContent_(); if (element_ && element_.offsetHeight) { return element_.offsetHeight; } return 0; } /** * 激活地图的拖拽平移 */ enableMapDragPan() { const _map = this.getMap(); if (!_map) return; if (this.mapDragPan) { _map.addInteraction(this.mapDragPan); delete this.mapDragPan; } } /** * 禁止地图的拖拽平移 */ disableMapDragPan() { const _map = this.getMap(); if (!_map) return; const interactions = _map.getInteractions().getArray(); interactions.every((item) => { if (item instanceof DragPan || item.constructor.name.indexOf("DragPan") > -1) { this.mapDragPan = item; _map.removeInteraction(item); return false; } return true; }); } /** * set map * @param map */ setMap(map) { super.setMap(map); if (map && map instanceof Map$1) { this.setStyle(merge(DEF_TEXT_STYEL, this.options_.style)); this.setValue(this.options_.value); } } finishDrawing() { } } const PlotTextBox$1 = PlotTextBox; class Point extends Point$2 { constructor(coordinates, point, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); __publicField(this, "options"); this.type = PlotTypes.POINT; this.options = params || {}; this.freehand = false; this.set("params", this.options); this.fixPointCount = 1; if (point && point.length > 0) { this.setPoints(point); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } generate() { const pnt = this.points[0]; this.setCoordinates(pnt); } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {{}|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Point$1 = Point; class Pennant extends Point$2 { constructor(coordinates, point, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); __publicField(this, "options"); this.type = PlotTypes.PENNANT; this.options = params || {}; this.freehand = false; this.fixPointCount = void 0; this.set("params", this.options); if (point && point.length > 0) { this.setPoints(point); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } generate() { this.setCoordinates(this.points); } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {{}|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Pennant$1 = Pennant; class Polyline extends LineString { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); this.type = PlotTypes.POLYLINE; this.freehand = false; this.set("params", params); if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } /** * 执行动作 */ generate() { this.setCoordinates(this.points); } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {ol.Map|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Polyline$1 = Polyline; class Arc extends LineString { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "freehand"); __publicField(this, "map"); __publicField(this, "points"); this.type = PlotTypes.ARC; this.fixPointCount = 3; this.set("params", params); if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } /** * 执行动作 */ generate() { const count = this.getPointCount(); if (count < 2) return; if (count === 2) { this.setCoordinates(this.points); } else { let [pnt1, pnt2, pnt3, startAngle, endAngle] = [this.points[0], this.points[1], this.points[2], 0, 0]; const center = getCircleCenterOfThreePoints(pnt1, pnt2, pnt3); const radius = MathDistance(pnt1, center); const angle1 = getAzimuth(pnt1, center); const angle2 = getAzimuth(pnt2, center); if (isClockWise(pnt1, pnt2, pnt3)) { startAngle = angle2; endAngle = angle1; } else { startAngle = angle1; endAngle = angle2; } this.setCoordinates(getArcPoints(center, radius, startAngle, endAngle)); } } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {ol.Map|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Arc$1 = Arc; class Circle extends Polygon$2 { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); this.type = PlotTypes.CIRCLE; this.fixPointCount = 2; this.set("params", params); if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } generate() { const count = this.getPointCount(); if (count < 2) { return false; } const center = this.points[0]; const radius = MathDistance(center, this.points[1]); this.setCoordinates([this.generatePoints(center, radius)]); } /** * 对圆边线进行插值 * @param center * @param radius * @returns {null} */ generatePoints(center, radius) { let [x, y, angle] = [0, 0, 0]; const points = []; for (let i = 0; i <= 100; i++) { angle = Math.PI * 2 * i / 100; x = center[0] + radius * Math.cos(angle); y = center[1] + radius * Math.sin(angle); points.push([x, y]); } return points; } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {{}|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Circle$1 = Circle; class Curve extends LineString { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); __publicField(this, "t"); this.type = PlotTypes.CURVE; this.t = 0.3; this.set("params", params); if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } /** * 执行动作 */ generate() { const count = this.getPointCount(); if (count < 2) { return false; } if (count === 2) { this.setCoordinates(this.points); } else { const points = getCurvePoints(this.t, this.points); this.setCoordinates(points); } } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {ol.Map|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const Curve$1 = Curve; class FreeHandLine extends LineString { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); this.type = PlotTypes.FREEHANDLINE; this.freehand = true; this.set("params", params); if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } /** * 执行动作 */ generate() { this.setCoordinates(this.points); } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {ol.Map|*} */ getMap() { return this.map; } /** * 判断是否是Plot * @returns {boolean} */ isPlot() { return true; } /** * 设置坐标点 * @param value */ setPoints(value) { this.points = !value ? [] : value; if (this.points.length >= 1) { this.generate(); } } /** * 获取坐标点 * @returns {Array.<T>} */ getPoints() { return this.points.slice(0); } /** * 获取点数量 * @returns {Number} */ getPointCount() { return this.points.length; } /** * 更新当前坐标 * @param point * @param index */ updatePoint(point, index2) { if (index2 >= 0 && index2 < this.points.length) { this.points[index2] = point; this.generate(); } } /** * 更新最后一个坐标 * @param point */ updateLastPoint(point) { this.updatePoint(point, this.points.length - 1); } /** * 结束绘制 */ finishDrawing() { } } const FreeHandLine$1 = FreeHandLine; class RectAngle extends Polygon$2 { constructor(coordinates, points, params) { super([]); __publicField(this, "type"); __publicField(this, "fixPointCount"); __publicField(this, "map"); __publicField(this, "points"); __publicField(this, "freehand"); __publicField(this, "isFill"); this.type = PlotTypes.RECTANGLE; this.fixPointCount = 2; this.set("params", params); this.isFill = params.isFill === false ? params.isFill : true; if (points && points.length > 0) { this.setPoints(points); } else if (coordinates && coordinates.length > 0) { this.setCoordinates(coordinates); } } /** * 获取标绘类型 * @returns {*} */ getPlotType() { return this.type; } /** * 执行动作 */ generate() { if (this.points.length === 2) { let coordinates; if (this.isFill) { const extent = boundingExtent(this.points); const polygon = fromExtent(extent); coordinates = polygon.getCoordinates(); } else { const start = this.points[0]; const end = this.points[1]; coordinates = [start, [start[0], end[1]], end, [end[0], start[1]], start]; } this.setCoordinates(coordinates); } } /** * 设置地图对象 * @param map */ setMap(map) { if (map && map instanceof Map$1) { this.map = map; } else { throw new Error("传入的不是地图对象!"); } } /** * 获取当前地图对象 * @returns {Map|*} */ getMap() {