Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I had used the following layers in leaflet,now i want to switch between the 4 layers ,please tell the code to create a layer switcher control in leaflet

// night layer
//var osmUrl = 'http://{s}.tile.cloudmade.com/a7db5562d0cd4fe0a2d8983fbb3b5519/999/256/{z}/{x}/{y}.png',


//golden layer
var osmUrl = 'http://{s}.tile.cloudmade.com/a7db5562d0cd4fe0a2d8983fbb3b5519/997/256/{z}/{x}/{y}.png'

//black layer
//var osmUrl = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png',

osmAttribution = 'Map data &copy; 2012 <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
share|improve this question
    
How you read the tutorial? –  R.K. Aug 25 '13 at 14:14
    
Welcome to GIS SE! You might want's to read this Leaflet tutorial leafletjs.com/examples/layers-control.html It addresses pretty much what you need. Please read the docs before asking a question next time. –  R.K. Aug 25 '13 at 14:24
    
R.K. you're right. I just hate saying "Read the Docs" sometimes –  geomajor56 Aug 25 '13 at 14:39
    
@geomajor56 Yeah. I hate doing it too but this one's featured prominently in the docs. I just wish the OP went through the tutorial before asking. It's rather brief. A little effort goes a long way. –  R.K. Aug 25 '13 at 14:50
add comment

1 Answer

First, you'll need to rename your basemaps differently:

// night layer
var night = http://{s}.tile.cloudmade.com/a7db5562d0cd4fe0a2d8983fbb3b5519/999/256/{z}/{x}/{y}.png',

//golden layer
var golden = 'http://{s}.tile.cloudmade.com/a7db5562d0cd4fe0a2d8983fbb3b5519/997/256/{z}/{x}/{y}.png'

//black layer
var black = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png',

Then use the Layer Control option as shown in this Leaflet Example.

I haven't tried this plugin, but it's a different type of control for selecting layers.

Hope this gets you started.

share|improve this answer
add comment

Your Answer

 
discard

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.