0

I have displayed multiple tile layers in OpenLayers. Now I want to display layers name in the browser console on every zoom level.

This is my code:

var layers = [
  new ol.layer.Tile({
    source: new ol.source.OSM(),
    name: "osm",
  }),

  new ol.layer.Tile({
    //   extent: [-13884991, 2870341, -7455066, 6338219],
    source: new ol.source.TileWMS({
      url: "http://localhost:8080/geoserver/cite/wms",
      params: { LAYERS: "cite:india1", TILED: true },
      serverType: "geoserver",
      transition: 0,
      crossOrigin: "anonymous",
    }),
  }),

  new ol.layer.Tile({
    //   extent: [-13884991, 2870341, -7455066, 6338219],
    source: new ol.source.TileWMS({
      url: "http://localhost:8080/geoserver/cite/wms",
      // params: {'LAYERS': 'cite:india1,cite:india2,cite:india3,cite:india4,cite:india5,cite:india6,cite:india7,cite:india8,cite:india9,cite:india10,cite:india11,cite:india12,cite:india13,cite:india14,cite:india15,cite:india16', 'TILED': true},
      params: { LAYERS: "cite:india16", TILED: true },
      serverType: "geoserver",
      transition: 0,
      crossOrigin: "anonymous",
    }),
  }),

  new ol.layer.Tile({
    //   extent: [-13884991, 2870341, -7455066, 6338219],
    source: new ol.source.TileWMS({
      url: "http://localhost:8080/geoserver/cite/wms",
      // params: {'LAYERS': 'cite:india1,cite:india2,cite:india3,cite:india4,cite:india5,cite:india6,cite:india7,cite:india8,cite:india9,cite:india10,cite:india11,cite:india12,cite:india13,cite:india14,cite:india15,cite:india16', 'TILED': true},
      params: { LAYERS: "cite:india15", TILED: true },
      serverType: "geoserver",
      transition: 0,
      crossOrigin: "anonymous",
    }),
  }),
];

var map = new ol.Map({
  layers: layers,
  target: "map",
  view: new ol.View({
    center: [-85.685, 39.891],
    //   -85.685, 39.891
    // -10997148, 4569099
    zoom: 3,
  }),
});
2
  • 1
    I cannot really tell what you want to achieve. Please edit the question and provide e.g. screenshots or a more detailed description including what you have tried so far, then we can try to help with that.
    – til_b
    Dec 8, 2022 at 8:40
  • 3
    It's not clear what exactly do you mean by "display layers name in the browser console on every zoom level". Layers do not change with zoom change, so every time names of all the layers would be displayed.
    – TomazicM
    Dec 8, 2022 at 9:25

1 Answer 1

0

I think you need to set the name for layers instead of using name in the layer.

layers.set('name', 'your_layer_name');
var nameLayers = layers.get('name');
console.log(nameLayers);
4
  • I think @rajdip wants to display the layer names in the browser console, not as a symbol on the tiles.
    – til_b
    Dec 8, 2022 at 8:38
  • Oops! My bad. I was confused
    – Jayzz
    Dec 8, 2022 at 8:45
  • @Jayzz i wants layer name on browser console
    – rajdip
    Dec 8, 2022 at 8:58
  • I'm updated my answer.
    – Jayzz
    Dec 8, 2022 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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