Coder Social home page Coder Social logo

.setMap(null) error about js-marker-clusterer HOT 6 OPEN

thdoan avatar thdoan commented on May 24, 2024
.setMap(null) error

from js-marker-clusterer.

Comments (6)

longcui avatar longcui commented on May 24, 2024 11

I got the same error, Use markerCluster.clearMarkers(); works

from js-marker-clusterer.

jerrywang121 avatar jerrywang121 commented on May 24, 2024 2

On top of implementing the onRemove() as suggested junalmeida , you will also need to take care of

  1. clear clutters[]
  2. set all markers with null map
  3. remove event listeners on previous map
    attached is modified version which works fine for switching on/off markers with setMap function call

markerclusterer.zip

from js-marker-clusterer.

thealjey avatar thealjey commented on May 24, 2024 1

@jerrywang121 your solution works perfectly! Could you make it into a pull request?

from js-marker-clusterer.

junalmeida avatar junalmeida commented on May 24, 2024

This also affects me. Add the following to line 229.

/**
 * Implementaion of the interface method.
 * @ignore
 */
MarkerClusterer.prototype.onRemove = function () {
    this.setReady_(true);
};

from js-marker-clusterer.

Gert25 avatar Gert25 commented on May 24, 2024

My short solution to this problem was to first overwrite the onRemove() function before calling the constructor and nuking the clusters.
var mc =window.MarkerClusterer.prototype.onRemove = function(){
for ( var i = 0 ; i < this.clusters_.length; i++){
this.clusters_[i].remove()
}
}
And then instantiate the Markerclusterer
mc = new window.MarkerClusterer(map,filteredMarkers, options)

note that filteredMarkers are my google markers and and the options I pass into the constructor options is an imagePath and the maxzoom options. it doesn't effect the way the solution is implemented.

Then finally I call the setMap(null) method on the Markercluster object which fires the onRemove function:
mc.setMap(null)

Also not that I remove the google markers from the map (by calling the setMap(null) method on each marker) before calling the mc.SetMap(null) method.

from js-marker-clusterer.

yepes avatar yepes commented on May 24, 2024

@longcui genius!!!

from js-marker-clusterer.

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.