Title: Refresh Map with jQuery
Last modified: March 29, 2022

---

# Refresh Map with jQuery

 *  [ckarisch](https://wordpress.org/support/users/ckarisch/)
 * (@ckarisch)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/refresh-map-with-jquery/)
 * Hi,
 * I use jQuery to switch between multiple maps. To realize this, I set a css class,
   that uses display: none.
    When displaying a map that has been hidden, it is not
   loaded correctly (only part of the map is shown). As soon as I resize the window,
   the map refreshes and works correctly.
 * Ho can I manually trigger a map refresh?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [MiKa](https://wordpress.org/support/users/photoweblog/)
 * (@photoweblog)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/refresh-map-with-jquery/#post-15521661)
 * Hi [@ckarisch](https://wordpress.org/support/users/ckarisch/)
 *  hmm, I am not sure. With jQuery call the OpenLayers function
 * `map.updateSize();`
 * could work. But the “map” is generated dynmically so you will have to look at
   your pagesource and “map” can change if you add or delete a osm-map on this site.
 * The plugin does not support an out-of-the-box solution.
 * Br, Michael
 *  Thread Starter [ckarisch](https://wordpress.org/support/users/ckarisch/)
 * (@ckarisch)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/refresh-map-with-jquery/#post-15528415)
 * Thank you. I tried to call that method, but it was not possible the map var is
   defined locally. I tried to redefine the map var:
 * const map = L.map(‘osm-map-cbcc74b’, {
    scrollWheelZoom: true, zoomControl: true,
   dragging: true });
 * But than i get this error: Uncaught Error: Map container is already initialized.
 * Kind regards, Chris
 *  Plugin Author [MiKa](https://wordpress.org/support/users/photoweblog/)
 * (@photoweblog)
 * [4 years, 2 months ago](https://wordpress.org/support/topic/refresh-map-with-jquery/#post-15528674)
 * Hi [@ckarisch](https://wordpress.org/support/users/ckarisch/),
 * change the WP OSM Plugin:
    Create a static osm plugin function to refresh it 
   with updateSize and provide a call to refresh all maps or just one specific. 
   I assume refresh all would be easier since you do not know which one you want
   to refresh. Then call this new function in your private coding. If it works and
   after I did some tests I could also take it to the standard so you will get plugin
   updates in future without loosing your call.
 * But if you know how to code it could be also easier to simply have a look to 
   the leaflet or openlayers libraries and write the mapping part exactly to your
   needs.
 * Br, Michael
 *  Thread Starter [ckarisch](https://wordpress.org/support/users/ckarisch/)
 * (@ckarisch)
 * [4 years, 1 month ago](https://wordpress.org/support/topic/refresh-map-with-jquery/#post-15617842)
 * Many thanks for the help. In the meantime, however, I have decided on a different
   solution that does not require a refresh.
 * Kind regards
    Chris

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Refresh Map with jQuery’ is closed to new replies.

 * ![](https://ps.w.org/osm/assets/icon-256x256.png?rev=2087144)
 * [OSM - OpenStreetMap](https://wordpress.org/plugins/osm/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/osm/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/osm/)
 * [Active Topics](https://wordpress.org/support/plugin/osm/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/osm/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/osm/reviews/)

## Tags

 * [jquery](https://wordpress.org/support/topic-tag/jquery/)

 * 4 replies
 * 2 participants
 * Last reply from: [ckarisch](https://wordpress.org/support/users/ckarisch/)
 * Last activity: [4 years, 1 month ago](https://wordpress.org/support/topic/refresh-map-with-jquery/#post-15617842)
 * Status: not resolved