mirocow / yii2-yandex-maps
Yii 2 yandex 地图模块
dev-master
2020-02-10 00:48 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-10 10:28:33 UTC
README
安装
安装此扩展的首选方式是通过 composer。
添加仓库
"repositories": [ { "type": "git", "url": "https://github.com/mirocow/yii2-yandex-maps.git" } ]
然后
php composer.phar require --prefer-dist "mirocow/yii2-yandex-maps" "*"
或者添加
"mirocow/yii2-yandex-maps" : "*"
到你的应用程序的 composer.json
文件的 require 部分。
对于最后的 Yii2 2.X 版本,请使用补丁 https://github.com/iamruslan/yii2-yandex-maps/commit/fee95f91b4b313424c5041101f57a6b49d0a7276
组件
mirocow\yandexmaps\Api
mirocow\yandexmaps\Map
mirocow\yandexmaps\Canvas
mirocow\yandexmaps\Placemark
mirocow\yandexmaps\Polygon
mirocow\yandexmaps\Controls
mirocow\yandexmaps\Polyline
mirocow\yandexmaps\GeoObject
- 待办事项: Geo XML
- 待办事项: 气球
- 待办事项: 提示
- 待办事项: 聚类器
mirocow\yandexmaps\Api
注册脚本的应用程序组件。
用法
将组件附加到应用程序(例如,编辑 config/main.php)
'components' => [ 'yandexMapsApi' => [ 'class' => 'mirocow\yandexmaps\Api', ] ],
mirocow\yandexmaps\Map
地图实例。
用法
$map = new \mirocow\yandexmaps\Map('yandex_map', [ 'center' => [55.7372, 37.6066], 'zoom' => 10, // Enable zoom with mouse scroll 'behaviors' => array('default', 'scrollZoom'), 'type' => "yandex#map", ], [ // Permit zoom only fro 9 to 11 'minZoom' => 9, 'maxZoom' => 11, 'controls' => [ "new ymaps.control.SmallZoomControl()", "new ymaps.control.TypeSelector(['yandex#map', 'yandex#satellite'])", ], ] );
mirocow\yandexmaps\Canvas
这是一个渲染地图的 HTML 标签的小部件。
用法
简单地将小部件添加到视图中
echo \mirocow\yandexmaps\Canvas::widget([ 'htmlOptions' => [ 'style' => 'height: 400px;', ], 'map' => $map, ]);
mirocow\yandexmaps\Controls
'controls' => [ // v 2.1 'new ymaps.control.ZoomControl({options: {size: "small"}})', //'new ymaps.control.TrafficControl({options: {size: "small"}})', //'new ymaps.control.GeolocationControl({options: {size: "small"}})', 'search' => 'new ymaps.control.SearchControl({options: {size: "small"}})', //'new ymaps.control.FullscreenControl({options: {size: "small"}})', //'new ymaps.control.RouteEditor({options: {size: "small"}})', ],
mirocow\yandexmaps\GeoObject
mirocow\yandexmaps\Placemark
$placemark = new mirocow\yandexmaps\objects\Placemark([ 55.7372, 37.6066 ], [ ], [ 'draggable' => true ] );
mirocow\yandexmaps\Polygon
待办事项
mirocow\yandexmaps\Clusterer
for (var i in map_point) { points[i] = new ymaps.GeoObject({ geometry : { type: 'Point', coordinates : [map_point[i]['lat'],map_point[i]['lng']] }, properties : { balloonContentBody : map_point[i]['body'] // hintContent : 'подробнее' } }, { iconImageHref: '/i/' + map_point[i]['spec']+'.png', iconImageSize: [29,29], balloonIconImageHref: '/i/' + map_point[i]['spec']+'.png', balloonIconImageSize: [29,29], hasBalloon: true }); } var clusterer = new ymaps.Clusterer(); clusterer.add(points); map.geoObjects.add(clusterer);
mirocow\yandexmaps\Polyline
待办事项
示例
包含 yandex 地图的用户表单
<?php $form = ActiveForm::begin([ 'options' => ['class' => 'user-settings'], 'fieldConfig' => [ 'options' => [ 'tag' => false, ], ], ]); $map = new \mirocow\yandexmaps\Map('yandex_map', [ 'center' => [55.7372, 37.6066], 'zoom' => 10, // Enable zoom with mouse scroll 'behaviors' => ['default', 'scrollZoom'], 'type' => "yandex#map", 'controls' => [], ], [ // Permit zoom only fro 9 to 11 'minZoom' => 1, 'maxZoom' => 11, 'controls' => [ // v 2.1 'new ymaps.control.ZoomControl({options: {size: "small"}})', //'new ymaps.control.TrafficControl({options: {size: "small"}})', //'new ymaps.control.GeolocationControl({options: {size: "small"}})', 'search' => 'new ymaps.control.SearchControl({options: {size: "small"}})', //'new ymaps.control.FullscreenControl({options: {size: "small"}})', //'new ymaps.control.RouteEditor({options: {size: "small"}})', ], 'behaviors' => [ 'scrollZoom' => 'disable', ], 'objects' => [ <<<JS search.events.add("resultselect", function (result){ // Remove old coordinates \$Maps['yandex_map'].geoObjects.each(function(obj){ \$Maps['yandex_map'].geoObjects.remove(obj); }); // Add selected coordinates var index = result.get('index'); var searchControl = \$Maps['yandex_map'].controls.get(1); searchControl.getResult(index).then(function(res) { var coordinates = res.geometry.getCoordinates(); $('#coordinates').html(''); $('#coordinates').append('<input type="hidden" name="User[coordinates][]" value="'+coordinates[0]+'">'); $('#coordinates').append('<input type="hidden" name="User[coordinates][]" value="'+coordinates[1]+'">'); }); }); JS ], ] );?> <?= \mirocow\yandexmaps\Canvas::widget([ 'htmlOptions' => [ 'style' => 'height: 400px;', ], 'map' => $map, ]); ?> <div id="coordinates"></div> <?php ActiveForm::end(); ?>