1

We have a usual source url of something like https://my-source/{x}/{y}/{z}. When the user selects filtering options, we'd like to add these params to the url as something like https://my-source/{x}/{y}/{z}?my-param=true and instantly update the map.

Is this possible to achieve in mapbox?

enyciaa
  • 1,982
  • 1
  • 14
  • 24
  • I'm not sure what you're trying to accomplish by adding parameters to the source url, but the way to modifying/filtering the source at runtime is to use expressions: https://docs.mapbox.com/android/maps/guides/styles/use-expressions/ – Etherlind May 13 '22 at 11:26
  • We did explore the option you mention above, but found our data set was too large. For example take the case that the users zoomed fully out, there are potentially millions of data points. So to keep the map speedy, we need to return a partial vector tile and maybe cache this tile. We could use filter expressions, but then we're filtering an already partial vector tile, with no way to tell the server "hey give us a bigger chunk of the vector tile". Hence trying the option of url params. – enyciaa May 16 '22 at 10:43

1 Answers1

1

Turns out this is relatively simple! If a little difficult to find, the code below will update the tile url dynamically:

val source = style.getSourceAs<VectorSource>(CHARGE_POINT_SOURCE_ID)
source?.tiles(listOf(newSourceUrl))
enyciaa
  • 1,982
  • 1
  • 14
  • 24