yii2-leaflet-extension

用 Leaflet 展示互动地图的 Yii 扩展库。(Yii 2 Extension library to display interactive maps with Leaflet.)

  • 所有者: 2amigos/yii2-leaflet-extension
  • 平台: BSD, Linux, Mac, Windows
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Yii2 的 LeafLet 扩展

使用 LeafletJs 显示交互式地图的扩展库

安装

安装此扩展程序的首选方法是通过 composer。这需要 composer-asset-plugin , 这也是 yii2 的一个依赖项,所以如果已经安装了 yii2,那么很可能已经设置好了。

要么运行

composer require 2amigos/yii2-leaflet-extension:~1.0

或添加

"2amigos/yii2-leaflet-extension" : "~1.0"

到应用程序的 composer.json 文件的 require 部分。

用法

使用 LeafletJs 时要考虑的一件事是我们需要一个 Tile Provider。 非常重要的是,如果我们未能提供 Tile Provider Url,地图将显示为 plain,而根本没有任何地图。

以下示例使用 MapQuest

// 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 © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
        'subdomains' => ['1', '2', '3', '4'],
    ],
]);

// now our component and we are going to configure it
$leaflet = new \dosamigos\leaflet\LeafLet([
    'center' => $center, // set the center
]);
// Different layers can be added to our map using the `addLayer` function.
$leaflet->addLayer($marker)      // add the marker
        ->addLayer($tileLayer);  // add the tile layer

// finally render the widget
echo \dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leaflet]);

// we could also do
// echo $leaflet->widget();

测试

要测试扩展,最好在您的计算机上克隆这个存储库。然后,转到extensions文件夹并执行以下操作(假设您的计算机上已经安装了composer)

$ composer install --no-interaction --prefer-source --dev

安装完所有必需的库后,请执行以下操作:

$ vendor/bin/phpunit

更多信息

有关 LeafLetJS 库的多种设置的更多信息,请访问 其API参考

贡献

有关详细信息,请参阅贡献

致谢

许可证

BSD许可证(BSD)。有关详细信息,请参阅许可文件

主要指标

概览
名称与所有者2amigos/yii2-leaflet-extension
主编程语言PHP
编程语言PHP (语言数: 2)
平台BSD, Linux, Mac, Windows
许可证Other
所有者活动
创建于2014-02-17 11:19:21
推送于2020-01-17 11:13:02
最后一次提交2017-04-12 13:45:31
发布数9
最新版本名称1.1.0 (发布于 2017-04-12 13:42:54)
第一版名称0.1.0 (发布于 2014-04-20 12:45:34)
用户参与
星数30
关注者数17
派生数26
提交数104
已启用问题?
问题数40
打开的问题数17
拉请求数5
打开的拉请求数1
关闭的拉请求数8
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?

LeafLet Extension for Yii2

Latest Version
Software License
Build Status
Coverage Status
Total Downloads

Extension library to display interactive maps with LeafletJs

Installation

The preferred way to install this extension is through
composer. This requires the
composer-asset-plugin,
which is also a dependency for yii2 – so if you have yii2 installed, you are
most likely already set.

Either run

composer require 2amigos/yii2-leaflet-extension:~1.0

or add

"2amigos/yii2-leaflet-extension" : "~1.0"

to the require section of your application's composer.json file.

Usage

One of the things to take into account when working with LeafletJs is that we need a Tile
Provider. Is very important, if we fail to provide a Tile Provider Url, the map will display plain, without any maps at
all.

The following example, is making use of MapQuest:

// 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' => ['1', '2', '3', '4'],
    ],
]);

// now our component and we are going to configure it
$leaflet = new \dosamigos\leaflet\LeafLet([
    'center' => $center, // set the center
]);
// Different layers can be added to our map using the `addLayer` function.
$leaflet->addLayer($marker)      // add the marker
        ->addLayer($tileLayer);  // add the tile layer

// finally render the widget
echo \dosamigos\leaflet\widgets\Map::widget(['leafLet' => $leaflet]);

// we could also do
// echo $leaflet->widget();

Testing

To test the extension, is better to clone this repository on your computer. After, go to the extensions folder and do
the following (assuming you have composer installed on your computer):

$ composer install --no-interaction --prefer-source --dev

Once all required libraries are installed then do:

$ vendor/bin/phpunit

Further Information

For further information regarding the multiple settings of LeafLetJS library please visit
its API reference

Contributing

Please see CONTRIBUTING for details.

Credits

License

The BSD License (BSD). Please see License File for more information.

2amigOS!
Web development has never been so fun!
www.2amigos.us