question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add layer-group into control-layers

See original GitHub issue

In official documentation, Leaftlet shows me to use L.control.layers(baseMaps, overlayMaps).addTo(map); to add baseMaps and overlayMaps to control layer. How can I do that with l-layer-group and l-control-layers?

I checked the example, it has the only baseMaps option.

Make an example, I want to add this layer group, it is a set of markers, how do I add another checkbox on control-layers to become overlayMaps?

<l-tile-layer
    layerType="base"
    name="Default Base"
    :url="url"
/>
<l-layer-group :visible="sourceVisible">
    <l-marker
         v-for="(item, index) in sources"
         :key="index"
         :lat-lng="[item.coordinates[1], item.coordinates[0]]"
         :icon="sourceIcon(item.icon)"
         @l-click="onClick(item)"
    >
    </l-marker>
</l-layer-group>

Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
KoRiGaNcommented, Apr 4, 2018

Hi @sangdth,

The documentation is far from perfect and I want to add many examples of the official documentation to Vue2Leaflet documentation but didn’t have the time yet. You can add overlay to your control like this:

<l-control-layers></l-control-layers>
<l-tile-layer
    layerType="base"
    name="Default Base"
    :url="url"
/>
<l-layer-group 
    :visible="sourceVisible"
    layerType="overlay"
    name="Sources">
    <l-marker
         v-for="(item, index) in sources"
         :key="index"
         :lat-lng="[item.coordinates[1], item.coordinates[0]]"
         :icon="sourceIcon(item.icon)"
         @l-click="onClick(item)"
    >
    </l-marker>
</l-layer-group>

Let me know if this helps.

Micka

4reactions
KoRiGaNcommented, Apr 5, 2018

Hi @mujahidinside,

You must add

layer-type="overlay" 

for layers to be added as overlay layers in the control.

Read more comments on GitHub >

github_iconTop Results From Across the Web

adding layers in layer group dynamically to layer control in ...
In your ajax callback, you should find layerGroup = L.layerGroup() .addLayer(vector1)) .addLayer(vector2)) .addLayer(vector3)) .
Read more >
Layer Groups and Layers Control - Leaflet - Leaflet
This tutorial will show you how to group several layers into one, and how to use the layers control to allow users to...
Read more >
How to add layers and update layer control dynamically : leaflet
There are public methods in L.Control.Layers control to add base layers and overlays dinamically (see full reference):.
Read more >
L.LayerGroup
Used to group several layers and handle them as one. If you add it to the map, any layers added or removed from...
Read more >
Layers control | React Leaflet
</Marker>. </LayersControl.Overlay>. <LayersControl.Overlay checked name="Layer group with circles">. <LayerGroup> ... <Popup>Popup in FeatureGroup</Popup>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found