I have a map where i'm loading several WMS layers from different urls. I'm trying to figure out a way to turn each layer on/off by an identifier, but i can't figure out how to add a unique identifier to the layer, or source of the layer. Basically i have:

for (const entry of entries) {
    const tileWMSOptions = {
              url: entry.URL,
              params: { LAYERS: layerNames, TILED: true },  
            const layer = new TileLayer({
              source: new TileWMS(tileWMSOptions),

my 'entry' object has an ID that i would like to associate with this layer, so that i can do some sort of


run through them, and do something specific if the id of that layer matches what i'm looking for. I don't see any way of doing this from https://openlayers.org/en/latest/apidoc/module-ol_layer_Tile-TileLayer.html or https://openlayers.org/en/latest/apidoc/module-ol_source_TileWMS.html . Any ideas?

1 Answer 1


You can include your own properties in the layer (similar to title in the documentation http://openlayers.org/en/latest/apidoc/module-ol_layer_Tile-TileLayer.html )

layer = new TileLayer({
              source: new TileWMS(tileWMSOptions),
              guid: guid

and retrieve using .get

  • Thanks, dumb mistake. Forget i'm working in javascript sometimes!
    – Phil
    Sep 22, 2018 at 22:00

Your Answer

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

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