Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Nikolay Pavlin for rotate polygon around point in leaflet map

I adapted @dooderson and @MBo from this question answers, the final code is something like this, it works perfectly!

rotatePoints (center, points, yaw) {  const res = []  const centerPoint = map.latLngToLayerPoint(center)  const angle = yaw * (Math.PI / 180)  for (let i = 0; i < points.length; i++) {    const p = map.latLngToLayerPoint(points[i])    // translate to center    const p2 = new Point(p.x - centerPoint.x, p.y - centerPoint.y)    // rotate using matrix rotation    const p3 = new Point(Math.cos(angle) * p2.x - Math.sin(angle) * p2.y, Math.sin(angle) * p2.x + Math.cos(angle) * p2.y)    // translate back to center    let p4 = new Point(p3.x + centerPoint.x, p3.y + centerPoint.y)    // done with that point    p4 = map.layerPointToLatLng(p4)    res.push(p4)}return res}

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>