GithubHelp home page GithubHelp logo

Removing maps? about modestmaps-js HOT 7 CLOSED

dhcole avatar dhcole commented on June 28, 2024
Removing maps?

from modestmaps-js.

Comments (7)

RandomEtc avatar RandomEtc commented on June 28, 2024

This is something that isn't supported properly yet, but definitely should be.

If your Map is initialized without dimensions then it will listen for resize events on the window. This needs cleaning up if the Map is removed. The MouseHandler object also listens for events on window but doesn't (yet) have a way remove them.

A map.destroy() function would need to handle these things and also clear any in-flight requests for tiles (otherwise the unload/error handlers for the images might cause errors when they return). That sounds scary but I'm pretty sure the request manager does the right thing already if you set a new provider, so it's probably just a matter of piggy-backing on that logic.

Hopefully we can look at this soon if it's not something you want to tackle yourself. In the meantime, honestly, 10 maps should be fine because there's not a lot of overhead to a map once the images have loaded.

But if they really aren't all visible at once (e.g. in a slide show) and you want to conserve memory/resources, consider a creating a pool of maps that you recycle by resetting the provider (if needed) and moving the parent element around in the DOM. The only caveat I can think of is that you might need to keep the maps in the DOM somewhere for some of the loading events to work, but you should be able to put a map in an element hidden with display:none without trouble.

from modestmaps-js.

dhcole avatar dhcole commented on June 28, 2024

Thanks @RandomEtc. Yes, the layout is similar to a slideshow. I'm not seeing any real performance issues at this point but wanted to play it safe. Thanks for this information.

from modestmaps-js.

tmcw avatar tmcw commented on June 28, 2024

First shot at this work in https://github.com/stamen/modestmaps-js/tree/mapdestroy

This

  • clears the request queue
  • unbinds window.resize

I'm uncertain as far as whether map.destroy should kill all of the DOM elements the map creates, the map parent, or none of the above, so haven't pushed on that work yet.

from modestmaps-js.

RandomEtc avatar RandomEtc commented on June 28, 2024

Looks good so far. Removing the mouse/touch event handlers would be the next main thing, and I'd say just go for it and clear all the DOM elements too. If that's not what you want, don't call destroy :)

from modestmaps-js.

tmcw avatar tmcw commented on June 28, 2024

Yeah, I'll fold #45 into this ticket then to simplify the branching.

from modestmaps-js.

tmcw avatar tmcw commented on June 28, 2024

Cool, in b70e476 and 756950d , handlers are now removable and removed in mapdestroy and layerParent is removed from the page. I think this branch is ready to roll.

from modestmaps-js.

tmcw avatar tmcw commented on June 28, 2024

Fixed in 2fd8e7d

from modestmaps-js.

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.