2015-11-04 89 views
1

我有一個設置了maxResolution的圖層,因此只有在您放大某個級別時才顯示該圖層。我的問題是,只有在該級別縮放時才加載圖層源數據。有沒有辦法預載矢量源數據?OL3:強制加載源

var source = new ol.source.Vector({ 
    url: '/mapsource/source.geojson', 
    format: new ol.format.GeoJSON() 
}); 

// how do I force loading the source here, and not wait for the map to render at 80 zoom? 

var layer = new ol.layer.Vector({ 
    title: 'Test layer', 
    source: source, 
    style: my_style, 
    maxResolution: 80 
}); 

回答

0

您可以通過ajax加載數據並添加到源代碼中。

var source = new ol.source.Vector(); 

$.getJSON('/mapsource/source.geojson').done(function(data){ 
    var features = (new ol.format.GeoJSON()).readFeatures(data); 
    source.addFeatures(features); 
});