Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Setting control layers #46

Open
arjenmeijer opened this issue Mar 7, 2019 · 3 comments
Open

Setting control layers #46

arjenmeijer opened this issue Mar 7, 2019 · 3 comments

Comments

@arjenmeijer
Copy link

arjenmeijer commented Mar 7, 2019

I am trying to add tilelayers combined with the Markercluster plugin.
This is working and provided as documentation:
...
use dosamigos\leaflet\layers\TileLayer;
use dosamigos\leaflet\controls\Layers;
...
$center = new LatLng(['lat' => (float)$latitude, 'lng' => (float)$longitude]);

$openstreet = new TileLayer([
'urlTemplate' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'clientOptions' => [
OpenStreetMap contributors'
]
]);

$arogis = new TileLayer([
'urlTemplate' => 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
'clientOptions' => [
OpenStreetMap contributors'
]
]);

$baseLayers = new Layers();
$baseLayers->setBaseLayers(['Card' => $openstreet, 'Photo' => $arogis]);

$leaflet = new LeafLet([
'tileLayer' => $openstreet,
'center' => $center,
'zoom'=> 13,
]);

$leaflet
->setControls([$baseLayers]);

Adding Markercluster works also.

$cluster = new MarkerCluster([
'url' => Url::to(['you rur lreturning json']),
]);
and changing $leaflet to:
$leaflet
->setControls([$baseLayers]);
$leaflet
->installPlugin($cluster);

Do to:
a. Setting grouplayers
b. Combining groupslayer control and MarkerCluster.

@tonydspaniard
Copy link
Member

Not sure I understand your challenge.

@arjenmeijer
Copy link
Author

I do not understand how I can set grouplayers. How can I add records to a group layer?
I have:

$layerGroups = [];

foreach($uniqegroup as $line) {
    $layerGroups[$line['name']] = new LayerGroup(['name' => $line['id'] ]);
}

This will set the layersgroups and give them a name. But it doesn't link the items to it.
So I missing the concept to add the individual item to a group. How should I do that?

@tonydspaniard
Copy link
Member

A layerGroup configures a set of layers (see the layers folder) objects and adds it to the layerControl. Please, see the examples: https://leafletjs.com/examples/layers-control/.

Please, check the tests here: https://github.com/2amigos/yii2-leaflet-extension/blob/master/tests/functional/LayersControlTest.php#L85 , that would give you a good starting point, the only thing missing is adding the layer to the map.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants