ttungbmt / yii2-leaflet-geocoder
Leaflet 交互式地图扩展库,适用于 Yii2。
1.0.0
2019-06-14 02:46 UTC
Requires
This package is auto-updated.
Last update: 2024-09-14 14:50:53 UTC
README
Yii 2 LeafletJs 插件,该插件添加了对 Leaflet 的地址查找支持,具有下拉列表功能和加载图标反馈。此插件与 LeafLet 库协同工作,适用于 Yii 2 框架。
重要 此插件使用的库已从 原始插件源代码 中修改。因此,如果您想修改此插件,请记住您不能从其原始源代码更新它。
安装
安装此扩展的首选方法是使用 composer。
运行以下命令
composer require ttungbmt/yii2-leaflet-geocoder "@dev"
或
"ttungbmt/yii2-leaflet-geocoder" : "@dev"
将以下内容添加到您的应用程序的 composer.json 文件的 require 部分。
使用方法
尽管我们只实现了三个,但您可以使用以下四种服务:
- Nominatim
- Bing
- MapQuest
- HCMGIS
- Mapbox
- Here
任何想要帮助整合更多服务的人都非常欢迎 :)
use dosamigos\leaflet\layers\TileLayer;
use ttungbmt\leaflet\Leaflet;
use dosamigos\leaflet\types\LatLng;
use ttungbmt\leaflet\geocoder\services\ServiceHCMGIS;
use ttungbmt\leaflet\geocoder\GeoCoder;
// lets use nominating service
$hcmgis = new ServiceHCMGIS();
// create geocoder plugin and attach the service
$geoCoderPlugin = new GeoCoder([
'service' => $hcmgis,
'clientOptions' => [
// we could leave it to allocate a marker automatically
// but I want to have some fun
'defaultMarkGeocode' => false
],
'clientEvents' => [
'markgeocode' => new JsExpression('function(e){ console.log(e) }')
]
]);
// add a marker to center
$marker = new Marker([
'name' => 'geoMarker',
'latLng' => $center,
'clientOptions' => ['draggable' => true], // draggable marker
'clientEvents' => [
'dragend' => 'function(e){
console.log(e.target._latlng.lat, e.target._latlng.lng);
}'
]
]);
// configure the tile layer
$tileLayer = new TileLayer([
'urlTemplate' => 'http://{s}.google.com/vt/lyrs={map}&x={x}&y={y}&z={z}',
'clientOptions' => [
'map' => 'm',
'attribution' => ''© Google Maps',
'subdomains' => ['mt0', 'mt1', 'mt2', 'mt3'],
]
]);
// initialize our leafLet component
$leaflet = new Leaflet([
'name' => 'geoMap',
'tileLayer' => $tileLayer,
'center' => $center,
'zoom' => 10,
]);
// add the marker
$leaflet->addLayer($marker);
// install the plugin
$leaflet->installPlugin($geoCoderPlugin);
// run the widget (you can also use dosamigos\leaflet\widgets\Map::widget([...]))
echo $leaflet->widget();
测试
$ ./vendor/bin/phpunit
贡献
请参阅 CONTRIBUTING 以获取详细信息。
鸣谢
许可证
BSD 许可证(BSD)。有关更多信息,请参阅 许可证文件。
网页开发从未如此有趣!
www.2amigos.us