我正在努力构建 OL3 Vector layer BBOX 策略加载。到目前为止,我可以使用有效的 json 语法轻松加载 Geojson 文件,但这是一次性策略。我的另一种方法是使用 ol.ServerVector ,对于我的理解,它会通过回调返回 Javascript,但我无法使其工作。
工作简单的 Geojson 层:
var vectorSource = new ol.source.GeoJSON(
({
projection: 'EPSG:3857',
preFeatureInsert: function(feature) {
feature.geometry.transform('EPSG:4326', 'EPSG:3857');
},
url: 'geojson2.json'
}));
Run Code Online (Sandbox Code Playgroud)
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
BBOX 尝试(移动时返回 json,但功能未加载到地图):
var vectorSource = new ol.source.ServerVector({
format: new ol.format.GeoJSON(),
loader: function(extent, resolution, projection) {
var url = 'geojson2.php?p='+
extent.join(',');
$.ajax({
url: url
});
},
strategy: ol.loadingstrategy.bbox,
projection: 'EPSG:3857',
});
// callback ?
var loadFeatures = …Run Code Online (Sandbox Code Playgroud)