Widgets list:
- CoordsInput: selection of coordinates on the map;
- StreetInput: jui autocomplete with street names of specified city;
- MapWidget: displays the Yandex map and the placemarks., (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require kl83/yii2-ymaps @dev
or add, (*4)
"kl83/yii2-ymaps": "@dev"
to the require section of your composer.json file., (*5)
Usage
<?= $form->field($model, 'coords')->widget('kl83\ymaps\CoordsInput', [
  'options' => [], // Html-attributes of container
  'ymapsClientOptions' => [], // Yandex map JS settings
  'placemarkClientProperties' => [], // Placemark JS properties
  'placemarkClientOptions' => [], // Placemark JS options
]) ?>
<?= $form->field($model, 'street')->widget('kl83\ymaps\StreetInput', [
  'options' => [], // Html-attributes
  'city' => '', // Search streets in specified city
]) ?>
<?= MapWidget::widget([
    'mapState' => [
        'center' => [55.76, 37.64],
        'zoom' => 16,
    ],
    'placemarks' => [
        [
            [55.76, 37.64],
            [], // properties
            [], // options
        ],
        [
            [55.76, 37.64],
        ],
    ],
]) ?>
Interactivity
Finds the specified address on the map, and moves the placemark to it., (*6)
$('.widget').coordsInput('search', 'Some address');
Get or set the city to search on., (*7)
$('.widget').streetInput('city'); // Get
$('.widget').streetInput('city', 'Some city'); // Set
License
MIT License, (*8)