0

I have a map that is created by leafletJS. I fitBounds the map to polygon area and my pointer is fixed in center of the map but in the special case like below my polygon is in a shape that the pointer does not fits in the polygon bounds although I fitBounds to polygon bound.

what shall I do for the polygons which the centered pointer does not place in polygon area in first load?

enter image description here

 const selectedPoint = point([mapCenter.lat, mapCenter.lng])
              const poly = polygon([polygonCoords])
              const isPointInPolygon = booleanPointInPolygon(selectedPoint, poly)

              if (isPointInPolygon) {
                // onDragEnd && onDragEnd({ latitude: mapCenter?.lat, longitude: mapCenter?.lng })
              } else {
                toast({ content: formatMessage(strings.selectInPolygonError), type: 'error' })
                onDragEnd && onDragEnd(null)
                myMap.fitBounds(mapPolygon.getBounds())
              }

N.SH
  • 616
  • 7
  • 20
  • You probably need a better definition of what your center is. See https://stackoverflow.com/questions/55982479/difference-between-centroid-and-centerofmass-in-turf There's also [this article](https://blog.mapbox.com/a-new-algorithm-for-finding-a-visual-center-of-a-polygon-7c77e6492fbc) that probably explains what you want. Also, fitToBounds moves the camera to show your whole polygon. It doesn't move the point or anything like that. – Lucas P. Luiz Apr 11 '23 at 15:11

0 Answers0