Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm adding a Stamen basemap to OpenLayers using the syntax below. Is it possible to change the layer's name, so that it appears in the Layer Switcher using this name (rather than "toner")?

The OpenLayers layer.setName method doesn't seem to work.


    <title> OpenLayers</title>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
        var map, layer;
        function initialize() {
            map = new OpenLayers.Map('map', {controls: [new OpenLayers.Control.LayerSwitcher({})]});
            stamenLayer = new OpenLayers.Layer.Stamen("toner");
            stamenLayer.setName = "custom layer name";
            map.setCenter(new OpenLayers.LonLat(-13630355, 4546576), 10);

    <style type="text/css">
        #map {
            width: 800px;
            height: 600px;
<body onload="initialize()">
    <div id="map"></div>

share|improve this question
setName is a need to try stamenLayer.setName("custom layer name"); – ca0v Aug 27 '12 at 13:44
@ca0v thanks - you should have put that as an answer cos you're right! – Stephen Lead Aug 27 '12 at 22:14
up vote 6 down vote accepted

Try to change the name of the layer after adding the layer.

Here it works:

write in console:

 map.addControl(new OpenLayers.Control.LayerSwitcher)


share|improve this answer

Looking at the source for the Stamen layer it seems the name is used to determine the provider:

OpenLayers.Layer.Stamen = OpenLayers.Class(OpenLayers.Layer.OSM, {
    initialize: function(name, options) {
        var provider = getProvider(name),
            url = provider.url

And finally the OSM constructor is invoked:

        return, name, hosts, options);

So it does seem that setName is the better option since you need the first parameter to match something in this PROVIDERS list:

        "toner":        MAKE_PROVIDER("toner", "png", 0, 20),
        "terrain":      MAKE_PROVIDER("terrain", "jpg", 4, 18),
        "watercolor":   MAKE_PROVIDER("watercolor", "jpg", 3, 16)
share|improve this answer

I've never used layer.setName before but if you want a custom name in the Layer Switcher:

stamenLayer = new OpenLayers.Layer.Stamen("whatever you type here 
                                           will show up in the layer switcher");
share|improve this answer
Thanks for the tip, however I don't believe this will actually work. As far as I can see, you need to use one of their supported keywords (toner, toner-lite, watercolor, etc) in order to specify a Stamen map – Stephen Lead Aug 27 '12 at 22:18

check out this:

map.layers[0].name = "newLayerName";
map.controls[4].redraw();  // OpenLayers.Control.LayerSwitcher

i hope it helps you...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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