javascript - Leaflet.js: Remove map and show error message? -
i'm using mapbox.js v2.1.1. want check if layer valid, , if not, remove map , show friendly error message.
i can remove map ok, can't error message show in place - see white box.
this js:
var map = l.mapbox.map('map', 'mapbox.streets').setview([52.905, -1.79], 6); var layer = l.mapbox.featurelayer() .loadurl(url) .on('ready', function() { if !(layer.getbounds().isvalid()) { map.remove(); $('#map').html("location unknown"); } }) .addto(map);
my html <div id="map-ccg"></div>
.
so think map.remove()
working fine, html not appearing in place.
what doing wrong?
i guess add new div under map , set html of instead, seems fiddly. must common requirement, there inbuilt leaflet way of doing this?
this might stupid question, if html looks <div id="map-ccg"></div>
, why doing $('#map')
instead of $('#map-ccg')
?
Comments
Post a Comment