2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

Problem with adding layerGroup to the map #6

Closed it3rmit closed 9 years ago

it3rmit commented 10 years ago

I am trying to implement a leaflet example with controls and overlays from this example using yii2-leaflet-extension. But I have faced some problems. It looks like the problem is because $layers->setOverlays supports only TileLayer, but doesn't support LayerGroup. In controls\Layers.php

/**
     * @param \dosamigos\leaflet\layers\TileLayer[] $overlays
     * @throws \yii\base\InvalidParamException
     * @todo: support for LayerGroups
     */
    public function setOverlays($overlays)
    {

        foreach((array)$overlays as $overlay) {
            if(!($overlay instanceof TileLayer)) {
                throw new InvalidParamException("All overlays should be of type TileLayer");
            }
        }

        $this->_overlays = $overlays;
    }

So, the question is does @todo task is going to be implemented? PS: if I am wrong about the solution, is it possible to implement the given example using existing yii2-leaflet-library features?

tonydspaniard commented 10 years ago

https://github.com/2amigos/yii2-leaflet-extension/blob/master/LeafLet.php#L282

it3rmit commented 10 years ago

Thanks for your answer, but it doesn't solve the problem. Yes, I can add layerGroup. I can't add control layers. I'll be more specific.

...
var cities = L.layerGroup([littleton, denver, aurora, golden]);

var baseMaps = {
    "Grayscale": grayscale,
    "Streets": streets
};

var overlayMaps = {
    "Cities": cities
};

L.control.layers(baseMaps, overlayMaps).addTo(map);

How can I implement this with yii2-leaflet-extension?

tonydspaniard commented 10 years ago

@it3rmit Sorry for late response. You can append all javascript you wish: https://github.com/2amigos/yii2-leaflet-extension/blob/master/LeafLet.php#L310