Less hackish tile loading; also works with empty data
This commit is contained in:
@@ -67,23 +67,22 @@ fetch(url).then(function(response) {
|
|||||||
format: new ol.format.GeoJSON(),
|
format: new ol.format.GeoJSON(),
|
||||||
tileGrid: ol.tilegrid.createXYZ(),
|
tileGrid: ol.tilegrid.createXYZ(),
|
||||||
tilePixelRatio: 16,
|
tilePixelRatio: 16,
|
||||||
tileLoadFunction: function(tile, tileCoord) {
|
tileLoadFunction: function(tile) {
|
||||||
var format = tile.getFormat();
|
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(
|
var features = format.readFeatures(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: data.features
|
features: data ? data.features : []
|
||||||
}, replacer));
|
}, replacer));
|
||||||
tile.setLoader(function() {
|
tile.setLoader(function() {
|
||||||
tile.setFeatures(features);
|
tile.setFeatures(features);
|
||||||
tile.setProjection(tilePixels);
|
tile.setProjection(tilePixels);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
tileUrlFunction: function(tileCoord) {
|
url: 'data:' // arbitrary url, we don't use it in the tileLoadFunction
|
||||||
return [tileCoord[0], tileCoord[1], -tileCoord[2] - 1];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
var vectorLayer = new ol.layer.VectorTile({
|
var vectorLayer = new ol.layer.VectorTile({
|
||||||
source: vectorSource
|
source: vectorSource
|
||||||
|
|||||||
Reference in New Issue
Block a user