katzz0/yii2-yandex-maps

Yii 2 Yandex 地图模块

安装: 933

依赖者: 0

建议者: 0

安全: 0

星星: 4

关注者: 3

分支: 30

开放问题: 1

类型:yii2-extension

dev-master 2015-07-02 11:19 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:44:03 UTC


README

此仓库是从 yii2-yandex-mapsMirocow 分支而来

组件

katzz0\yandexmaps\Api

注册脚本的应用程序组件。

用法

将组件附加到应用程序(例如,编辑config/main.php)

'components' => [
	'yandexMapsApi' => [
		'class' => 'mirocow\yandexmaps\Api',
	]
 ],

katzz0\yandexmaps\Map

地图实例。

用法

use katzz0\yandexmaps\Map;

$map = new 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'])",
        ],
    ]
);

katzz0\yandexmaps\Canvas

这是一个渲染您地图 HTML 标签的部件。

用法

简单地将部件添加到视图

use katzz0\yandexmaps\Canvas as YandexMaps;

<?= YandexMaps::widget([
    'htmlOptions' => [
        'style' => 'height: 600px;',
    ],
    'map' => new Map('yandex_map', [
        'center' => [55.7372, 37.6066],
        'zoom' => 17,
        'controls' => [Map::CONTROL_ZOOM],
        'behaviors' => [Map::BEHAVIOR_DRAG],
        'type' => "yandex#map",
    ],
    [
        'objects' => [new Placemark(new Point(55.7372, 37.6066), [], [
            'draggable' => true,
            'preset' => 'islands#dotIcon',
            'iconColor' => '#2E9BB9',
            'events' => [
                'dragend' => 'js:function (e) {
                    console.log(e.get(\'target\').geometry.getCoordinates());
                }'
            ]
        ])]
    ])
]) ?>

您还可以使用直接放置标签

<?= YandexMaps::widget([
    'htmlOptions' => [
        'style' => 'height: 600px;',
    ],
    'map' => new Map(null, [
        'center' => 'London',
        'zoom' => 17,
        'controls' => [Map::CONTROL_ZOOM],
        'behaviors' => [Map::BEHAVIOR_DRAG],
        'type' => "yandex#map",
    ],
    [
        'objects' => [new Placemark(null, [], [
            'draggable' => true,
            'preset' => 'islands#dotIcon',
            'iconColor' => '#2E9BB9',
            'events' => [
                'dragend' => 'js:function (e) {
                    console.log(e.get(\'target\').geometry.getCoordinates());
                    }'
            ]
        ])]
    ])
]) ?>