Lay Theme Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Search

    Integrate mapbox map

    General Discussion
    2
    5
    34
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Walker
      Walker last edited by Walker

      Hi there,
      I want to integrate a mapbox map into a page.

      I have tried a lot but I can't get it done.

      Here is the way I tried to do it.
      (here is also a simple instruction from mapbox: https://www.mapbox.com/install/javascript/cdn-install/)

      In the custom head area I copied this:

      <script src='https://api.mapbox.com/mapbox-gl-js/v2.9.1/mapbox-gl.js'></script>
      <link href='https://api.mapbox.com/mapbox-gl-js/v2.9.1/mapbox-gl.css' rel='stylesheet' />
      
      <script>
        mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
        var map = new mapboxgl.Map({
          container: 'map',
          style: 'mapbox://styles/mapbox/streets-v11'
        });
      </script>
      

      In the specific page where the map should show up, I inserted a html with the following:

      <div id='map' style='width: 400px; height: 300px;'></div>
      

      Thats it, but nothing will appear on the site.
      ––––
      When I insert the Div into the custom head area it works, but then the map is globaly on every page.

      I think this should be not too complicated.
      If anybody can help I would be very happy.

      Thanks

      1 Reply Last reply Reply Quote 0
      • arminunruh
        arminunruh Global Moderator last edited by arminunruh

        insert this:

        <script>
          mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
          var map = new mapboxgl.Map({
            container: 'map',
            style: 'mapbox://styles/mapbox/streets-v11'
          });
        </script>
        

        into "html at bottom"

        Walker 1 Reply Last reply Reply Quote 0
        • Walker
          Walker @arminunruh last edited by

          Hi @arminunruh,
          thanks for the answer.

          I changed the code, but didn't work.

          I have the feeling the problem is the div which I insert into the certain page. Here is a picture how I did it.
          dfdf.png

          The interesting part is, when I put all the code I posted above into the custom head area (also the "div id=map ...") then the map appears. But on every page and always ...

          1 Reply Last reply Reply Quote 0
          • arminunruh
            arminunruh Global Moderator last edited by arminunruh

            well the div markup is wrong too

            <div id="map"></div>

            u're missing a >

            why don't u try and do it exactly like they did in the tutorial?
            they didnt put all of the javascript in the <head>.

            they put part of it after the <div id="map"></div>

            if u do so make sure to activate compatibility mode in lay options (all the way at the bottom)

            Walker 1 Reply Last reply Reply Quote 0
            • Walker
              Walker @arminunruh last edited by

              Thanks a lot for you time!

              Now it works. 😘

              1 Reply Last reply Reply Quote 1
              • First post
                Last post
              Post a link to where the problem is if possible, please <3
              I don't answer or check forum DMs, please just post on the forum.
              Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com

              Before you post:

              Use the Search Feature. Maybe there is already a solution to your issue.

              1. Update Lay Theme and all Lay Theme Addons
              2. Disable all Plugins
              3. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code ", click "Save Changes"
              4. When using a WordPress Cache plugin, disable it or clear your cache. Now see if your problem solved itself.
              Go here, see if your problem is listed here:
              Troubleshooting

              When you post:
              1. Post a link to where the problem is
              2. If the problem is difficult to explain, post screenshots / link to a video to explain it

              Thanks!

              Online Users

              J
              O
              M

              Recent Topics

              • Search as icon instead of text?

              • FILTER Categories showing all projects

              • H

                Vimeo embed with autoplay and loop is really slow...help!

              • A

                website not loading on iphone safari

              laytheme.com