wp-plugin-leaflet-map icon indicating copy to clipboard operation
wp-plugin-leaflet-map copied to clipboard

Re-initialise map

Open merijnponzo opened this issue 3 years ago • 0 comments
trafficstars

I was looking for a way to re-initalise a map, for example: the map is already rendered with the shortcode in a popup, and needs to be shown when the popup is active.

map.invalidateSize() with a timeout does the trick, is this the way to go?

export const Maps = () => {
  return {
    active: true,
    init() {},
    setActive() {
      this.active = !this.active;
      if (window.WPLeafletMapPlugin) {
        // window.WPLeafletMapPlugin.init();
        const mapsFound = window.WPLeafletMapPlugin.maps;
        for (var i = 0, len = mapsFound.length; i < len; i++) {
          var map = mapsFound[i];
          setTimeout(function () {
            map.invalidateSize();
          }, 600);
        }
      }
    },
  };
};

// export all blocks
export default { Maps };

merijnponzo avatar Jan 28 '22 12:01 merijnponzo