• Resolved svenatkins

    (@svenatkins)


    Hello,
    it is possible to access the map object with another script after the map is initialized?

    Greetings,
    Sven

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author 100plugins

    (@100plugins)

    Hi @svenatkins,

    Actually yes. The map object is called oumMap in Javascript. Here you’ll find the LeafletJS documentation on what you can do with it: https://leafletjs.com/reference.html

    Best regards,
    Daniel

    Thread Starter svenatkins

    (@svenatkins)

    Hi Daniel,
    unfortunately that didn’t work for me.
    I have added a script to a page below the map, the map is added via WordPress, the script in the template file.

    document.querySelectorAll('.btn_swiper').forEach(link=> {
      link.addEventListener('click', function() {
    	const lng = document.querySelector('.swiper-slide-active').getAttribute('data-longitude');
    	const lat = document.querySelector('.swiper-slide-active').getAttribute('data-latitude');
    
    	console.log(lng, lat);      
    	oumMap.flyTo([lat,lng], 18);
      })
    })

    And I get the following error: oumMap.flyTo([lat,lng], 18);

    When I add the script in the file: frontend-block-map.js with map.flyto… it works fine.
    But I need it in combination with the swiper.js

    Thanks,
    Sven

    Plugin Author 100plugins

    (@100plugins)

    Hey @svenatkins,

    Did you try to wrap your code inside

    $('document').ready(function(){
      // your code
    
    });

    ?

    If you like to avoid jquery you’d need to use a vanilla JS equivalent.

    Best Regards,
    Daniel

    • This reply was modified 2 years, 8 months ago by 100plugins.
    Thread Starter svenatkins

    (@svenatkins)

    Hi Daniel,
    sorry no luck with jQuery.

    Uncaught ReferenceError: oumMap is not defined

    Do I have to activate a setting somewhere to make it work?

    Thanks,
    Sven

    Thread Starter svenatkins

    (@svenatkins)

    I found the error: was testing with version 1.2.19. It works fine with version 1.2.20.

    Sorry.

    Plugin Author 100plugins

    (@100plugins)

    Ah! Yeah, I should have told you that I added this feature with version 1.2.20

    Best regards,
    Daniel

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Access the map object with another script’ is closed to new replies.