proper implementation of invalidateSize() to display mapbox/leaflet on mobile device

心不动则不痛 提交于 2019-12-09 03:38:28

What does the styling look like on $('map')? I see your inline CSS, but is there anything else on it? Try giving it a size to be sure everything else is working first.

Also, if you are using any kind of CSS animation to resize the map container, you need to wait until after the animation is done, e.g.:

window.setTimeout(function() {
    map.invalidateSize();
}, 1000);

Why not start out with the most basic map you can get and go from there. First check if the code posted below works, then change it to your token en mapid, test again, add the layercontrol, test again etc. Add one feature at a time and keep testing, you'll find out where it goes wrong then easily. That's at the moment hard to guess without your full code and a proper testcase on Plunker or JSfiddle or somewhere else where we could test it.

<!DOCTYPE html>
<html>
    <head>
        <meta charset=utf-8 />
        <title>A simple map</title>
        <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
        <script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
        <link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css' rel='stylesheet' />
        <style>
            body { margin:0; padding:0; }
            #map { position:absolute; top:0; bottom:0; width:100%; }
        </style>
    </head>
    <body>
        <div id='map'></div>
        <script>
            L.mapbox.accessToken = 'pk.eyJ1IjoicGF1bC12ZXJob2V2ZW4iLCJhIjoiZ1BtMWhPSSJ9.wQGnLyl1DiuIQuS0U_PtiQ';
            var map = L.mapbox.map('map', 'examples.map-i86nkdio').setView([40, -74.50], 9);
        </script>
    </body>
</html>

Taken from: https://www.mapbox.com/mapbox.js/example/v1.0.0/

the maps now work.

the issue was http/https. two things had to be changed.

1) the method of calling the tiles and associated php script initially, i used tileserver.php to call

'Streets':L.tileLayer('[url]url/[mbtiles file name].tilejson' 

now i'm using mbtiles-server.php to call

'Streets':L.tileLayer("[url]/mbtiles-server.php?db=[mbtiles file name].mbtiles&z={z}&x={x}&y={y}.png") 

note: php script had to be in the same folder/directory as the mbtiles file. also, replace text in [] with your own

2) leaflet css/js was used only, no mapbox as the api uses a secure key

much thanks again @iH8 for the excellent work!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!