简体   繁体   English

如何使用mapstraction延迟标记加载openlayers地图

[英]how to delay marker loading openlayers map with mapstraction

I have a page with displays 10 markers in an openlayers map used via mapstraction. 我有一个页面,该页面在通过mapstraction使用的openlayers地图中显示10个标记。

I want to load map first then marker one by one say after every second, I tried using window.setTimeout() it loads the map and loads only first marker after that it stops. 我想先加载地图,然后每秒钟一遍又一遍地说一遍,我尝试使用window.setTimeout()来加载地图,并且在它停止后仅加载第一个标记。

  var map;
  var lat = new Array() ;
  lat=${latitude};
  var lon= new Array();
  lon=${longitude};
  var oneByOneCounter=0;
  var count=10;
  function initMap(){  
       map = new Mapstraction('mymap','openlayers');
       map.setCenter(new LatLonPoint(0.0,0.0));
       map.addControls({pan: true, zoom:'small', map_type:true});
       renderMarkerOneByOne();
       map.autoCenterAndZoom();
     };


   function renderMarkerOneByOne() {
   if (oneByOneCounter < count) {
       latitude= lat[oneByOneCounter];
       longitude= lon[oneByOneCounter];
       var point = new LatLonPoint(latitude,longitude);
       var marker = new Marker(point);
       var info = "("+(oneByOneCounter+1)+")";
       marker.setInfoBubble(info);
       marker.setHover(true);
       marker.setIcon('icon_green.png', [27,31]);
       map.addMarker(marker);    
       oneByOneCounter++;
       window.setTimeout("renderMarkerOneByOne()", 1000);
     } else {
       oneByOneCounter = 0;
    }
   }

I am not able to figure out where I am doing wrong renderMarkerOneByOne() function executes properly and on putting alert() I can see the marker object is getting created all the time but, for some reason after the first marker gets plotted the other markers are not getting plotted on the map. 我无法弄清楚我在哪里做错了renderMarkerOneByOne()函数正确执行,并在放置alert()时可以看到一直在创建标记对象,但是由于某些原因,第一个标记被绘制后,其他标记就被创建了没有在地图上标绘。

Any help or suggestion is welcomed 欢迎任何帮助或建议

Thanks 谢谢

尝试使用setInterval()代替setTimeout()。

It has to be something like this 一定是这样的

var map;
var lat = new Array() ;
lat=${latitude};
var lon= new Array();
lon=${longitude};
var oneByOneCounter=0;
var count=10;
var centerPoint;
function initMap(){  
   map = new Mapstraction('mymap','openlayers');    
   map.addControls({pan: true, zoom:'small', map_type:true});
  centerPoint= new LatLonPoint(lat[0],lon[0]);// or any point anyone wants to put center
   renderMarkerOneByOne();
   map.setCenterAndZoom(centerPoint,"desired zoom level");
 };

I found the solution after wasting too much time on debugging the code. 在浪费太多时间调试代码之后,我找到了解决方案。 Lots of mapstraction functions doesn't work properly with openlayers api 许多Mapstraction函数无法与Openlayers API一起正常使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM