1

I am trying to make moving cars on MapBox using new promising GL Symbol layer/source. It looks very nice both on android and ios, but I faced with two impossibilities.

  1. Symbols are always clustering. setIconAllowOverlap() and setIconIgnorePlacement() don't help: on some zoom it WILL be clustered. On both platforms.

How can I disable symbols clustering completely?


UPDATE: the code and even fast solution! (possibly bug? see comment at withTextField)

in onStyleLoaded():
...
carManager = new SymbolManager(mapView, mapboxMap, style);
carManager.setIconAllowOverlap(true);//doesn't help
carManager.setIconIgnorePlacement(true);//doesn't help
...

in drawCarFunction():
...
            SymbolOptions carOptions = new SymbolOptions()
                    .withLatLng(latLng)
                    .withIconImage(carPlate)
                    //.withTextField(carPlate) //!!!! here it will cluster if text exists, and will NOT - without any text
                    ;
            Symbol car= carManager.create(carOptions);
            carSymbols.add(car);
...

Next question:

  1. On Android we have symbolManager.addClickListener() , but how could I catch a click on iOS? I know I can catch the tap, calculate nearest marker etc but

How to get symbol click simpler in swift?

  1. In Moving cars task I should enumerate existing cars, move running, add newest. Where should I store cars IDs to get it later on next move? Where are no even symbol.setTag() option... Storing IDs in snippet (as on GMaps) is not that choice I expected from MapBox. Sure, I can make an array of pairs "car ID = symbol ID", but

How to store my own UID in the symbol?

UPDATE: the code. Note the comment near getTag()

void moveExistingCarOrAddNew(int carId, LatLng newLocation){ 
  for (int i = 0; i < carManager.getAnnotations().size(); i++) { 
    if (carManager.getAnnotations().get(i).getTag()==carId){ //but no getTag() here, I should fit data into text fields
       car.setLatLng(newLocation); //move! 
    } else { 
       ...//create new marker as shown above } 
    }
  }
}
riastrad
  • 1,624
  • 10
  • 22
djdance
  • 3,110
  • 27
  • 33
  • Can you narrow your problem down a specific thing and show the code that is giving you the problem? – Magnas Mar 09 '19 at 18:09
  • I've updated my questions. Also I've found the solution of first one, but this is probably the bug. – djdance Mar 10 '19 at 09:59
  • Actually, my questions is for MapBox support team mostly, because first piece of code is from official example – djdance Mar 10 '19 at 09:59
  • I think you can set symbol's layout style `icon-allow-overlap` and `text-allow-overlap` as `true` for unclustering. – Chase Choi Mar 11 '19 at 01:41
  • I set it already, don't work. They are clustering on both platforms – djdance Mar 11 '19 at 05:03
  • 2
    I'd recommend splitting your questions into single issues by platform (iOS or Android) Answering all 4 questions in one response for different platforms would be a bit muddled. – riastrad Mar 12 '19 at 20:10
  • Hey you got the solution or not? I am facing same problem in android .Please help me out. – Nadim Ansari Mar 18 '21 at 13:09
  • Nope. I had to use a lot of individual SymbolLayers for every car. – djdance Mar 18 '21 at 19:56

0 Answers0