stevage / map-gl-utils

A utility library that makes Mapbox GL JS or Maplibre GL a bit more convenient to work with.
https://npmjs.com/package/map-gl-utils
210 stars 24 forks source link

make layer type optional in props? #43

Open peterqliu opened 9 months ago

peterqliu commented 9 months ago
map.U.addCircleLayer('trees-circle', 'trees', {
    circleColor: 'green', // paint property
    circleRadius: ['interpolate', ['zoom'], 12, 3, 15, 5], // paint property
    circleSortKey: ['get', 'tree-sort-key'], // layout property
    filter: ['!=', 'type', 'stump'], // other property
});

Proposal to make the layer prefix optional in all props. The props above would read color, radius, and sortKey.

Only when disambiguating multiple props of the same kind (stroke- and circle-color in circle layers, icon-, text-, and halo-color in symbol layers, etc) will prefixes be needed. In those cases, the nonprefixed form will refer to the word in the layer type ("color" will refer to circle-color and "width" to line-width)

stevage commented 9 months ago

Yeah, interesting idea. I think personally I probably wouldn't use it much, due to the ambiguities. And also that semantic differences start to get conflated - line-offset has a bit of a different meaning from icon-offset.

But I'd be happy to accept a PR.

Not sure what should happen with ambiguous properties like offset in a symbol layer. Probably it shouldn't translate to anything.