• 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

    (@photoweblog)

    Hi @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

    (@ckarisch)

    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

    (@photoweblog)

    Hi @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

    (@ckarisch)

    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.