Leaflet 军事标绘 复杂图形 实现

打印 上一主题 下一主题

主题 1523|帖子 1523|积分 4569

需求

看到别的公司做的要图标绘,我们也想做一个,以是我就研究一下怎么实现。
像打击方向、钳击、聚集地这些,网上已有大佬开源,我之前已集成到我的Demo中。
要图标绘的标号虽然很多,多数都是点状的,相对比较简单。有些线状的比较复杂,如下图所示:

阐明:因为我没有相关的svg图形,使用其它svg图形拼凑的,图形本身是个四不像,后面只要换一下svg图形就行了。
这篇文章主要讲解一下,我是怎样实现的。
实现原理


  • 样条曲线
    为什么是样条曲线而不是二次或三次贝塞尔曲线呢?因为不确定绘制几个点。
    我的算法基础比较弱,以前我只能上网搜索开源代码,现在直接问DeepSeek就可以了,我让它封装成js方法,这种经典算法,它给的封装好的js方法可以正确运行。
  • svg图形
    曲线上的图形,通过svg实现。项目中用到的标号,也是通过svg格式提供的。
  • svg图形的旋转角度
    接下来最关键的,就是svg图形的旋转角度,这个算法,问DeepSeek不太好问,它也很难一次性给出正确的代码,以是主要是自己写。
样条曲线算法

样条曲线算法
  1. /**
  2. * 获取样条插值曲线点的坐标
  3. * @param {Array} points - 输入的坐标点数组,格式为 [[number, number], ...]
  4. * @param {number} numSegments - 每两个原始点之间的曲线分段数
  5. * @returns {Array} 平滑曲线的坐标点数组
  6. */
  7. L.PlotUtils.getSplineCurve = function (points, numSegments = 25) {
  8.     if (points.length < 2) return points.slice();
  9.     // 扩展点数组处理边界情况
  10.     const extendedPoints = [
  11.         points[1],          // 添加第二个点作为起始虚拟点
  12.         ...points,          // 原始点
  13.         points[points.length - 2] // 添加倒数第二个点作为结束虚拟点
  14.     ];
  15.     const curvePoints = [];
  16.     // 遍历每个中间段生成曲线
  17.     for (let i = 1; i <= extendedPoints.length - 3; i++) {
  18.         const p0 = extendedPoints[i - 1];
  19.         const p1 = extendedPoints[i];
  20.         const p2 = extendedPoints[i + 1];
  21.         const p3 = extendedPoints[i + 2];
  22.         // 生成当前段的曲线点
  23.         for (let t = 0; t < 1; t += 1 / numSegments) {
  24.             const t2 = t * t;
  25.             const t3 = t2 * t;
  26.             // Catmull-Rom样条插值公式
  27.             const x = 0.5 * (
  28.                 (2 * p1[0]) +
  29.                 (-p0[0] + p2[0]) * t +
  30.                 (2 * p0[0] - 5 * p1[0] + 4 * p2[0] - p3[0]) * t2 +
  31.                 (-p0[0] + 3 * p1[0] - 3 * p2[0] + p3[0]) * t3
  32.             );
  33.             const y = 0.5 * (
  34.                 (2 * p1[1]) +
  35.                 (-p0[1] + p2[1]) * t +
  36.                 (2 * p0[1] - 5 * p1[1] + 4 * p2[1] - p3[1]) * t2 +
  37.                 (-p0[1] + 3 * p1[1] - 3 * p2[1] + p3[1]) * t3
  38.             );
  39.             curvePoints.push({ x, y });
  40.         }
  41.     }
  42.     // 确保包含最后一个原始点
  43.     let lastPoint = points[points.length - 1];
  44.     curvePoints.push({ x: lastPoint[0], y: lastPoint[1] });
  45.     return curvePoints;
  46. }
复制代码
判断三点构成的曲线弯曲方向

