2amigos / yii2-leaflet-extension

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

No support for disabling scrollWheelZoom #34

Closed akopan closed 7 years ago

akopan commented 8 years ago

The Leaflet JS library supports disabling scrollWheelZoom with the following code:

var map = L.map('mapDiv', {});
map.scrollWheelZoom.disable();

I haven't found how your yii2 extension supports this. I circumvented this issue by using the following code in my Yii2 app when creating my Map widget:

$map = Map::widget(['leafLet' => $leaflet, 'height' => 450, 'scrollWheelZoom' => false]);

And adding the support in the Map widget (widgets\Map.php) :

class Map extends Widget
{
    // I added a new public property for scrollWheelZoom, defaults to enabled
    $public scrollWheelZoom = true;

    // Map init, etc here

    public function registerScript()
    {
    // registerScript() code here...

    $clientEvents = $this->leafLet->clientEvents;

            if (!empty($clientEvents)) {
                foreach ($clientEvents as $event => $handler) {
                    $js[] = "$name.on('$event', $handler);";
                }
            }

            $js[] = "$name.setView({$lateInitClientOptions['center']}, {$lateInitClientOptions['zoom']});";

            // Logic for setting scrollWheelZoom in JS
+++         $js[] = $this->scrollWheelZoom ? "$name.scrollWheelZoom.enable();" : "$name.scrollWheelZoom.disable();";

            $view->registerJs("function {$name}_init(){\n" . implode("\n", $js) . "}\n\n{$name}_init();");
    }
}

Am I missing something? Or should I submit a pull request?

akopan commented 8 years ago

This is a very helpful option to support. If this project is not really active any more, hopefully this code can help others with scroll wheel issues in this plugin.

tonydspaniard commented 7 years ago

@akopan this project is active. Just not having time to make updates anymore. To disable scrollWheelZoom is as simple as adding this:

$leafLet = new LeafLet([
    'name' => 'propertyMap',
    'tileLayer' => $tileLayer,
    'center' => $center,
    'zoom' => 10,
    'clientOptions' => [
        'maxZoom' => 18
    ]
]);

// ... more code here 

$leafLet->appendJs('propertyMap.scrollWheelZoom.disable();'); // disable zoom