davidjeddy/yii2-leaflet-draw-plugin

Plugin for the 2amigo Leaflet extension that adds the Leaflet.Draw functionality.

0.1.0 2015-09-25 16:22 UTC

This package is auto-updated.

Last update: 2020-09-05 09:52:54 UTC


README

Yii 2 LeafletJs Plugin for the 2amigo Leaflet extension that adds the Leaflet Draw functionality.

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

php composer.phar require "davidjeddy/yii2-leaflet-draw-plugin" "*"

or add

"davidjeddy/yii2-leaflet-draw-plugin" : "*"

to the require section of your application's composer.json file.

Usage

    // first lets setup the center of our map
    $center = new \dosamigos\leaflet\types\LatLng(['lat' => 51.508, 'lng' => -0.11]);

    // now lets create a marker that we are going to place on our map
    $marker = new \dosamigos\leaflet\layers\Marker(['latLng' => $center, 'popupContent' => 'Hi!']);

    // The Tile Layer (very important)
    $tileLayer = new \dosamigos\leaflet\layers\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',
        ]
    ]);

    // now our component and we are going to configure it
    $leaflet = new \dosamigos\leaflet\LeafLet([
        'center' => $center, // set the center
    ]);

	// init the 2amigos leaflet plugin provided by the package
    $drawFeature = new \davidjeddy\leaflet\plugins\draw\Draw();
	// optional config array for leadlet.draw
    $drawFeature->options = [
        "position" => "topright",
        "draw" => [
            "polyline" => [
                "shapeOptions" => [
                    "color" => "#ff0000",
                    "weight" => 10
                ]
            ],
            "polygon" => [
                "allowIntersection" => false, // Restricts shapes to simple polygons
                "drawError" => [
                    "color" => "#e1e100", // Color the shape will turn when intersects
                    "message" => "<b>Oh snap!</b> you can't draw that!" // Message that will show when intersect
                ],
                "shapeOptions" => [
                    "color" => "#bada55"
                ]
            ],
            "circle" => true, // Turns off this drawing tool
            "rectangle" => [
                "shapeOptions" => [
                    "clickable" => false
                ]
            ]
        ]
    ];

    // Different layers can be added to our map using the `addLayer` function.
    $leaflet->addLayer($marker)             // add the marker
            ->addLayer($tileLayer)          // add the tile layer
            ->installPlugin($drawFeature);  // add draw plugin

    // we could also do
    echo $leaflet->widget(['options' => ['style' => 'min-height: 300px']]);

Testing

TODO

Todo

ADD edit menu ability ADD custom marker functionality

Contributing

Please see ./docs/CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see ./docs/License File for more information.

Special Thanks

2amigOS!
Web development has never been so fun!
http://2amigos.us/

(http://http://sourcetoad.com/)
Sourcetoad is an award winning app development firm based in Tampa, FL. We are specialists in cross-platform web and mobile application development.
http://sourcetoad.com/