I found this simple openlayers example online , the map initialization looks like below:
var styles = [
'Road',
'Aerial',
'AerialWithLabels',
'collinsBart',
'ordnanceSurvey'
];
var layers = [];
var i, ii;
for (i = 0, ii = styles.length; i < ii; ++i) {
layers.push(new ol.layer.Tile({
visible: false,
preload: Infinity,
source: new ol.source.BingMaps({
key: 'Ak-dzM4wZjSqTlzveKz5u0d4IQ4bRzVI309GxmkgSVr1ewS6iPSrOvOKhA-CJlm3',
imagerySet: styles[i]
// use maxZoom 19 to see stretched tiles instead of the BingMaps
// "no photos at this zoom level" tiles
// maxZoom: 19
})
}));
}
var map = new ol.Map({
layers: layers,
// Improve user experience by loading tiles while dragging/zooming. Will make
// zooming choppy on mobile or slow devices.
loadTilesWhileInteracting: true,
target: 'map',
view: new ol.View({
center: [-6655.5402445057125, 6709968.258934638],
extent: [-16655.5402445057125, 6609968.258934638,0,6809968],
maxZoom: 20,
minZoom:13,
zoom: 13
})
});
var select = document.getElementById('layer-select');
function onChange() {
var style = select.value;
for (var i = 0, ii = layers.length; i < ii; ++i) {
console.log( layers[i].getSource().item(1) + " " + styles[i] );
layers[i].setVisible(styles[i] === style);
}
}
select.addEventListener('change', onChange);
onChange();
Now what i really was trying to do was , i wanted to console.log the imagerySet
of every layer , inside the below peice of code:
function onChange() {
var style = select.value;
for (var i = 0, ii = layers.length; i < ii; ++i) {
console.log( layers[i].getSource().item(1) + " " + styles[i] );
layers[i].setVisible(styles[i] === style);
}
}
I tried the below few method:
layers[i].getSource().item(1);
and
layers[i].getSource().getImagerySet();
but it does't give me the desired result , can anybody corrent me and tell me whats the correct way to imagerySet
inside the loop ?