2amigos / yii2-leaflet-markercluster-plugin
此包已被 弃用 且不再维护。未建议替代包。
Yii2 LeafLet 插件,提供美观、复杂、高性能的标记聚合解决方案,具有平滑动画和众多优秀特性。
1.0.0
2015-03-31 11:45 UTC
Requires
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2023-08-16 03:10:04 UTC
README
Yii 2 LeafletJs 插件,提供美观、复杂、高性能的标记聚合解决方案,具有平滑动画和众多优秀特性。此插件与 LeafLet 库协同工作于 Yii 2 框架。
安装
推荐通过 composer 安装此扩展。
运行
composer require 2amigos/yii2-leaflet-markercluster-plugin:~1.0
或添加
"2amigos/yii2-leaflet-markercluster-plugin" : "~1.0"
到应用 composer.json
文件的 require 部分。
使用
使用外部 JSON URL 源
// LeafLet initialization component
// ...
// create cluster plugin
$cluster = new dosamigos\leaflet\plugins\markercluster\MarkerCluster([
'jsonUrl' => Yii::$app->controller->createUrl('site/json')
]);
// install to LeafLet component
$leafLet->plugins->install($cluster);
// done render widget
echo $leafLet->widget(['options' => ['style' => 'height: 400px']]);
返回标记的示例操作
public function actionJson()
{
Yii::$app->getResponse()->format = Response::FORMAT_JSON;
echo json_encode([
"markers" => [
["lat"=>-37.8210922667, "lng"=>175.2209316333, "popup" => "2"],
["lat"=>-37.8210819833, "lng"=>175.2213903167, "popup" => "3"],
]
]);
}
现在,随着创建标记而添加标记
// LeafLet initialization component
// ...
// create cluster plugin
$cluster = new dosamigos\leaflet\plugins\markercluster\MarkerCluster([
'jsonUrl' => Yii::$app->controller->createUrl('site/json')
]);
// sample location
$center = new dosamigos\leaflet\types\LatLng(['lat' => 51.508, 'lng' => -0.11]);
$marker1 = new dosamigos\leaflet\layers\Marker([
'latLng' => $center,
'popupContent' => 'Hey! I am a marker'
]);
$marker2 = new dosamigos\leaflet\layers\Marker([
'latLng' => $center,
'popupContent' => 'Hey! I am a second marker'
]);
// add them to the cluster plugin
$cluster
->addLayer($marker1)
->addLayer($marker2);
// install to LeafLet component
$leafLet->plugins->install($cluster);
贡献
请参阅 CONTRIBUTING 获取详细信息。
致谢
许可证
BSD 许可证 (BSD)。请参阅 许可证文件 获取更多信息。
网络开发从未如此有趣!
www.2amigos.us