leonardoxr/yii2-leaflet-extension

LeafLet 移动端友好交互式地图扩展库,适用于 Yii2。

安装: 0

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 0

分支: 26

类型:yii2-extension

1.1.0 2017-03-26 18:39 UTC

This package is auto-updated.

Last update: 2024-09-29 05:21:58 UTC


README

Latest Version Software License Build Status Coverage Status Total Downloads

扩展库,用于通过 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 一起工作时,需要注意的一件事是我们需要一个瓦片提供者。如果没有提供瓦片提供者 URL,地图将显示为空白,没有任何地图。

以下示例使用 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();

测试

为了测试扩展,最好在你的计算机上克隆此仓库。然后,转到扩展文件夹并执行以下操作(假设你的计算机上已安装 composer

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

一旦安装了所有必需的库,请执行以下操作:

$ vendor/bin/phpunit

更多信息

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

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可证

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

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