Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolyunya committed Jul 22, 2014
0 parents commit 2fe3b57
Show file tree
Hide file tree
Showing 7 changed files with 1,280 additions and 0 deletions.
674 changes: 674 additions & 0 deletions LICENSE.txt

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions README.md
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',

]
);
~~~
33 changes: 33 additions & 0 deletions composer.json
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"
}
}
}
62 changes: 62 additions & 0 deletions sources/assets/MapInputAsset.php
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;
}

}

?>
Loading

0 comments on commit 2fe3b57

Please sign in to comment.