如上图所示,圆圈需要根据曲线弯曲方向调整到曲线的一侧
  1. /**
  2. * 计算样条曲线在指定百分比位置的坐标及切线向量
  3. * @param {Array} points - 原始坐标点数组,格式 [{x: number, y: number}, ...]
  4. * @param {number} t - 曲线位置百分比参数,取值范围 [0, 1]
  5. * @returns {Object} 包含坐标和切线的对象 {x, y, dx, dy}
  6. */
  7. L.PlotUtils.getSplineCurvePointAndTangent = function (points, t) {
  8.     if (points.length < 2) return { x: 0, y: 0, dx: 0, dy: 0 };
  9.     // 按曲线总长度的百分比
  10.     let tR;
  11.     if (t == 0 || t == 1) {
  12.         tR = t;
  13.     }
  14.     else {
  15.         let points2 = [];
  16.         for (let p of points) {
  17.             points2.push([p.x, p.y]);
  18.         }
  19.         let totalDistance = L.PlotUtils.wholeDistance(points2);
  20.         let sum = 0;
  21.         let index = 0;
  22.         for (let i = 1; i < points2.length; i++) {
  23.             let d = L.PlotUtils.distance(points2[i - 1], points2[i]);
  24.             sum += d;
  25.             if (sum >= totalDistance * t) {
  26.                 index = i;
  27.                 break;
  28.             }
  29.         }
  30.         tR = index / points2.length;
  31.     }
  32.     // 参数约束处理(转换为全局位置)
  33.     const totalSegments = points.length - 1;
  34.     let tGlobal = Math.max(0, Math.min(tR, 1)) * totalSegments;
  35.     tGlobal = Math.min(tGlobal, totalSegments - 1e-9); // 防止超出最后一个点
  36.     // 创建镜像端点解决边界问题
  37.     const first = points[0], last = points[points.length - 1];
  38.     const extended = [
  39.         { x: 2 * first.x - points[1].x, y: 2 * first.y - points[1].y },
  40.         ...points,
  41.         { x: 2 * last.x - points[points.length - 2].x, y: 2 * last.y - points[points.length - 2].y }
  42.     ];
  43.     // 确定当前曲线段
  44.     const segIndex = Math.floor(tGlobal);
  45.     const localT = tGlobal - segIndex;
  46.     // 获取控制点集(调整索引偏移)
  47.     const p0 = extended[segIndex];
  48.     const p1 = extended[segIndex + 1];
  49.     const p2 = extended[segIndex + 2];
  50.     const p3 = extended[segIndex + 3];
  51.     // 计算坐标点
  52.     const t2 = localT * localT;
  53.     const t3 = t2 * localT;
  54.     const x = 0.5 * (
  55.         (2 * p1.x) +
  56.         (-p0.x + p2.x) * localT +
  57.         (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * t2 +
  58.         (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t3
  59.     );
  60.     const y = 0.5 * (
  61.         (2 * p1.y) +
  62.         (-p0.y + p2.y) * localT +
  63.         (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * t2 +
  64.         (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t3
  65.     );
  66.     // 计算切线向量
  67.     const dx = 0.5 * (
  68.         (-p0.x + p2.x) +
  69.         2 * (2 * p0.x - 5 * p1.x + 4 * p2.x - p3.x) * localT +
  70.         3 * (-p0.x + 3 * p1.x - 3 * p2.x + p3.x) * t2
  71.     );
  72.     const dy = 0.5 * (
  73.         (-p0.y + p2.y) +
  74.         2 * (2 * p0.y - 5 * p1.y + 4 * p2.y - p3.y) * localT +
  75.         3 * (-p0.y + 3 * p1.y - 3 * p2.y + p3.y) * t2
  76.     );
  77.     return { x, y, dx, dy };
  78. }
复制代码
svg图形旋转算法

不需要思量曲线弯曲方向的环境
  1. /**
  2. * 判断三点构成的曲线弯曲方向
  3. * @param {Object} A - 起点坐标 [ number, number ]
  4. * @param {Object} B - 中间点坐标 [ number, number ]
  5. * @param {Object} C - 终点坐标 [ number, number ]
  6. * @returns {'left' | 'right' | 'straight'} 弯曲方向
  7. */
  8. L.PlotUtils.determineCurveDirection = function (A, B, C) {
  9.     // 计算向量AB和BC
  10.     const abx = B[0] - A[0];
  11.     const aby = B[1] - A[1];
  12.     const bcx = C[0] - B[0];
  13.     const bcy = C[1] - B[1];
  14.     // 计算叉积 (AB × BC)
  15.     const crossProduct = abx * bcy - aby * bcx;
  16.     // 处理浮点数精度误差(阈值可调整)
  17.     const epsilon = 1e-8;
  18.     if (crossProduct > epsilon) return 'left';    // 逆时针方向
  19.     if (crossProduct < -epsilon) return 'right';  // 顺时针方向
  20.     return 'straight';  // 三点共线
  21. }
复制代码
需要思量曲线弯曲方向的环境
  1. L.Plot.SplineCurve.prototype.getRotation = function (angle, scale, lineWidth) {
  2.     let rotation = Math.atan(Math.abs(angle.dy / angle.dx));
  3.     rotation = 180 * rotation / Math.PI;
  4.     let strokeWidth = lineWidth / scale;
  5.     let transform = "";
  6.     if (angle.dx > 0 && angle.dy > 0) {
  7.         rotation = -rotation;
  8.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  9.     } else if (angle.dx > 0 && angle.dy < 0) {
  10.         rotation = rotation;
  11.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  12.     }
  13.     else if (angle.dx < 0 && angle.dy > 0) {
  14.         rotation = 180 + rotation;
  15.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  16.     }
  17.     else if (angle.dx < 0 && angle.dy < 0) {
  18.         rotation = 180 - rotation;
  19.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  20.     }
  21.     else if (angle.dx == 0) {
  22.         if (angle.dy > 0) {
  23.             rotation = - rotation;
  24.         } else {
  25.             rotation = rotation;
  26.         }
  27.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  28.     }
  29.     else if (angle.dy == 0) { // 只有一个点时角度为0
  30.         rotation = 0;
  31.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  32.     }
  33.     return { rotation, transform, strokeWidth }
  34. }
复制代码
标绘图形封装

基于样条曲线,可以实现多种同类标绘图形,这里实现了三种标绘图形
  1. // 样条曲线L.Plot.SplineCurve = function (points, options) {    this.points = points;    this.options = {        fixPointCount: 6    }    Object.assign(this, options);    this.type = L.PlotTypes.SPLINECURVE;}// 创建样条曲线L.Plot.SplineCurve.prototype.create = function (map, plotLayer) {    this.map = map;    this.plotLayer = plotLayer;    this.map.addEventListener("zoomend", this.mapZoomEnd, this);    let polyline = L.polyline([], { color: this.color, opacity: this.opacity || 1 });    this.plotLayer.addLayer(polyline);    polyline.plot = this;    this.polyline = polyline;    this.layer = polyline;    this.svgMarker = L.marker(this.points[0])    this.svgMarker.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.svgMarker);    this.arrowMarker = L.marker(this.points[0])    this.arrowMarker.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.arrowMarker);    let zoom = this.map.getZoom();    let scale = Math.pow(1.2, (zoom - 14));    this.updateIcons(scale);}// 地图放大缩小L.Plot.SplineCurve.prototype.mapZoomEnd = function (e) {    let zoom = this.map.getZoom();    let scale = Math.pow(1.2, (zoom - 14));    this.updateIcons(scale);}L.Plot.SplineCurve.prototype.setPoints = function (points) {    this.points = points;    if (this.points.length < 2) {        return;    }    let proPoints = L.PlotUtils.proPoints(this.convertLatLngs(this.points));    let pList = L.PlotUtils.getSplineCurve(proPoints);    let latlngs = L.PlotUtils.unProPoints(pList);    this.polyline.setLatLngs(latlngs);    this.svgMarker.setLatLng(L.PlotUtils.unProPoint(pList[0]));    this.arrowMarker.setLatLng(L.PlotUtils.unProPoint(pList[pList.length - 1]));    let zoom = this.map.getZoom();    let scale = Math.pow(1.2, (zoom - 14));    this.updateIcons(scale);}L.Plot.SplineCurve.prototype.convertLatLngs = function (points) {    let pnts = [];    for (let point of points) {        pnts.push({ lat: point[0], lng: point[1] });    }    return pnts;}/**
  2. * 判断三点构成的曲线弯曲方向
  3. * @param {Object} A - 起点坐标 [ number, number ]
  4. * @param {Object} B - 中间点坐标 [ number, number ]
  5. * @param {Object} C - 终点坐标 [ number, number ]
  6. * @returns {'left' | 'right' | 'straight'} 弯曲方向
  7. */
  8. L.PlotUtils.determineCurveDirection = function (A, B, C) {
  9.     // 计算向量AB和BC
  10.     const abx = B[0] - A[0];
  11.     const aby = B[1] - A[1];
  12.     const bcx = C[0] - B[0];
  13.     const bcy = C[1] - B[1];
  14.     // 计算叉积 (AB × BC)
  15.     const crossProduct = abx * bcy - aby * bcx;
  16.     // 处理浮点数精度误差(阈值可调整)
  17.     const epsilon = 1e-8;
  18.     if (crossProduct > epsilon) return 'left';    // 逆时针方向
  19.     if (crossProduct < -epsilon) return 'right';  // 顺时针方向
  20.     return 'straight';  // 三点共线
  21. }L.Plot.SplineCurve.prototype.getRotation = function (angle, scale, lineWidth) {
  22.     let rotation = Math.atan(Math.abs(angle.dy / angle.dx));
  23.     rotation = 180 * rotation / Math.PI;
  24.     let strokeWidth = lineWidth / scale;
  25.     let transform = "";
  26.     if (angle.dx > 0 && angle.dy > 0) {
  27.         rotation = -rotation;
  28.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  29.     } else if (angle.dx > 0 && angle.dy < 0) {
  30.         rotation = rotation;
  31.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  32.     }
  33.     else if (angle.dx < 0 && angle.dy > 0) {
  34.         rotation = 180 + rotation;
  35.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  36.     }
  37.     else if (angle.dx < 0 && angle.dy < 0) {
  38.         rotation = 180 - rotation;
  39.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  40.     }
  41.     else if (angle.dx == 0) {
  42.         if (angle.dy > 0) {
  43.             rotation = - rotation;
  44.         } else {
  45.             rotation = rotation;
  46.         }
  47.         transform = `transform: scale(${scale},${scale}); transform-origin: center right;`;
  48.     }
  49.     else if (angle.dy == 0) { // 只有一个点时角度为0
  50.         rotation = 0;
  51.         transform = `transform: scale(${scale},-${scale}); transform-origin: center right;`;
  52.     }
  53.     return { rotation, transform, strokeWidth }
  54. }L.Plot.SplineCurve.prototype.updateIcons = function (scale) {    let proPoints = L.PlotUtils.proPoints(this.convertLatLngs(this.points));    let pList = L.PlotUtils.getSplineCurve(proPoints);    // 切线    let angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0);    this.updateSvgIcon(angle, scale);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 1);    this.updateArrowMarkerIcon(angle, scale * 0.3);}L.Plot.SplineCurve.prototype.updateSvgIcon = function (angle, scale) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation(angle, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                        `,        className: 'plot-svg-marker',        iconSize: [144, 144],  // 图标显示尺寸        iconAnchor: [72, 72] // 图标锚点位置    });    this.svgMarker.setIcon(svgIcon);    this.svgMarker.setRotationAngle(rotation);}L.Plot.SplineCurve.prototype.updateArrowMarkerIcon = function (angle, scale) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation(angle, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                        `,        className: 'plot-svg-marker',        iconSize: [144, 144],  // 图标显示尺寸        iconAnchor: [72, 72] // 图标锚点位置    });    this.arrowMarker.setIcon(svgIcon);    this.arrowMarker.setRotationAngle(rotation);}L.Plot.SplineCurve.prototype.getPointCount = function () {    return this.points.length;}L.Plot.SplineCurve.prototype.getPoints = function () {    return this.points;}L.Plot.SplineCurve.prototype.finishDrawing = function () { }// 释放资源L.Plot.SplineCurve.prototype.dispose = function (e) {    this.map.removeEventListener("zoomend", this.mapZoomEnd, this); // 注意:添加的时候传了this,移除的时候必需要传this,否则移除不掉}// 样条曲线 子范例1L.Plot.SplineCurveSub1 = function (points, options) {    L.Plot.SplineCurve.call(this); // 调用父类构造函数    this.points = points;    this.options = {        fixPointCount: 6    }    Object.assign(this, options);    this.type = L.PlotTypes.SPLINECURVE_SUB1;}// 继承原型L.Plot.SplineCurveSub1.prototype = Object.create(L.Plot.SplineCurve.prototype);L.Plot.SplineCurveSub1.prototype.constructor = L.Plot.SplineCurveSub1;// 更新图标L.Plot.SplineCurveSub1.prototype.updateIcons = function (scale) {    let proPoints = L.PlotUtils.proPoints(this.convertLatLngs(this.points));    let pList = L.PlotUtils.getSplineCurve(proPoints);    // 切线    let angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0);    this.updateSvgIcon(angle, scale);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 1);    this.updateArrowMarkerIcon(angle, scale * 0.3);}// 更新图标L.Plot.SplineCurveSub1.prototype.updateSvgIcon = function (angle, scale) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation(angle, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                        `,        className: 'plot-svg-marker',        iconSize: [144, 144],  // 图标显示尺寸        iconAnchor: [72, 72] // 图标锚点位置    });    this.svgMarker.setIcon(svgIcon);    this.svgMarker.setRotationAngle(rotation);}// 样条曲线 子范例2L.Plot.SplineCurveSub2 = function (points, options) {    L.Plot.SplineCurve.call(this); // 调用父类构造函数    this.points = points;    this.options = {        fixPointCount: 6    }    Object.assign(this, options);    this.type = L.PlotTypes.SPLINECURVE_SUB2;}// 继承原型L.Plot.SplineCurveSub2.prototype = Object.create(L.Plot.SplineCurve.prototype);L.Plot.SplineCurveSub2.prototype.constructor = L.Plot.SplineCurveSub2;// 更新图标L.Plot.SplineCurveSub2.prototype.updateIcons = function (scale) {    let proPoints = L.PlotUtils.proPoints(this.convertLatLngs(this.points));    let pList = L.PlotUtils.getSplineCurve(proPoints);    // 切线    let angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0);    this.updateSvgIcon(angle, scale);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 1);    this.updateArrowMarkerIcon(angle, scale * 0.3);}// 更新图标L.Plot.SplineCurveSub2.prototype.updateSvgIcon = function (angle, scale) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation(angle, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                                                `,        className: 'plot-svg-marker',        iconSize: [144, 144],  // 图标显示尺寸        iconAnchor: [72, 72] // 图标锚点位置    });    this.svgMarker.setIcon(svgIcon);    this.svgMarker.setRotationAngle(rotation);}// 样条曲线 子范例3L.Plot.SplineCurveSub3 = function (points, options) {    L.Plot.SplineCurve.call(this); // 调用父类构造函数    this.points = points;    this.options = {        fixPointCount: 6    }    Object.assign(this, options);    this.type = L.PlotTypes.SPLINECURVE_SUB3;}// 继承原型L.Plot.SplineCurveSub3.prototype = Object.create(L.Plot.SplineCurve.prototype);L.Plot.SplineCurveSub3.prototype.constructor = L.Plot.SplineCurveSub3;// 创建样条曲线L.Plot.SplineCurveSub3.prototype.create = function (map, plotLayer) {    this.map = map;    this.plotLayer = plotLayer;    this.map.addEventListener("zoomend", this.mapZoomEnd, this);    let polyline = L.polyline([], { color: this.color, opacity: this.opacity || 1 });    this.plotLayer.addLayer(polyline);    polyline.plot = this;    this.polyline = polyline;    this.layer = polyline;    this.svgMarker = L.marker(this.points[0])    this.svgMarker.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.svgMarker);    this.arrowMarker = L.marker(this.points[0])    this.arrowMarker.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.arrowMarker);    this.circleMarker1 = L.marker(this.points[0])    this.circleMarker1.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.circleMarker1);    this.circleMarker2 = L.marker(this.points[0])    this.circleMarker2.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.circleMarker2);    this.marker3 = L.marker(this.points[0])    this.marker3.setRotationOrigin('50% 50%');    this.plotLayer.addLayer(this.marker3);    let zoom = this.map.getZoom();    let scale = Math.pow(1.2, (zoom - 14));    this.updateIcons(scale);}// 更新图标L.Plot.SplineCurveSub3.prototype.updateIcons = function (scale) {    let proPoints = L.PlotUtils.proPoints(this.convertLatLngs(this.points));    let pList = L.PlotUtils.getSplineCurve(proPoints);    // 切线    let angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0);    this.updateSvgIcon(angle, scale);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 1);    this.updateArrowMarkerIcon(angle, scale * 0.3);    let direction = 'straight';    if (proPoints.length >= 3) {        direction = L.PlotUtils.determineCurveDirection(proPoints[proPoints.length - 3], proPoints[proPoints.length - 2], proPoints[proPoints.length - 1]);    }    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0.15);    let lnglat = L.PlotUtils.unProPoint({ x: angle.x, y: angle.y });    this.updateCircleIcon1(angle, direction, scale, lnglat);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0.3);    lnglat = L.PlotUtils.unProPoint({ x: angle.x, y: angle.y });    this.updateCircleIcon2(angle, direction, scale, lnglat);    angle = L.PlotUtils.getSplineCurvePointAndTangent(pList, 0.8);    lnglat = L.PlotUtils.unProPoint({ x: angle.x, y: angle.y });    this.updateIcon3(angle, direction, scale, lnglat);}// 更新图标L.Plot.SplineCurveSub3.prototype.updateSvgIcon = function (angle, scale) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation(angle, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                                                `,        className: 'plot-svg-marker',        iconSize: [144, 144],  // 图标显示尺寸        iconAnchor: [72, 72] // 图标锚点位置    });    this.svgMarker.setIcon(svgIcon);    this.svgMarker.setRotationAngle(rotation);}// 更新图标L.Plot.SplineCurveSub3.prototype.updateCircleIcon1 = function (angle, direction, scale, lnglat) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation2(angle, direction, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                        `,        className: 'plot-svg-marker',        iconSize: [48, 48],  // 图标显示尺寸        iconAnchor: [24, 24] // 图标锚点位置    });    this.circleMarker1.setIcon(svgIcon);    this.circleMarker1.setRotationAngle(rotation);    this.circleMarker1.setLatLng(lnglat);}// 更新图标L.Plot.SplineCurveSub3.prototype.updateCircleIcon2 = function (angle, direction, scale, lnglat) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation2(angle, direction, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                        `,        className: 'plot-svg-marker',        iconSize: [48, 48],  // 图标显示尺寸        iconAnchor: [24, 24] // 图标锚点位置    });    this.circleMarker2.setIcon(svgIcon);    this.circleMarker2.setRotationAngle(rotation);    this.circleMarker2.setLatLng(lnglat);}// 更新图标L.Plot.SplineCurveSub3.prototype.updateIcon3 = function (angle, direction, scale, lnglat) {    let lineWidth = 2;    let { rotation, transform, strokeWidth } = this.getRotation2(angle, direction, scale, lineWidth);    // 显示svg图标    let svgIcon = L.divIcon({        html: `                                                                `,        className: 'plot-svg-marker',        iconSize: [48, 36],  // 图标显示尺寸        iconAnchor: [24, 18] // 图标锚点位置    });    this.marker3.setIcon(svgIcon);    this.marker3.setRotationAngle(rotation);    this.marker3.setLatLng(lnglat);}
复制代码
截图


源码地址

https://gitee.com/s0611163/leaflet-plot

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

飞不高

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表