From f9d92ec58e19ee0d99ffc7c8f2fa14e8a0cf3386 Mon Sep 17 00:00:00 2001 From: "n.vanderburg" Date: Wed, 18 Jan 2017 19:03:10 +0100 Subject: [PATCH] changes --- MapPicker.php | 2 +- MapPickerAsset.php | 9 ++-- README.md | 2 +- StaticMap.php | 115 --------------------------------------------- composer.json | 2 +- 5 files changed, 9 insertions(+), 121 deletions(-) delete mode 100644 StaticMap.php diff --git a/MapPicker.php b/MapPicker.php index c930b6e..ad58291 100644 --- a/MapPicker.php +++ b/MapPicker.php @@ -1,6 +1,6 @@ sourcePath = __DIR__ . '/assets'; + parent::init(); + } public function loadMapsLib($apiKey) { diff --git a/README.md b/README.md index cff6188..0bf21fb 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Usage Once the extension is installed, simply use it in your code by : ```php -echo \app\components\widgets\Maps\MapPicker::widget([ +echo proximitymad\yii2mapspickerwidget\MapPicker::widget([ 'apiKey'=>'gmaps-api-key' //required, 'search'=>'Madrid, Spain' //required ]); diff --git a/StaticMap.php b/StaticMap.php deleted file mode 100644 index 08a3168..0000000 --- a/StaticMap.php +++ /dev/null @@ -1,115 +0,0 @@ -'40.4647254', 'lng'=>'-3.6724659', 'width'=>'50','height'=>'50','apiKey'=>'xxx'); * - *``` - * Ejemplo con opciones: - * ```php - * $options = [ - * 'width'=>50, - * 'height'=>50, - * 'color'=>'red', - * 'label'=>'P', - * 'size'=>'tiny', - * 'markers'=>[ - * [ - * 'color'=>'red', - * 'label'=>'P', - * 'lat'=>'40.5', - * 'lng'=>'-4.67' - * ] - * ] - * ]; - * ``` - */ -class StaticMap extends Widget -{ - /** - * @var bool|string La API KEY de Google para cargar el mapa, obligatorio - */ - public $apiKey = false; - /** - * @var bool|int Latitud del marcador - */ - public $lat = false; - /** - * @var bool|int Longitud del marcador - */ - public $lng = false; - /** - * @var int Ancho de la imagen a generar - */ - public $width = 100; - /** - * @var int Alto de la imagen a generar - */ - public $height = 100; - /** - * @var int|bool Zoom del mapa - */ - public $zoom = false; - /** - * @var string Color del marcador: black, brown, green, purple, yellow, bluye, gray, orange, red, white o 24bits (0xFFFFCC) - */ - public $labelColor = 'green'; - /** - * @var string Caracter del marcador (mayusculas) - */ - public $label = 'P'; - /** - * @var string tamaƱo del marcador: tiny, mid, small - */ - public $size = 'mid'; - /** - * @var array Marcadores adicionales. - * Cada marcador debe tener obligatoriamente los atributos `lat` y `lng`, y opcionalmente `color` y `label` - */ - public $markers = []; - /** - * @var string Url base que genera el mapa - */ - public $apiUrl = 'http://maps.googleapis.com/maps/api/staticmap'; - - public function init() - { - if (!$this->lat || !$this->lng || !$this->apiKey) { - throw new Exception("El widget StaticMap requiere los parametros lat, lng y apiKey"); - } - } - - public function run() - { - $url = $this->apiUrl; - $urlParts = []; - $urlParts[] = "markers=color:{$this->labelColor}%7Clabel:{$this->label}%7Csize:{$this->size}%7C{$this->lat},{$this->lng}"; - if ($this->zoom) { - $urlParts[] = "zoom={$this->zoom}"; - } - $urlParts[] = "size={$this->width}x{$this->height}"; - $urlParts[] = "key=" . $this->apiKey; - foreach ($this->markers as $marker) { - $color = ArrayHelper::getValue($marker, 'color', 'red'); - $label = ArrayHelper::getValue($marker, 'label', 'P'); - $lat = ArrayHelper::getValue($marker, 'lat'); - $lng = ArrayHelper::getValue($marker, 'lng'); - if ($lat && $lng) { - $urlParts[] = "markers=color:{$color}%7Clabel:{$label}%7C{$lat},{$lng}"; - } - } - $url .= "?" . implode("&", $urlParts); - return Html::img($url); - } -} \ No newline at end of file diff --git a/composer.json b/composer.json index b8b347e..f22eb70 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "require": {}, "autoload": { "psr-4": { - "proximitymad\\yii2-mapspicker-widget\\": "" + "proximitymad\\yii2mapspickerwidget\\": "" } } }