3

The intention here is to determine the proper convention for adding multiple styling rules for a single layer in 'layers' list. My impression was such that multiple layer entries would mean a call to draw the whole layer multiple times which should be avoided. However, in cases such as the need to style both fill and stroke (lines) it appears the official recommendation is to add one layer with Fill type, and another layer with Line type. In this instance, will the engine draw the whole layer twice? Does that only happen when the type is repeated? Or rather, is it contingent on ID uniqueness?

This is what I initially imagined handling for an "else rule" and one with a filter would look like:


      {
         "source-layer" : "myLayer",
         "type" : "fill",
         "paint" : {
            "fill-color" : "blue"
         },
         "id" : "myLayer",
         "source" : "test"
      },
      {
         "source-layer" : "myLayer",
         "type": "fill",
         "paint" : {
            "fill-color" : "red"
         },
         "id" : "myLayer",
         "source" : "test",
         "filter" : [ "==", [ "get", "ATTRIBUTE" ], "colorMeRed" ]
      },

Will this draw myLayer, then draw it again, overlapping?

2
  • You can't have two layers with the same id. You'll want to use myLayer and myLayer1 or any other names that aren't the name. Commented Sep 17, 2019 at 22:33
  • I have a heavy vector tile layer, which I don't want to load twice (to save on bandwidth) but just style it twice. Did you ever find a good solution?
    – Shaunak
    Commented Oct 26, 2019 at 5:16

1 Answer 1

0

Far as I can tell the existing solution to what I'm aiming to implement is "data-driven styles" e.g. https://docs.mapbox.com/mapbox-gl-js/example/data-driven-circle-colors/ which, contrary to most styling conventions, will rely on a filter inside the styling block rather than at the layer level.

It's still unclear to me if duplicating a layer with a different 'type' set will draw the whole polygon twice.

4
  • Drawing is an internal implementation detail, but yes a fill layer will be drawn then a line layer will be drawn if you have a fill and line layer. Commented Sep 17, 2019 at 22:35
  • AndrewHarvey to be clear it would be the same polygon layer source w/ type set as line in the 2nd instance. Since Fill type only allows a fill-outline-color property with 1px width, that is the workaround I found.
    – Sleep6
    Commented Sep 19, 2019 at 14:06
  • That's not a workaround it's the official way of doing polygon outlines. Commented Sep 19, 2019 at 21:36
  • 2
    The official way seems pretty hackish.
    – Sleep6
    Commented Sep 21, 2019 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.