2016-03-07 54 views
0

我已经把我的vectorSource这样的:打开图层3创建进度条装载机loadingstrategy.bbox

var vectorSource = function (date) { 
return new ol.source.Vector({ 
    // Start loader 
    loader: function (extent, resolution, projection) { 
     var url = 'urlpath?date=' + date; 
     // Show progress bar 
     $('#progress').fadeIn(); 
     $.ajax({ 
      url: url, 
      success: function (data) { 
       var format = new ol.format.GeoJSON(); 
       var features = format.readFeatures(data, function() { 
        featureProjection: 'EPSG:3857' 
       }); 
       var source = vectorSource(); 
       // Add the features not printing on the map but the data is there      
       source.addFeatures(features); 
       // When source is ready, then finish 
       if (source.getState() == 'ready') { 
        setTimeout(function() { 
         // Hide progress bar 
         $('#progress').fadeOut(750); 
        }, 1000) 
       } 
      } 
     }); 
    }, 
    strategy: ol.loadingstrategy.all, 
}); 

}

我可以读取功能,但我不能把它们打印成图。我试图看看它是投影问题还是尝试再次渲染地图,但不知道这个答案。

回答

0

这是一个ajax请求,您无法预测需要加载的时间,因此请创建一个进度条。相反,您已经准备好了start loadingend loading事件。

var vectorSource = new ol.source.Vector({ 
    loader: function (extent, resolution, projection) { 
     var url = requestedUrl; 
     alert("START loading here"); 
     $.ajax({ 
      url: url, 
      success: function (data) {     
       var features = geoJSONFormat.readFeatures(data); 
       vectorSource.addFeatures(features); 
       alert("FINISH loading here"); 
      } 
     }); 
    }, 
    strategy: ol.loadingstrategy.bbox 
}); 
+0

谢谢@pavlos。这是在用户等待加载所有功能时使用加载程序的最佳方法吗?理想情况下,地图baseLayer会立即加载,然后加载器隐藏一次所有的功能加载 –

+0

Hi @pavlos。由于我努力将特征打印到地图中,因此我编辑了原始问题。 –