ol-mapbox-style icon indicating copy to clipboard operation
ol-mapbox-style copied to clipboard

Rendering raster styles when using OpenLayers MapboxVector layer

Open scadergit opened this issue 3 years ago • 12 comments

I am attempting to create a MapboxVector layer, as one of many other layers in a larger application. The problem is raster style layers are ignored, as that is beyond the scope of applyStyle. Using olms is not feasible, given the management of the layers by the application. Is there a means to apply (or limit) olms to an layer group that was defined by the application?

~Looking how map is used within apply, I wonder if it would be the wiser if a layer group was sent to it instead of a map...~ Looks like apply needs the map view.

scadergit avatar Aug 01 '22 16:08 scadergit

Currently there is no way to achieve what you want directly. But it should not be too hard to make applyStyle work with Tile layers, in addition to Vector and VectorTile layers.

ahocevar avatar Aug 01 '22 19:08 ahocevar

Would that mean making the Tile layer url parameter optional in exchange for providing a style url parameter that the Tile layer can pull the tile url from, or would you expect that to be done up-front, and simply invoke the applyStyle if an additional style url parameter is passed?

scadergit avatar Aug 01 '22 19:08 scadergit

Currently, when you call applyStyle() with a VectorLayer or VectorTile layer instance, ol-mapbox-style knows what to do with it. The same can be implemented for TileLayer. If the TileLayer has a source already, applyStyle will override its url or url loading function, same as for a VectorTile source. If it has no source yet, applyStyle() will create one.

ahocevar avatar Aug 01 '22 20:08 ahocevar

Thanks...reviewed a lot of the code today, but missed that part. I'll look it over again.

scadergit avatar Aug 01 '22 21:08 scadergit

@scadergit Thanks for digging into this. Let me know if I can help anywhere.

ahocevar avatar Aug 02 '22 14:08 ahocevar

In that approach, the application would need to know up-front if a style definition included raster and/or vector layers, create separate layers for each, and call applyStyle() on each?

scadergit avatar Aug 08 '22 19:08 scadergit

Correct. But I see your point now. It looks like what you are looking for are layers and sources options for apply(). Adding those would also be an acceptable solution. Those could be an array of layer or source ids, or a function that receives a Mapbox layer or source as argument and returns a boolean to indicate whether to include or not.

ahocevar avatar Aug 08 '22 19:08 ahocevar

What if apply() was updated (or create applyGroup()?) to apply the new layers of the style definition to an OL group argument, and ignore any map/view style definition configuration?

scadergit avatar Aug 08 '22 19:08 scadergit

It should be possible to extend the API so apply() also accepts a layer group in as first argument. In that case, mapbox-style property would be set on the layer group, and the background would be set on the first layer instead of the map.

ahocevar avatar Aug 08 '22 19:08 ahocevar

I have a wip to review, can I get push permissions?

scadergit avatar Aug 12 '22 21:08 scadergit

Just create a pull request.

ahocevar avatar Aug 12 '22 21:08 ahocevar

Apparently my brain checked out early for the weekend...pull request created

scadergit avatar Aug 13 '22 03:08 scadergit

Resolved in #648

Thanks, @ahocevar for your help on this effort.

scadergit avatar Aug 18 '22 19:08 scadergit