yii2-map-input-widget

A Yii2 input widget which provides a user-friendly interface for selecting geographical coordinates via Google maps. Allows users to select geographical coordinates by clicking on an interative Google map embedded into your web-page. Also allows users to type in a place name to search for it via Google Places API.

  • Owner: Kolyunya/yii2-map-input-widget
  • Platform:
  • License:: GNU General Public License v3.0
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

Yii2 map input widget

Description

A Yii2 input widget which provides a user-friendly interface for selecting geographical coordinates via Google maps. Allows users to select geographical coordinates by clicking on an interative Google map embedded into you web-page. Also allows users to type in a place name to search for it via Google Places API.

The widget is composer-enabled. You can aquire the latest available version from the packagist repository.

Demo

A simple widget demo is available here. You may inspect the hidden input value via some web-developer tool (e.g. Firebug) to see how geographical coordinates are represented inside the widget.

Usage examples

Minimal example

All widget parameters are optional, have some sensible default values and may not be configured.

echo $form->field($model, 'coordinates')->widget('kolyunya\yii2\widgets\MapInputWidget');

Extended example

An exhaustive list of widget parameters (which are not derived from yii\widgets\InputWidget) available for configuration is described in the following example.

echo $form->field($model, 'coordinates')->widget(
    'kolyunya\yii2\widgets\MapInputWidget',
    [

        // Google maps browser key.
        'key' => $key,

        // Initial map center latitude. Used only when the input has no value.
        // Otherwise the input value latitude will be used as map center.
        // Defaults to 0.
        'latitude' => 42,

        // Initial map center longitude. Used only when the input has no value.
        // Otherwise the input value longitude will be used as map center.
        // Defaults to 0.
        'longitude' => 42,

        // Initial map zoom.
        // Defaults to 0.
        'zoom' => 12,

        // Map container width.
        // Defaults to '100%'.
        'width' => '420px',

        // Map container height.
        // Defaults to '300px'.
        'height' => '420px',

        // Coordinates representation pattern. Will be use to construct a value of an actual input.
        // Will also be used to parse an input value to show the initial input value on the map.
        // You can use two macro-variables: '%latitude%' and '%longitude%'.
        // Defaults to '(%latitude%,%longitude%)'.
        'pattern' => '[%longitude%-%latitude%]',

        // Google map type. See official Google maps reference for details.
        // Defaults to 'roadmap'
        'mapType' => 'satellite',

        // Marker animation behavior defines if a marker should be animated on position change.
        // Defaults to false.
        'animateMarker' => true,

        // Map alignment behavior defines if a map should be centered when a marker is repositioned.
        // Defaults to true.
        'alignMapCenter' => false,

        // A flag which defines if a search bar should be rendered over the map.
        'enableSearchBar' => true,

    ]
);

Main metrics

Overview
Name With OwnerKolyunya/yii2-map-input-widget
Primary LanguageJavaScript
Program languagePHP (Language Count: 4)
Platform
License:GNU General Public License v3.0
所有者活动
Created At2014-07-18 16:28:27
Pushed At2018-03-17 08:34:52
Last Commit At2018-01-10 17:26:57
Release Count6
Last Release Namev1.2.0 (Posted on 2018-01-10 17:29:10)
First Release Name1.0.0 (Posted on 2015-03-07 18:11:58)
用户参与
Stargazers Count28
Watchers Count5
Fork Count24
Commits Count37
Has Issues Enabled
Issues Count15
Issue Open Count2
Pull Requests Count2
Pull Requests Open Count4
Pull Requests Close Count5
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private