makeitbetter/yiimaps

Maps manager module for Yii2.

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

v1.1.1 2019-05-26 08:16 UTC

This package is not auto-updated.

Last update: 2024-04-22 07:05:16 UTC


README

N|Solid

yiimaps is a module for Yii framework 2.0 to control coordinates of models and displaying the models on map. The module uses an API of Yandex.maps.

Installation

Add package:

#!sh
$ composer require makeitbetter/yiimaps

Configure the application by adding (yii2 guide):

#!php
$config['modules']['yiimaps'] = [
    'class' => 'makeitbetter\yiimaps\Module',
    'options' => [],
];
$config['bootstrap'][] = 'yiimaps';

Usage

In your forms:

#!php
use makeitbetter\yiimaps\widgets\CoordsInput;
use yii\widgets\ActiveForm;

$form = ActiveForm::begin();

echo $form->field($model, 'property_name')->widget(CoordsInput::className(), $options);

ActiveForm::end();

Available options:

lat - Name of model attribute containing latitude value, default is lat.

lon - Name of model attribute containing longitude value, default is lon.

Or without an ActiveForm object:

#!php
echo CoordsInput::widget(['model' => $model, 'attribute' => 'property_name']);

Displaying models on map:

#!php
use makeitbetter\yiimaps\widgets\YandexMap;

echo YandexMap::widget([
    'models' => $models,

Available options:

lat - Name of model attribute containing latitude value, default is lat.

lon - Name of model attribute containing longitude value, default is lon.

balloonContent - Name of model attribute or callback function which returns a content for balloon, default is balloonContent.

groupBy - Name of related entity and its primary key, which contains a coordinates. For example, if models Persons belongs to entity Addresses, you should definde 'groupBy' => 'address.id'. Persons with the same address will be displayed on map like a one point. Balloon will be contains data of every person and then data of address (except when you use a callback function).

placemarkIcon - Icon of placemark, default is islands#redDotIcon see more... If value is an array, keys will be checked against the value of the attribute $placemark. Use key 'default' to define default placemark icon.

placemark - Name of model attribute to define a placemark icon.

useClusterer - Wheter to use clusterer, default is false.

clustererIcon - Clusterer icon, default is islands#invertedBlackClusterIcons see more...

mapHeight - Map height, default is 300px.

mapWidth - Map width, default is 100%.

Internationalisation

For adding translations of module strings register a source modules/yiimaps. For example add to your application config file following code:

#!php
$config['components']['i18n'] = [
    'translations' => [
        ...
        'modules*' => [
            'class' => 'yii\i18n\PhpMessageSource',
        ],
    ],
];

This configuration means that the application will search the translations at file @app/messages/xx-XX/modules/yiimaps.php

See more about internationalisation in yii2 guide

Demo: https://makeitbetter.su/projects/yiimaps