Fix language (#5022)
1. Improve some of the language to be more readable 2. Correct reference to night style base map, which isn't actually used 3. Add detail that it's possible to style the text in the control
This commit is contained in:
parent
a97b87d033
commit
d135fc4527
@ -26,9 +26,11 @@ Easy enough! Now you have a `cities` layer that combines your city markers into
|
||||
|
||||
### Layers Control
|
||||
|
||||
Leaflet has a nice little control that allows your users control what layers they want to see on your map. In addition to showing you how to use it, we'll show another handy use for layer groups.
|
||||
Leaflet has a nice little control that allows your users to control which layers they see on your map. In addition to showing you how to use it, we'll also show you another handy use for layer groups.
|
||||
|
||||
There are two types of layers --- base layers that are mutually exclusive (only one can be visible on your map), e.g. tile layers, and overlays --- all the other stuff you put over the base layers. In this example, we want to have two base layers (grayscale and night-style base map) to switch between, and an overlay to switch on and off --- city markers (those we created earlier). Let's create those layers and add the default ones to the map:
|
||||
There are two types of layers: (1) base layers that are mutually exclusive (only one can be visible on your map at a time), e.g. tile layers, and (2) overlays, which are all the other stuff you put over the base layers. In this example, we want to have two base layers (a grayscale and a colored base map) to switch between, and an overlay to switch on and off: the city markers we created earlier.
|
||||
|
||||
Now let's create those base layers and add the default ones to the map:
|
||||
|
||||
<pre><code>var grayscale = L.tileLayer(mapboxUrl, {id: '<a href="https://mapbox.com">MapID</a>', attribution: mapboxAttribution}),
|
||||
streets = L.tileLayer(mapboxUrl, {id: '<a href="https://mapbox.com">MapID</a>', attribution: mapboxAttribution});
|
||||
@ -39,7 +41,7 @@ var map = L.map('map', {
|
||||
layers: [grayscale, cities]
|
||||
});</code></pre>
|
||||
|
||||
Next, we'll create two objects. One will contain our base layers and one will contain our overlays. These are just simple objects with key/value pairs. The key is what sets the text for the layer in the control (e.g. "Streets"). The corresponding value is a reference to the layer (e.g. `streets`).
|
||||
Next, we'll create two objects. One will contain our base layers and one will contain our overlays. These are just simple objects with key/value pairs. The key sets the text for the layer in the control (e.g. "Streets"), while the corresponding value is a reference to the layer (e.g. `streets`).
|
||||
|
||||
<pre><code>var baseMaps = {
|
||||
"Grayscale": grayscale,
|
||||
@ -50,7 +52,7 @@ var overlayMaps = {
|
||||
"Cities": cities
|
||||
};</code></pre>
|
||||
|
||||
Now, all that's left to do is to create a [Layers Control](../../reference.html#control-layers) and add it to the map. The first argument passed when creating the layers control is the base layers object. The second argument is the overlays object. Both arguments are optional --- for example, you can pass just a base layers object by omitting the second argument, or just an overlays objects by passing `null` as the first argument.
|
||||
Now, all that's left to do is to create a [Layers Control](../../reference.html#control-layers) and add it to the map. The first argument passed when creating the layers control is the base layers object. The second argument is the overlays object. Both arguments are optional: you can pass just a base layers object by omitting the second argument, or just an overlays objects by passing `null` as the first argument. In each case, the omitted layer type will not appear for the user to select.
|
||||
|
||||
<pre><code>L.control.layers(baseMaps, overlayMaps).addTo(map);</code></pre>
|
||||
|
||||
@ -58,5 +60,13 @@ Note that we added `grayscale` and `cities` layers to the map but didn't add `st
|
||||
|
||||
Also note that when using multiple base layers, only one of them should be added to the map at instantiation, but all of them should be present in the base layers object when creating the layers control.
|
||||
|
||||
Finally, you can style the keys when you define the objects for the layers. For example, this code will make the label for the grayscale map gray:
|
||||
|
||||
<pre><code>var baseMaps = {
|
||||
"<span style='color: gray'>Grayscale</span>": grayscale,
|
||||
"Streets": streets
|
||||
};
|
||||
</code></pre>
|
||||
|
||||
Now let's [view the result on a separate page →](example.html)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user