Unfolding markers - Polygons inside polygons

edited September 2014 in Library Questions

Hello everyone,

I am trying to load the features contained in a geojson file as markers (as shown in this example: http://unfoldingmaps.org/tutorials/markers-data-geojson.html). However when the file has these type of geometries (see picture), unfolding does not recognize the inner polygon as a marker. Is there any way to fix this?

Multipolygon

I hope someone can help me to solve this!!! Thanks

Note: The geometry can't be modified since it represents land use regions in a city!

Answers

  • Not sure I fully understand. Is the inner polygon an actual polygon, or simply a hole in the outer polygon? What do you want to do with it (that you need a marker for it)?

  • Hi, thanks for replying!

    What I have is the following: I have a polygon with a hole (a ring) and I have an inner polygon which is exactly inside the hole. Each of these geometries have different attributes (population, income, number of blocks, etc).

    What I want to do is to be able to catch the event when I roll the mouse over or when I click on one of these polygons to retrieve specific information about it. Markers look like a good option to achieve this (using the "getFirstHitMarker(mouseX,mouseY)" method), no?.

    I found out that all polygons (multi-polygons and simple polygons) are included in the markers list, so the problem should be in the "getFirstHitMarker" method. Any clue/suggestion about what can I do to be able to select the inner polygons?

  • edited September 2014 Answer ✓

    Ok, so I understand the two polygons are independent each having own properties. Then it should be fairly easy. The getFirstHitMarker returns the first found marker which contains the mouse pointer (or whatever screen pos you gave as param). Thus, you only need to order your markers accordingly, i.e. in your case the smaller ones atop the larger ones (meaning in the marker list they should be: inner, outer).

    Alternatively, you could use the getHitMarkers(x, y) and do a second check yourself.

  • Great! Now it works! What I did was the following. I used the getHitMarkers(x,y) and when the size of this array was > 1, I set as selected the Marker which is in the position [1] of the "HitMarkers" array. I'm not sure if this is the most efficient way to do this but it works.

    Thanks for your help!

  • edited September 2014

    Great to hear. Seems like you simply need to reverse the order of the markers in the list to begin with.

    [1] is the second one, and if that's always the one you need just switch their positions before in order to directly use getFirstHitMarker.

Sign In or Register to comment.