This is a default map without layers control

This is a map with different base layers

In this example a layer model is defined. A layer model is defined by objects containing the properties of the layers.
The base layers are defined in the baselayers object inside the layers definition:

layers: {
    baselayers: {
        mapOne: {... map properties ...},
        mapTwo: {... map properties ...},
        ...
        mapN: {... map properties ...}
    },
    overlays: {
        overlayOne: {... overlay properties ...},
        overlayTwo: {... overlay properties ...},
        ...
        overlayM: {... overlay properties ...}    }
}
            

A baselayer object must contain the map properties

  • name: The display name in the layer control
  • type: The type of layer. The supported values are: 'xyz' and 'wms'
  • url: The url of the map service to use
It can also contain optional properties
  • top: This map layer will be on the top, making it visible. Possible values: true , falseThere can only be one top baselayer on a map. If this property is not present or all are false, the first defined baselayer map will be the top one. If more than one layer have the top set to true the last layer defined will be the visible.
  • layerParams: Additional parameters used in the baselayer url
  • layerOption: Options of the Leaflet layer

Note:

The code below is the definition of baselayers in this example.

Layers osm and cycle do not define any specific parameters, only options. Layers cloudmade define layer parameters that are included in the url.

baselayers: {
    osm: {
        name: 'OpenStreetMap',
        type: 'xyz',
        url: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
        layerOptions: {
            subdomains: ['a', 'b', 'c'],
            attribution: '© OpenStreetMap contributors',
            continuousWorld: true
        }
    },
    cycle: {
        name: 'OpenCycleMap',
        type: 'xyz',
        url: 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png',
        layerOptions: {
            subdomains: ['a', 'b', 'c'],
            attribution: '© OpenCycleMap contributors - © OpenStreetMap contributors',
            continuousWorld: true
        }
    },
    cloudmade1: {
        name: 'Cloudmade Night Commander',
        type: 'xyz',
        url: 'http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png',
        layerParams: {
            key: '007b9471b4c74da4a6ec7ff43552b16f',
            styleId: 999
        },
        layerOptions: {
            subdomains: ['a', 'b', 'c'],
            continuousWorld: true
        }
    },
    cloudmade2: {
        name: 'Cloudmade Tourist',
        type: 'xyz',
        url: 'http://{s}.tile.cloudmade.com/{key}/{styleId}/256/{z}/{x}/{y}.png',
        layerParams: {
            key: '007b9471b4c74da4a6ec7ff43552b16f',
            styleId: 7
        },
        layerOptions: {
            subdomains: ['a', 'b', 'c'],
            continuousWorld: true
        }
    }
}
            

Consider:

You can define the layers model or not, using the default tile layer or the defined in your layer models, but you can't switch from one to another. So if you delete your layers model (after using it) you will end up with errors and warnings in your console, and probably your map will fail to response. If you use the defaults and later create a layers model, it will be ignored.
minZoom, and maxZoom defined in the layers override the minZoom, and maxZoom of the whole map, so if you do not define them a 0-18 zooms Leaflet defaults will be used.

This is a map with dynamic addition and deletion of layers

This is a map with WMS and XYZ layers

Be careful with WMS layers:

Most WMS layers (that are more intended for GIS applications than for slippy maps) do not use the EPSG:3857 (EPSG:900913) Spherical Mercator projection. This will lead to error in the map and you won't see anything. Although you set the srs option in the layer, Leaflet won't reproject it (as almost do all map viewers).
At this moment the EPSG:3857 projection is the only supported by the leaflet directive. If you need other SRSs please consider contributing to the project including in the directive support for the Proj4 Leaflet plugin