Ele*_*ore 5 javascript leaflet
这是我用来在网站上绘制传单地图的功能:
function drawTweetMap(points) {
if (tweetMap != null)
tweetMap.remove();
var london = [51.505, -0.09];
tweetMap = L.map('tweetMap').setView(london, 5);
var cloudmadeUrl = 'http://{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg';
var subDomains = ['otile1','otile2','otile3','otile4'];
var cloudmadeAttrib = 'Data, imagery and map information provided by <a href="http://open.mapquest.co.uk" target="_blank">MapQuest</a>, <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank">CC-BY-SA</a>';
L.tileLayer(cloudmadeUrl,
{attribution: cloudmadeAttrib,
maxZoom: 18,
subdomains: subDomains})
.addTo(tweetMap);
var markers = L.markerClusterGroup();
var points_rand = L.geoJson(points, {onEachFeature: onEachFeature});
markers.addLayer(points_rand);
tweetMap.addLayer(markers);
tweetMap.fitBounds(markers.getBounds());
}
Run Code Online (Sandbox Code Playgroud)
定期调用此函数:
mapWatch = setInterval(function() {
retrieveCurrentTweetPositions()},
numMinutes*60*1000);
Run Code Online (Sandbox Code Playgroud)
在此功能中:
function retrieveCurrentTweetPositions() {
var points = retrieveCurrentPositions();
var mapInput = translatePointsInMapFormat(points);
drawTweetMap(mapInput);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果以此方式绘制地图,则结果如下:

在其他问题中,我发现可以使地图的大小无效以解决此问题,因此建议在启动此功能时调用它:
function updateTweetMapPosition() {
setTimeout(function(){
tweetMap.invalidateSize(true);}
,500)
}
Run Code Online (Sandbox Code Playgroud)
我这样做了,这解决了第一个地图绘制过程中的问题。但是,当我尝试第二次重绘地图时,结果如下:

有没有人遇到这个问题?如何重载完整内容的地图?
谢谢。
编辑
这是jsFiddle:http : //jsfiddle.net/qzpwvqzk/
| 归档时间: |
|
| 查看次数: |
12988 次 |
| 最近记录: |