0
$\begingroup$

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:

  1. Blue headphone 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
  2. Blue marker with arrow- Blue marker with arrow (zindex should be such that it appears on top of others except Blueheadphone marker) - constant priority 4
  3. Blue marker - Blue marker - constant priority 3
  4. Orange marker - Orange Marker - constant priority 2
  5. Green marker - Green Marker - constant priority 1

So to give you complete picture it may look like as below:

Sample Image

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 Blue headphone 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 Orange marker and it is in same / overlapping location, its zindex would be 20*2 = 40 which obviously is greater than 5 so Blue headphone will go behind Orange marker.

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 Orange marker will never be bigger than any number generated for Blue headphone

Example

$\endgroup$
3
  • $\begingroup$ Can you just split the range of int into five sections? The formula will be like this: zindex = (intZIndex++) + (constantprioirt-1)*d, where d is like MAX_INT/5 $\endgroup$
    – Glinka
    Commented Jul 5, 2016 at 18:02
  • $\begingroup$ I think range is a good idea too. I have created a jsFiddle. Could you please have a look and let me know this is what you meant? It is really hard to verify results in this case as they don't start with the range they are defined for. $\endgroup$
    – ndd
    Commented Jul 5, 2016 at 18:41
  • $\begingroup$ Yes, that's what I meant. In this case you can't have more than 1,801,439,850,948,198 markers total, but with 10,000 markers per 24 hours that's more than enough (for about 500 million years) $\endgroup$
    – Glinka
    Commented Jul 6, 2016 at 7:08

0

You must log in to answer this question.

Browse other questions tagged .