• Resolved andyt1980

    (@andyt1980)


    Hi,
    When adding a leaflet map shortcode to a post built using the Guteberg editor the map doesnt display and gives the following browser console error:

    Uncaught TypeError: Cannot read property ‘addLayer’ of undefined
    at e.addTo (leaflet.js:5)
    at (index):177
    at init (97909.js:1)

    I can confirm if I switch to a post created with the classic wordpress editor the map displays fine.

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

    (@bozdoz)

    Sounds interesting. I cannot recreate this. Could you give me more details on the theme you’re using perhaps?

    Check out my screenshots:

    View post on imgur.com

    View post on imgur.com

    Thread Starter andyt1980

    (@andyt1980)

    Hmmm, thats strange, I’m using Generatepress which is generally regarded as a very well coded theme as it always adheres to WordPress coding standards. I would have said its a plugin causing the issue but how would it still work in the classic editor?

    Thread Starter andyt1980

    (@andyt1980)

    Whats really odd is if I press the preview button in the editor the map displays on the preview page, but if I press update and publish the change it doesn’t display on the published page. The div wrapper is there, just empty.

    Thread Starter andyt1980

    (@andyt1980)

    ok, so it seems I was getting the issue with the map not displaying at the bottom of the post because I was also trying to display another map full-width after the header using a Advanced Custom Fields to ‘inject’ the map after the header using a theme hook.

    Basically I have a Wysiwyg Editor ACF field for the map shortcode. I then call this field in the after_header hook like so:

    <div><?php the_field(‘map’); ?></div>

    And it’s this implementation of the shortcode which causes the JS error and prevents the map from displaying. So I’m now thinking it’s more likely an ACF field issue, but any advice would be appreciated.

    Thread Starter andyt1980

    (@andyt1980)

    ok nevermind it appears I wasn’t writing the shortcodes correctly.

    Now I’ve been able to test the plugin/maps correctly I have a few queries.

    – When adding a GPX is there no way for the map to zoom to the area where the GPX is located without having to manually add an address or coordinates?
    – I disabled mousewheel zoom and drag as I will be using full-width maps and don’t want people getting stuck on maps. When testing on mobile (safari), if you interact with the map using the zoom controls or pinch zooming then there is a delay before you can scroll past the map again.
    Ideally it would use this gesture handling leaflet plugin:
    https://github.com/elmarquis/Leaflet.GestureHandling
    Demo – https://elmarquis.github.io/Leaflet.GestureHandling/examples/
    This still allows scrollzoom on desktop and works perfectly on mobile

    • This reply was modified 6 years, 7 months ago by andyt1980.
    • This reply was modified 6 years, 7 months ago by andyt1980.
    Plugin Author bozdoz

    (@bozdoz)

    I was working on a function to zoom to all relevant layers, but I don’t think it’s finished. You could set the map center to the location, but I agree it’s not a great solution for dynamic maps. I’m not aware of a mobile delay.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Gutenberg Error’ is closed to new replies.