Open alexandreDavid opened 3 years ago
What is your Zoom level? map.getZoom()
I reproduce very often it might not be a problem of zoom but calculation of vertex position on the line
In this code snippet you see that the calculation converts the latlng to a pixel point and then back. https://github.com/geoman-io/leaflet-geoman/blob/ff58d546ae5807a331485c16b5ac442b6bbce527/src/js/Mixins/Snapping.js#L425-L446
I didn't found a way to do this with the latlng directly, a PR from you is welcome, else we can't fix this.
I know this is old, but I'm also running into a similar issue here. I'm performing geo analysis with Turf (https://turfjs.org/) to ensure that my smaller polygons do not extend outside of the bounds of a larger, outer polygon.
When I use the snapping feature and the small polygon gets snapped to the larger one, the point at which the smaller is snapped is outside the bounds of the larger polygon according both to Turf and to point-on-line-segment calculations that I accomplished.
I've done a workaround using Turf's buffer method (https://turfjs.org/docs/#buffer) where I essentially extend the outer polygon by 2 feet, like so:
` import { polygon } from '@turf/helpers' import containsHelper from '@turf/boolean-contains' import bufferHelper from '@turf/buffer'
const validate = (zoneLatLngs, sectorLatLngs) => { const zone = polygon(zoneLatLngs) const bufferedZone = bufferHelper(zone, 2, { units: 'feet' }) const sector = polygon(sectorLatLngs)
// Zone contains sector
if (containsHelper(bufferedZone, sector)) return true
return false
} `
Pulling the point away from the snapped location outside of the polygon validates correctly, given a 2 foot tolerance. Hopefully this is helpful for somebody else.
I know this is old, but I'm also running into a similar issue here. I'm performing geo analysis with Turf (https://turfjs.org/) to ensure that my smaller polygons do not extend outside of the bounds of a larger, outer polygon.
When I use the snapping feature and the small polygon gets snapped to the larger one, the point at which the smaller is snapped is outside the bounds of the larger polygon according both to Turf and to point-on-line-segment calculations that I accomplished.
I've done a workaround using Turf's buffer method (https://turfjs.org/docs/#buffer) where I essentially extend the outer polygon by 2 feet, like so:
` import { polygon } from '@turf/helpers' import containsHelper from '@turf/boolean-contains' import bufferHelper from '@turf/buffer'
const validate = (zoneLatLngs, sectorLatLngs) => { const zone = polygon(zoneLatLngs) const bufferedZone = bufferHelper(zone, 2, { units: 'feet' }) const sector = polygon(sectorLatLngs)
// Zone contains sector if (containsHelper(bufferedZone, sector)) return true return false
} `
Pulling the point away from the snapped location outside of the polygon validates correctly, given a 2 foot tolerance. Hopefully this is helpful for somebody else.
Hey thanks for your reply but still not sure how do you apply your validate function into the snap function
When I edit a polygon with a zoom level low and I snap this polygon to another one, it's very common the created snap point is not exactly on the line / point. For me, it's a problem regarding I control if these polygons are not intersecting.