LeafLet GeoSearch Plugin

What is LeafLet GeoSearch Plugin?

Is a LeafletJs Plugin that adds support for address lookup (a.k.a. geocoding / geoseaching) to Leaflet. This Plugin works in conjunction with LeafLet library for Yii 2 framework.

Installation

The preferred way to install this extension is through composer.

Either run

composer require 2amigos/yii2-leaflet-geosearch-plugin:~1.0

or add the following to the require section of your application's composer.json file:

"2amigos/yii2-leaflet-geosearch-plugin" : "~1.0"

Usage example

use dosamigos\leaflet\layers\TileLayer;
use dosamigos\leaflet\LeafLet;
use dosamigos\leaflet\types\LatLng;
use dosamigos\leaflet\plugins\geosearch\GeoSearch;
use dosamigos\leaflet\widgets\Map;

$center = new LatLng(['lat' => 39.67442740076734, 'lng' => 2.9347229003906246]);

$geoSearchPlugin = new GeoSearch([
    'service' => GeoSearch::SERVICE_OPENSTREETMAP
]);

$tileLayer = new TileLayer([
    'urlTemplate' => 'http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg',
    'clientOptions' => [
        'attribution' => 'Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> ' .
            '<img src="http://developer.mapquest.com/content/osm/mq_logo.png">, ' .
            'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' .
            '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
        'subdomains' => '1234'
    ]
]);

$leafLet = new LeafLet([
    'name' => 'geoMap',
    'tileLayer' => $tileLayer,
    'center' => $center,
    'zoom' => 10,
    'clientEvents' => [
        // setting up one of the geo search events for fun
        'geosearch_showlocation' => 'function(e){
            console.log(e.target);
        }'
    ]
]);

// add the plugin
$leafLet->installPlugin($geoSearchPlugin);

// run the widget (you can also use Map::widget([...]))
echo $leafLet->widget();

Share this

Contributors Thanks All

 

Do you have a good idea? Why Don't We Talk?