Giter VIP home page Giter VIP logo

Comments (11)

ahocevar avatar ahocevar commented on September 26, 2024

You could do something like

// clear everything from previous style
map.setLayerGroup(new ol.layer.Group());
// apply new style
olms.apply(map, satJson);

from ol-mapbox-style.

medida avatar medida commented on September 26, 2024

Thanks - Sadly this will remove all other layers like markers etc..

I've got a solution at the moment where i loop through the layers of the map and then remove the layer which is the tiles of the map. Its not pretty.
I'll look into the groups to see if i can use this.

I can have lots of markers displayed on a map and it would be nice if the style added through apply() could be stored in its own object... Is that possible?

Thanks

from ol-mapbox-style.

ahocevar avatar ahocevar commented on September 26, 2024

We're currently working on a solution where only changes from a previous apply() or applyStyle() call will be applied to the map. This will result in what you're looking for.

In the meantime, you can loop through the existing layers and only remove those that have a mapbox-layers property.

from ol-mapbox-style.

medida avatar medida commented on September 26, 2024

Thats sounds great - is there an approx timescale for that?

thanks

from ol-mapbox-style.

ahocevar avatar ahocevar commented on September 26, 2024

Should be done in a few weeks.

from ol-mapbox-style.

medida avatar medida commented on September 26, 2024

also trying to get the mapbox-layers property.

If i'm looping through all the layers - I've looked at each object and cannot see a property matching the above.

_map_layers = map.getLayers().getArray()

_map_layers.forEach(function (_l) {
console.log(_l)

        })

from ol-mapbox-style.

ahocevar avatar ahocevar commented on September 26, 2024

Try this:

const layers = map.getLayers().getArray();
for (let i = layers.length - 1; i >= 0; --i) {
  const layer = layers[i];
  if (layer.get('mapbox-layers')) {
    map.removeLayer(layer);
  }
}

from ol-mapbox-style.

medida avatar medida commented on September 26, 2024

Thanks - that's great..

Look forward to the new release as well

thanks for the quick replies.

from ol-mapbox-style.

brightrain avatar brightrain commented on September 26, 2024

Hello @ahocevar just checking in on this toggle issue to see if the solution you mention here has been implemented. I am also trying to toggle between a 'streets' and 'imagery' layer (from map tiler) and can't seem to work out the pattern. Is your solution above still the correct approach or is there a new\better way. Thank you for your work and input.

from ol-mapbox-style.

ahocevar avatar ahocevar commented on September 26, 2024

Unfortunately this has not been implemented yet, but I may be able to get this feature funded and implemented before the end of the year.

The snipped I posted in #77 (comment) should still work. Just call it before applying the new style to the existing map.

from ol-mapbox-style.

brightrain avatar brightrain commented on September 26, 2024

That's exactly what I did and it works great. thx

from ol-mapbox-style.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.