Closed eyedol closed 10 years ago
<?php
use yii\helpers\Html;
use kartik\icons\Icon;
?>
<?php
//initialise all waypoints
$mycenter = 0;
$locations = array();
foreach($dpLocations AS $location){
foreach($location->party->addresses AS $address)
{
if($mycenter == 0)
{
$center = new dosamigos\leaflet\types\LatLng(['lat' => $address->no_latitude, 'lng' => $address->no_longitude]);
}
$locations[$location->party->organisationName] = new dosamigos\leaflet\types\LatLng(['lat' => $address->no_latitude, 'lng' => $address->no_longitude]);
$mycenter++;
}
}
if($mycenter>0)
{
$layer = new dosamigos\leaflet\layers\TileLayer([
//'urlTemplate' => 'http://{s}.tile.cloudmade.com/key/997/256/{z}/{x}/{y}.png',
'urlTemplate' => 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
'map' => 'BlogMap'.$location->param2_int,
'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'.$location->param2_int
]);
// 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']]);
}
?>
@philippfrenzel Thanks for the code snippets. It would be nice if this kind of snippet is added to the doc. It's a lot of work figuring out how to use it. Plus using the makimaker plugin throws an exception
Argument 1 passed to dosamigos\leaflet\layers\Marker::setIcon() must be an instance of dosamigos\leaflet\types\Icon, instance of yii\web\JsExpression given, called in /home/eyedol/Devel/Workspace/eatout/advanced/vendor/yiisoft/yii2/base/Component.php on line 168 and defined
It seems leaflet expects it's Icon type but makimarker returns a JSON string.
@eyedol is it working on your side? I send a pull request which removed the type passed over to the function so then it's working fine! you can see a working map here:
http://www.simplebutmagnificent.com (my girlfriends blog;))
@eyedol I know that all Yii2 extensions have very little documentation but this is due to the plans that I have for all them. Apologies now as I do not have much time but documentation wont be an issue in the future. I am waiting for Yii2 beta.
Best and also thank you @philippfrenzel
@tonydspaniard I'm happy you had the time to build this "first" version, as docs are cool, for the current stability I totally understand that it's hard to follow up, even as you are having more then one repo to keep "up to date" ;)
Would be nice to provide documentation on how to use this plugin