I did ask this question on SO but it seems this will find more appropriate audience here.
I have a Google map where I am dropping markers based on events, this happens periodically and after 8 hours a marker is removed. Events are real time and their is no guarantee which will appear when, on an average in period of 24 hours number of markers dropped will be somewhere between 5000 to 10000. For sake of this question lets assume I have below markers:
Blueheadphone marker (zindex must be set in way that it shows on top of any other icon no matter when other icons appear on the map) - constant priority 5
- Blue marker with arrow (zindex should be such that it appears on top of others except Blueheadphone marker) - constant priority 4
- Blue marker - constant priority 3
- Orange Marker - constant priority 2
- Green Marker - constant priority 1
So to give you complete picture it may look like as below:
When I am adding them in Google Maps I am setting zindex like this:
zindex = intZIndex++ * constantprioirty
//where intZIndex is int variable initialized with value 1.
Now obviously this doesn't work well because say first was dropped then it's zindex would be set to
1*5 = 5
and now when the say 20th marker is dropped and lets assume it is and it is in same / overlapping location, its zindex would be
20*2 = 40
which obviously is greater than 5 so will go behind
.
Another thing that I can probably try is to assign Prime numbers as priority and then do Priority(index++) but I don't think this will always work.
I was thinking if I can some how map them in two dimensions like shown below then using x and y I can probably get a unique number in a way that any number generated for will never be bigger than any number generated for