2amigos / yii2-leaflet-extension

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

Using more than one plug in at a time #17

Closed davidjeddy closed 8 years ago

davidjeddy commented 8 years ago

After setting up the map (working) my project requires the usage of both the geoSearch and another plugin. However, this does not seem to be implemented at the moment. Exp:

    $leaflet
        ->addlayerGroup($markerLayerGroup) // add layerGroup (of markers)
        ->addLayer( new \dosamigos\leaflet\layers\TileLayer([
            'clientOptions' => [
                'attribution' => \Yii::$app->keyStorage->get('common.teburu4.tileAttribution')
            ],
            'urlTemplate'   => \Yii::$app->keyStorage->get('common.teburu4.tileProviderUrl'),
        ]))
        ->installPlugin($geoSearchPlugin)
        ->installPlugin($drawPlugin);

This results in a ' PHP Fatal Error – yii\base\ErrorException Call to a member function installPlugin() on a non-object' error. So I broke the installPlugin() method call out.

    $leaflet
        ->addlayerGroup($markerLayerGroup) // add layerGroup (of markers)
        ->addLayer( new \dosamigos\leaflet\layers\TileLayer([
            'clientOptions' => [
                'attribution' => \Yii::$app->keyStorage->get('common.teburu4.tileAttribution')
            ],
            'urlTemplate'   => \Yii::$app->keyStorage->get('common.teburu4.tileProviderUrl'),
        ]));
    $leaflet->installPlugin($geoSearchPlugin)
    $leaflet->installPlugin($drawPlugin);

Only the LAST plugin is displayed in the map element.

How can the Leaflet extension be extended to handle more than one plugin?

tonydspaniard commented 8 years ago

@davidjeddy it does handle more than one plugin, the problem with your code is the concatenation of methods on the first example. See here: https://github.com/2amigos/yii2-leaflet-extension/blob/master/src/LeafLet.php#L238.

The second should work. Maybe there is a plugin conflict issue?