I have a series of tile sources equating to different map providers at specific resolutions and I would like to set an extent so that when the relevant layer is selected, the map pans and zooms to the extent of the tiles.
Following this example I've set the extent for each source. I'm also able to get the extent of the selected layer using this code in my layerswitcher control:
curExtent = map.getView().calculateExtent(map.getSize());
if (extent != null) {
extent = layers[s].getExtent();
}
else {
extent = map.getView().calculateExtent(map.getSize());
}
layerZoom = layers[s].getProperties().minZoom;
map.getView().fit(extent, map.getSize());
layers[s].setVisible(true);
I'm able to get the resolution/zoom at this point but I'm not sure how to set the view to the minResolution/zoom property of each source. Can anyone please help?
Further to this I'm now able to get the map to pan and zoom but the layer tiles don't appear. I thought it was a projection issue but I'm in the right location and zoom. Do I need to delay loading of the tiles maybe?
Here is the amended code:
var curExtent = map.getView().calculateExtent(map.getSize());
if (title == selectedValue) {
if (extent != []) {
extent = layers[s].getExtent();
}
else {
extent = curExtent;
}
console.log(extent);
layerZoom = layers[s].getProperties().minZoom;
var sourceCentre = ol.extent.getCenter(extent);
console.log(sourceCentre);
console.log(layerZoom);
console.log(curExtent);
console.log(extent);
map.getView().setCenter(sourceCentre);
map.getView().setZoom(layerZoom);
layers[s].setVisible(true);
}
else {
layers[s].setVisible(false);
}
I've set up a simple fiddle which now seems to work although I'm struggling to get the extent of the other standard map layers and the functionality seems to break after the initial successful action.
ol.layer.Tile
?