mapbox-gl-draw 绘制态势标绘-双箭头

CreateDoubleArrow.js

function getMid(t,e){return[(t[0]+e[0])/2,(t[1]+e[1])/2]}function getDistance(t,e){return Math.sqrt(Math.pow(t[0]-e[0],2)+Math.pow(t[1]-e[1],2))}function getAngle(t,e,i){let n=getAzimuth(e,t)-getAzimuth(e,i);return n<0?n+TWO_PI:n}function getAzimuth(t,e){let i,n=Math.asin(Math.abs(e[1]-t[1])/getDistance(t,e));return e[1]>=t[1]&&e[0]>=t[0]?i=n+Math.PI:e[1]>=t[1]&&e[0]<t[0]?i=TWO_PI-n:e[1]<t[1]&&e[0]<t[0]?i=n:e[1]<t[1]&&e[0]>=t[0]&&(i=Math.PI-n),i}function getSymetricPoint(t,e,i,n,r){let o=getAzimuth(t,e),c=r?o+i:o-i,g=n*Math.cos(c),a=n*Math.sin(c);return[e[0]+g,e[1]+a]}function calculateSymmetryPoint(t,e,i){let n,r,o,c,g=getMid(t,e),a=getDistance(g,i),P=getAngle(t,g,i);return P<HALF_PI?(r=a*Math.sin(P),o=a*Math.cos(P),c=getSymetricPoint(t,g,HALF_PI,r,!1),n=getSymetricPoint(g,c,HALF_PI,o,!0)):P>=HALF_PI&&P<Math.PI?(r=a*Math.sin(Math.PI-P),o=a*Math.cos(Math.PI-P),c=getSymetricPoint(t,g,HALF_PI,r,!1),n=getSymetricPoint(g,c,HALF_PI,o,!1)):P>=Math.PI&&P<1.5*Math.PI?(r=a*Math.sin(P-Math.PI),o=a*Math.cos(P-Math.PI),c=getSymetricPoint(t,g,HALF_PI,r,!0),n=getSymetricPoint(g,c,HALF_PI,o,!0)):(r=a*Math.sin(2*Math.PI-P),o=a*Math.cos(2*Math.PI-P),c=getSymetricPoint(t,g,HALF_PI,r,!0),n=getSymetricPoint(g,c,HALF_PI,o,!1)),n}function getBaseLength(t){return Math.pow(wholeDistance(t),.99)}function wholeDistance(t){let e=0;for(let i=0;i<t.length-1;i++)e+=getDistance(t[i],t[i+1]);return e}function getAngleOfThreePoints(t,e,i){let n=getAzimuth(e,t)-getAzimuth(e,i);return n<0?n+TWO_PI:n}function getArrowHeadPoints(t,e,i){let n=getBaseLength(t),r=n*hea
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
Mapbox GL Draw 是一款基于 Mapbox GL JS 的开源插件,用于在地图上进行绘制操作,支持点、线、面等多种几何要素的绘制和编辑,是一款非常适合用于态势标绘的工具。 使用 Mapbox GL Draw 进行绘制态势标绘,可以通过以下步骤实现: 1. 引入 Mapbox GL JS 和 Mapbox GL Draw 插件,可通过 npm 安装或手动下载引入。 2. 在页面中创建地图容器,并初始化地图: ```javascript var map = new mapboxgl.Map({ container: 'map', style: 'mapbox://styles/mapbox/streets-v11', // 地图样式 center: [lng, lat], // 地图中心点经纬度 zoom: 13 // 地图缩放级别 }); ``` 3. 初始化 Mapbox GL Draw 插件,并将其添加到地图上: ```javascript var draw = new MapboxDraw({ displayControlsDefault: false, // 是否显示默认控件 controls: { // 自定义控件 point: true, line_string: true, polygon: true, trash: true } }); map.addControl(draw); ``` 4. 监听绘制事件,根据不同的绘制类型获取绘制的坐标信息: ```javascript map.on('draw.create', function(e) { var type = e.features[0].geometry.type; var coordinates = e.features[0].geometry.coordinates; // 根据绘制类型进行处理 }); ``` 5. 根据绘制类型,将绘制的要素添加到地图上: ```javascript map.addLayer({ 'id': 'drawn-feature', 'type': type, 'source': { 'type': 'geojson', 'data': { 'type': 'Feature', 'geometry': { 'type': type, 'coordinates': coordinates } } }, 'paint': { 'fill-color': '#f00', // 面颜色 'fill-opacity': 0.5, // 面透明度 'line-color': '#f00', // 线颜色 'line-width': 2 // 线宽度 } }); ``` 通过以上步骤,就可以使用 Mapbox GL Draw 进行绘制态势标绘了。除了绘制外,Mapbox GL Draw 还支持编辑、删除等操作,可以根据实际需求进行调整。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

侧耳倾听...

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值