Multiple FeatureSourceVectorTileSources in MapStyle

Hi,

Is it possible to have multiple FeatureSourceVectorTileSources in one MapStyle ? I tried to use MapStyle::AddStyle() to add two FeatureSourceVectorTileSources but from some reason only the one which was added first is visible on the map.

Is this intentional or am I doing something wrong ?

Br, Simo

Hi Simo,

It is possible, and what you hit was us failing in silence, and it’s been fixed in beta185.

The rule: Every source is registered under a name, and every layer names the source it reads. Two sources means two names.

If you build the layers in code, the name is the argument you pass — and the third argument of CreateFill / CreateLine is that same name (the fourth is the source-layer inside it):

style.AddStyleLayers(parcels, "parcels-source",
    i => StyleLayer.CreateFill("parcels-fill", i, "parcels-source", "parcels", paint: ...));

style.AddStyleLayers(roads, "roads-source",
    i => StyleLayer.CreateLine("roads-line", i, "roads-source", "roads", paint: ...));

If you add style documents, the name comes from the document’s own sources block, and the source you pass is bound to it:

const string parcelsDoc = """
{ "sources": { "parcels-source": { "type": "vector" } },
  "layers": [ { "id": "parcels-fill", "type": "fill",
                "source": "parcels-source", "source-layer": "parcels",
                "paint": { "fill-color": "#88AACC" } } ] }
"""";

style.AddStyle(parcelsDoc, parcels);
style.AddStyle(roadsDoc, roads);     // declares "roads-source"

Two documents that both declare the same name — are the likely cause of what you saw: we kept the first source and dropped the second without a word, so the second document’s layers read the first document’s tiles.

What beta185 changed. Nothing about what is possible; both of the above worked before. What changed is that the two ways of getting the name wrong now throw instead of drawing nothing:

These layers name a source the style does not have: ‘fill’ read ‘somebody-elses-name’.
this style has ‘its-own-name’.

One last thing: the AddStyleLayers overload that takes no source name invents one (vector-1, vector-2) which you cannot write in your layers — so with more than one source, always pass the name yourself.

Thanks,
Ben