传单加载不完整的地图
leaflet loads incomplete map
我正在将传单地图动态添加到 div。地图只显示了一部分,见图。一旦我调整了浏览器 window 的大小,地图就完全显示出来了。有没有解决的办法?我尝试了一些初步想法,请参阅代码中的 //。但其中 none 有效。incomplete map
function mapThis(lat,long,wikiTitle){
var div_Id= "#wikiExtract"+wikiTitle
var map_Id= "map"+wikiTitle
$(div_Id).append("<div id='"+map_Id+"' style='width: 600px; height:
400px'></div>");
var map = L.map(map_Id).setView([lat, long], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a
href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-
SA</a>'
}).addTo(map);
//$("#"+map_Id).css( "height", "500px" );
//map.invalidateSize()
//$("#"+map_Id).hide()
//$("#"+map_Id).show()
//$(window).trigger('resize');
}
如果地图至少可以正常工作(除了不完整的图块加载),您可以在地图的 div
容器显示/插入 [=16= 后简单地调用 map.invalidateSize()
] 最终尺寸。
Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default.
您可以使用此代码:
它对我有用。
setInterval(function () {
map.invalidateSize();
}, 100);
如果使用 JQuery,文档准备就绪后,以下代码会更新大小:
$(document).ready(function () {
mymap.invalidateSize();
});
我正在将传单地图动态添加到 div。地图只显示了一部分,见图。一旦我调整了浏览器 window 的大小,地图就完全显示出来了。有没有解决的办法?我尝试了一些初步想法,请参阅代码中的 //。但其中 none 有效。incomplete map
function mapThis(lat,long,wikiTitle){
var div_Id= "#wikiExtract"+wikiTitle
var map_Id= "map"+wikiTitle
$(div_Id).append("<div id='"+map_Id+"' style='width: 600px; height:
400px'></div>");
var map = L.map(map_Id).setView([lat, long], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a
href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-
SA</a>'
}).addTo(map);
//$("#"+map_Id).css( "height", "500px" );
//map.invalidateSize()
//$("#"+map_Id).hide()
//$("#"+map_Id).show()
//$(window).trigger('resize');
}
如果地图至少可以正常工作(除了不完整的图块加载),您可以在地图的 div
容器显示/插入 [=16= 后简单地调用 map.invalidateSize()
] 最终尺寸。
Checks if the map container size changed and updates the map if so — call it after you've changed the map size dynamically, also animating pan by default.
您可以使用此代码: 它对我有用。
setInterval(function () {
map.invalidateSize();
}, 100);
如果使用 JQuery,文档准备就绪后,以下代码会更新大小:
$(document).ready(function () {
mymap.invalidateSize();
});