Less hackish tile loading; also works with empty data

This commit is contained in:
Andreas Hocevar
2017-01-19 19:30:34 +01:00
committed by GitHub
parent b0b0e94d89
commit 7f5e1e2e62

View File

@@ -67,23 +67,22 @@ fetch(url).then(function(response) {
format: new ol.format.GeoJSON(),
tileGrid: ol.tilegrid.createXYZ(),
tilePixelRatio: 16,
tileLoadFunction: function(tile, tileCoord) {
tileLoadFunction: function(tile) {
var format = tile.getFormat();
var data = tileIndex.getTile.apply(tileIndex, tileCoord);
var tileCoord = tile.getTileCoord();
var data = tileIndex.getTile(tileCoord[0], tileCoord[1], -tileCoord[2] - 1);
var features = format.readFeatures(
JSON.stringify({
type: 'FeatureCollection',
features: data.features
features: data ? data.features : []
}, replacer));
tile.setLoader(function() {
tile.setFeatures(features);
tile.setProjection(tilePixels);
});
},
tileUrlFunction: function(tileCoord) {
return [tileCoord[0], tileCoord[1], -tileCoord[2] - 1];
}
url: 'data:' // arbitrary url, we don't use it in the tileLoadFunction
});
var vectorLayer = new ol.layer.VectorTile({
source: vectorSource