Marker inside Polygon

485 views
Skip to first unread message

Martin Friedrich

unread,
Feb 16, 2013, 1:38:27 AM2/16/13
to leafl...@googlegroups.com
I am looking for a plugin or idea to search markers inside a placed polygon to get attributes of the markers back. Is there a solution in leaflet?

Regards

Martin

ben wyss

unread,
Feb 16, 2013, 12:09:49 PM2/16/13
to leafl...@googlegroups.com
I use CartoDB and Leaflet for exactly this. CartoDB has a api that can be used to query your data, it will kick back the results in json which can be easily rendered in leaflet
cheers,
Ben
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Leaflet" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Paulo Vieira

unread,
Feb 20, 2013, 11:47:32 AM2/20/13
to leafl...@googlegroups.com
On Saturday, February 16, 2013, Martin Friedrich <mille...@googlemail.com> wrote:
> I am looking for a plugin or idea to search markers inside a placed polygon to get
> attributes of the markers back. Is there a solution in leaflet?

I think the closest thing to what you want that leaflet currently has is the "intersects" method in L.Bound.

You'll have to implement this yourself (and maybe make a plugin out of it?).

If the polygon of your problem is a triangle (or any other convex polygon), it is trivial. If it is not convex, you could do some preprocessing and calculate a rough triangulation of the polygon. Then it would be a matter of checking if the marker if inside of one of the triangles.

Another possibility is the "even-odd rule":
http://en.wikipedia.org/wiki/Point_in_polygon

Also, some days ago I saw a nice example of using leaflet+d3 which is related to this subject:

bounding box queries with quadtrees from d3
http://bl.ocks.org/calvinmetcalf/4963273


And this plugin is also related:
https://github.com/kajic/leaflet-locationfilter/

Martin Friedrich

unread,
Feb 20, 2013, 2:06:26 PM2/20/13
to leafl...@googlegroups.com
Thanks to all for your help. I will have a look on the examples.
Reply all
Reply to author
Forward
0 new messages