Marker and polygon locations not agreeing?

11 views
Skip to first unread message

Daniel Mauer

unread,
Nov 30, 2016, 1:40:39 PM11/30/16
to Leaflet

[Crossposted at gis.stackexchange]


I've got a leaflet map, to which I added a GeoJSON object (a polygon, specifically) and a number of Markers. The markers should all be inside the polygon, but they're not being displayed that way:


Marker and Polygon strangeness


To be exact about it, the GeoJSON Polygon's coordinates are:


[[29.53125,49.921875],[29.53125,50.625],[30.9375,50.625],[30.9375,49.921875],[29.53125,49.921875]]


And the green-highlighted marker's coordinates are:


 [30.9332103729, 50.3615112305]


As you can see that marker is showing up well outside the outline of the polygon. The problem is considerably worse at wider zoom levels -- zoomed all the way in, the green marker makes its way just barely inside the polygon outline.


Any idea what could be causing this?


Max Abou-Hagar

unread,
Dec 7, 2016, 12:21:19 PM12/7/16
to Leaflet
From personal experience, most of the time something like that happens when the custom icon's anchor is wrong.
Try to generate a circle on the map and place an marker at the exact same position. You then have to figure the coordinates out how you want the icon to appear exactly (this is obvious for "default" icons, as they have that arrow, but maybe not that easy for custom icons sometimes).

The idea is that you can perfectly align the icon to the circles center, so you have the most correct icon anchor.

Max
Reply all
Reply to author
Forward
0 new messages