2amigos/yii2-leaflet-geocoder-plugin

此包已被废弃,不再维护。没有推荐替代包。

Yii2 LeafLet 插件,为 Leaflet 提供地址查找功能,并带有下拉列表结果和加载图标反馈。

1.0.3 2019-04-06 16:13 UTC

This package is auto-updated.

Last update: 2023-07-29 01:31:15 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Yii 2 LeafletJs 插件,添加了将地址查找功能集成到 Leaflet 的支持,具有下拉列表和加载图标反馈功能。此插件与 LeafLet 库结合使用,用于 Yii 2 框架。

重要 该插件使用的库已从 原始插件源 进行了修改。因此,如果您希望修改插件,请记住您不能从其原始源更新它。

安装

推荐通过 composer 安装此扩展。

运行以下命令

composer require 2amigos/yii2-leaflet-geocoder-plugin:~1.0

或者将以下内容添加到应用程序 composer.json 文件的 require 部分。

"2amigos/yii2-leaflet-geocoder-plugin" : "~1.0"

使用方法

尽管我们只实现了三个,但您可以使用以下四种服务之一

  • Nominatim
  • Bing
  • MapQuest

任何愿意帮助整合更多服务的人都非常欢迎 :)

use dosamigos\leaflet\layers\TileLayer;
use dosamigos\leaflet\LeafLet;
use dosamigos\leaflet\types\LatLng;
use dosamigos\leaflet\layers\Marker;
use dosamigos\leaflet\plugins\geocoder\ServiceNominatim;
use dosamigos\leaflet\plugins\geocoder\GeoCoder;


// lets use nominating service
$nominatim = new ServiceNominatim();

// create geocoder plugin and attach the service
$geoCoderPlugin = new GeoCoder([
    'service' => $nominatim,
    'clientOptions' => [
        // we could leave it to allocate a marker automatically
        // but I want to have some fun
        'showMarker' => false
    ]
]);

// add a marker to center
$center = new LatLng(['lat' => '49.006889', 'lng' => '8.403653']);
$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://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'
    ]
]);

// initialize our leafLet component
$leafLet = new LeafLet([
    'name' => 'geoMap',
    'tileLayer' => $tileLayer,
    'center' => $center,
    'zoom' => 10,
    'clientEvents' => [
        // I added an event to ease the collection of new position
        'geocoder_showresult' => 'function(e){
            // set markers position
            geoMarker.setLatLng(e.Result.center);
        }'
    ]
]);

// 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)。请参阅 许可文件 以获取更多信息。

2amigOS!
Web 开发从未如此有趣!
www.2amigos.us