forked from Kolyunya/yii2-map-input-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2fe3b57
Showing
7 changed files
with
1,280 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#Yii2 map input widget | ||
##Description | ||
A [Yii2 input widget](http://www.yiiframework.com/doc-2.0/yii-widgets-inputwidget.html) which provides a user-friendly interface for selecting geographical coordinates via [Google maps](https://www.google.com/maps/preview). Allows users to select geographical coordinates by clicking on an interative Google map embedded into you web-page. | ||
|
||
##Usage | ||
|
||
###Minimal example | ||
To reproduce the following minimal example you will need to acquire a Google maps browser key as described in [Google maps developer's guide](https://developers.google.com/maps/documentation/javascript/tutorial#api_key). The key may be stored as an application parameter for easy referencing or anywhere you like. All other widget parameters have some sensible default values and may not be configured. | ||
~~~php | ||
echo $form->field($model,'coordinates')->widget | ||
( | ||
'kolyunya\yii2\widgets\MapInputWidget', | ||
[ | ||
// Google maps browser key. | ||
'key' => $key, | ||
] | ||
); | ||
~~~ | ||
|
||
###Extended example | ||
An exhaustive list of widget parameters (which are not derived from [yii\widgets\InputWidget](http://www.yiiframework.com/doc-2.0/yii-widgets-inputwidget.html)) available for configuration is described in the following example. | ||
~~~php | ||
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', | ||
|
||
] | ||
); | ||
~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "kolyunya/yii2-map-input-widget", | ||
"description": "Yii2 map input widget. Allows you to select geographcal coordinates via a human-friendly inteface.", | ||
"keywords": | ||
[ | ||
"yii2", | ||
"extension", | ||
"widget", | ||
"map", | ||
"input", | ||
"geocoding", | ||
"geo-coordinates", | ||
"coordinates" | ||
], | ||
"homepage": "https://github.com/Kolyunya/yii2-map-input-widget", | ||
"type": "yii2-extension", | ||
"license": "GNU GPL v3.0", | ||
"authors": | ||
[ | ||
{ | ||
"name": "Oleynikov Nikolay", | ||
"email": "[email protected]", | ||
"homepage": "http://github.com/Kolyunya/" | ||
} | ||
], | ||
"autoload": | ||
{ | ||
"psr-4": | ||
{ | ||
"kolyunya\\yii2\\": "sources" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
// Yii2 map input widget allows selecting geographical coordinates. | ||
// Copyright (C) 2014 Nikolay Oleynikov | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// Author email: [email protected] | ||
|
||
namespace kolyunya\yii2\assets; | ||
|
||
class MapInputAsset extends \yii\web\AssetBundle | ||
{ | ||
|
||
public static $key; | ||
|
||
public $sourcePath = '@kolyunya/yii2-map-input-widget/sources/web'; | ||
|
||
public $depends = | ||
[ | ||
'yii\web\JqueryAsset', | ||
]; | ||
|
||
public $jsOptions = | ||
[ | ||
'position' => \yii\web\View::POS_END, | ||
]; | ||
|
||
public function __construct( $config = [] ) | ||
{ | ||
$this->js[] = $this->getGoogleMapScriptUrl(); | ||
$this->js[] = 'js/map-input-widget.js'; | ||
parent::__construct($config); | ||
} | ||
|
||
private function getGoogleMapScriptUrl() | ||
{ | ||
$scriptUrl = "http://maps.googleapis.com/maps/api/js?"; | ||
$scriptUrl .= http_build_query | ||
( | ||
[ | ||
'key' => self::$key, | ||
'sensor' => 'false', | ||
] | ||
); | ||
return $scriptUrl; | ||
} | ||
|
||
} | ||
|
||
?> |
Oops, something went wrong.