javascript - Leaflet map background tiles appear as broken links -
good day! have little project going , need have map in website. fine , except 1 detail: background tiles appear broken links no apparent (to me) reason. , appreciated :) here's picture:
html code:
<html> <head> <link rel="stylesheet" type="text/css" href="bootstr/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="dizainas.css"> <link rel="stylesheet" href="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.css"> <script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-bbhdlvqf/xty9gja0dq3hiwqf8lacrtxxzkrutelt44=" crossorigin="anonymous"></script> </head> <body> <!-- <div id="mapas"></div> --> <div class="navbar navbar-inverse navbar-fixed-top" role="navigation"> <div class="container-fluid"> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li> <a>menu item 1</a> </li> <li> <a>menu item 2</a> </li> </ul> </div> </div> </div> <div id="container"> <div id="sidebar"> <div class="sidebar-wrapper"> <div id="features" class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">sidebar header</h3> </div> </div> </div> </div> <div id="mapas"></div> </div> <script src="bootstr/js/bootstrap.min.js"></script> <script src="https://npmcdn.com/leaflet@1.0.0-rc.2/dist/leaflet.js"></script> <script src="mechanika.js"></script> </body> </html>
css:
@import 'https://fonts.googleapis.com/css?family=slabo+27px'; html, body, #container { height: 100%; width: 100%; overflow: hidden; font-family: 'slabo 27px', serif; } body { cursor:url(http://i.imgur.com/aysurdr.png), auto; padding-top: 50px; background-color: lightgray; } .navbar { min-height: 50px; } #sidebar { float: left; height: 100%; max-width: 100%; width: 150px; } .sidebar-wrapper { height: 100%; position: relative; width: 100%; } @media (max-width: 767px) { #sidebar { display: none; } } #mapas { height: 100%; width: auto; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); /* background-color:rgba(0,0,0,1);*/ background: #000000; }
javascript:
console.log("nu veikia"); var map = l.map('mapas').setview([0, 0], 2); l.tilelayer('/users/domas/desktop/mapas/{z}/{x}/{y}.png', { minzoom: 2, maxnativezoom: 5, maxzoom: 6, attribution: 'eso/inaf-vst/omegacam', nowrap: true }).addto(map); var bounds = l.latlngbounds([[84, 173], [-84, -173]]); map.setmaxbounds(bounds); map.on('drag', function() { map.paninsidebounds(bounds, { animate: false }); }); console.log(map.getbounds());
as seem use custom map (custom tiles), did make sure provide tiles areas have 404 errors?
you can open browser developer tools (on pc, use f12 / on mac, use cmd + alt + i) see url of missing tiles.
if not have tiles , not want provide them, can specify bounds of custom tile layer, leaflet not try download tiles outside area.
use bounds
option of tile layer.
note option independent map's maxbounds
option / setmaxbounds()
method, applies entire map, , affects user interaction (where user can pan to).
Comments
Post a Comment