ghettovoice / vuelayers

Web map Vue components with the power of OpenLayers
https://vuelayers.github.io/
MIT License
682 stars 230 forks source link

layer switcher #454

Closed wendellwt closed 2 years ago

wendellwt commented 2 years ago

Is it possible to use OpenLayers LayerSwitcher in vuelayers?

Would it be something like this?

<vl-overlay ref="ovly_ref">
   <vl-layer-vector ref="layer_ref">
       ....
   </vl-layer-vector>
</vl-overlay>

And define the switcher as:

var layerSwitcher = new LayerSwitcher();
map.addControl(layerSwitcher);

And then somehow insert the references to that layer into ol-layerswitcher:

  overlayGroup.getLayers().push(
    new Layer({
       title: 'My Layer',
       source: this.$refs.layer_ref }) )

Where should the group be defined? Does vuelayers automatically generate this?

Is the vl-overlay ref ovly_ref inserted into the group instead of the vl-layer-vector ref layer_ref?

Thank you

ghettovoice commented 2 years ago

Hello @wendellwt , vl-overlay component is for another purposes. It appends div container and bind it to some coordinate. So it not needed here.

As for LayerSwitcher usage: it expects custom layer fields that vuelayers doesn't support, but you can append them in the created event handler for each layer that should be in the switcher panel. Here is example https://jsfiddle.net/ghettovoice/qa8p913o/401/

wendellwt commented 2 years ago

Perfect! That works great!

Thank you again @ghettovoice !

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.