Esempio n. 1
0
<?php

//initialise all waypoints
$mycenter = 0;
$locations = array();
foreach ($dpLocations as $address) {
    if ($address->latitude == '') {
        $address->save();
    }
    if ($mycenter == 0) {
        $center = new dosamigos\leaflet\types\LatLng(['lat' => $address->latitude, 'lng' => $address->longitude]);
    }
    $locations[$address->id] = new dosamigos\leaflet\types\LatLng(['lat' => $address->latitude, 'lng' => $address->longitude]);
    $mycenter++;
}
if ($mycenter > 0) {
    $layer = new dosamigos\leaflet\layers\TileLayer(['urlTemplate' => 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'map' => 'BlogMap' . $model->id, 'clientOptions' => ['attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors']]);
    $leafLet = new dosamigos\leaflet\LeafLet(['center' => $center, 'zoom' => 13, 'TileLayer' => $layer, 'name' => 'BlogMap' . $model->id]);
    // Initialize plugin
    $makimarkers = new dosamigos\leaflet\plugins\makimarker\MakiMarker(['name' => 'makimarker']);
    $leafLet->installPlugin($makimarkers);
    //var_dump($leafLet->plugins);exit;
    foreach ($locations as $key => $value) {
        // generate icon through its icon
        $marker = new dosamigos\leaflet\layers\Marker(['latLng' => $value, 'icon' => $leafLet->plugins->makimarker->make("cafe", ['color' => "#b0b", 'size' => "m"]), 'popupContent' => $key]);
        $leafLet->addLayer($marker);
    }
    echo dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leafLet, 'options' => ['style' => 'height: 400px']]);
}
Esempio n. 2
0
<?php

use yii\helpers\Html;
use kartik\icons\Icon;
$center = new dosamigos\leaflet\types\LatLng(['lat' => $latitude - 0.0001, 'lng' => $longitude - 0.0001]);
$iplocation = new dosamigos\leaflet\types\LatLng(['lat' => $latitude, 'lng' => $longitude]);
$layer = new dosamigos\leaflet\layers\TileLayer(['urlTemplate' => 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', 'map' => 'BlogMap' . str_replace('.', '', $latitude), 'clientOptions' => ['attribution' => 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors']]);
$leafLet = new dosamigos\leaflet\LeafLet(['center' => $center, 'zoom' => $options['zoom'], 'TileLayer' => $layer, 'name' => 'BlogMap' . str_replace('.', '', $latitude)]);
// Initialize plugin
$makimarkers = new dosamigos\leaflet\plugins\makimarker\MakiMarker(['name' => 'makimarker']);
$leafLet->installPlugin($makimarkers);
// generate icon through its icon
$marker = new dosamigos\leaflet\layers\Marker(['latLng' => $iplocation, 'icon' => $leafLet->plugins->makimarker->make("pitch", ['color' => "#b0b", 'size' => "m"]), 'popupContent' => 'IP Location']);
$leafLet->addLayer($marker);
$leafLet->appendJs('BlogMap' . str_replace('.', '', $latitude) . "._onResize()");
echo dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leafLet, 'height' => $options['height']]);
<div>
    <?php 
// 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]);
$drawFeature = new \davidjeddy\leaflet\plugins\draw\Draw();
$drawFeature->options = ["position" => "topright", "draw" => ["polyline" => ["shapeOptions" => ["color" => "#ff0000", "weight" => 10]], "polygon" => ["allowIntersection" => false, "drawError" => ["color" => "#e1e100", "message" => "<b>Oh snap!</b> you can't draw that!"], "shapeOptions" => ["color" => "#bada55"]], "circle" => true, "rectangle" => ["shapeOptions" => ["clickable" => false]]]];
// Different layers can be added to our map using the `addLayer` function.
$leaflet->addLayer($marker)->addLayer($tileLayer)->installPlugin($drawFeature);
// add draw plugin
// we could also do
echo $leaflet->widget(['options' => ['style' => 'min-height: 300px']]);
?>
</div>