I have a layer with maxResolution set, such that the layer is displayed only when you zoom in at a certain level. My issue is that the layer source data is loaded only when zooming at that level. Is there a way to preload the vector source data?
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
});
You can load data over ajax and add to your source.
var source = new ol.source.Vector();
$.getJSON('/mapsource/source.geojson').done(function(data){
var features = (new ol.format.GeoJSON()).readFeatures(data);
source.addFeatures(features);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.