1

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 ?

FIDDLE HERE

1 Answer 1

2

imagerySet is a specific attribute for bing maps. It wont work in any other tile type. getImagerySet wont work as there is no such function documented on ol3. Also seems that ol3 have no function to retrieve the bing image type. You can always pass a custom attribute during layer initilasation and the retrive it using the get method. Check the following fiddle I use myattribute on layer and pass the styles[i] value. Then I can get this value using layers[i].get('myattribute')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.