diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e35a6d9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2010 Thibault Duplessis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..2913e5f --- /dev/null +++ b/README.markdown @@ -0,0 +1,8 @@ +dmGoogleMapPlugin allows to display configurable google maps. +It packages a Diem front widget, and adds a _map() helper. +The plugin is fully extensible. Only works with [Diem 5.0](http://diem-project.org/) installed. + +Documentation +------------- + +See the online documentation : [Diem Google Map plugin documentation](http://diem-project.org/plugins/dmgooglemapplugin) diff --git a/config/dm/assets.yml b/config/dm/assets.yml new file mode 100644 index 0000000..69bc448 --- /dev/null +++ b/config/dm/assets.yml @@ -0,0 +1,10 @@ +js: + + dmGoogleMapPlugin: + + api: http://maps.google.com/maps/api/js?sensor=false + + widgetShowForm: widget/showForm + + launcher: launcher + dmGoogleMap: dmGoogleMap \ No newline at end of file diff --git a/config/dm/services.yml b/config/dm/services.yml new file mode 100644 index 0000000..2c7afff --- /dev/null +++ b/config/dm/services.yml @@ -0,0 +1,18 @@ +parameters: + + google_map_tag.class: dmGoogleMapTag + google_map_tag.options: [] + + google_map_helper.class: dmGoogleMapHelper + +services: + + google_map_tag: + class: %google_map_tag.class% + shared: false + arguments: [ %google_map_tag.options% ] + + google_map_helper: + class: %google_map_helper.class% + shared: true + arguments: [ @context ] \ No newline at end of file diff --git a/config/dm/widget_types.yml b/config/dm/widget_types.yml new file mode 100644 index 0000000..3e09fc3 --- /dev/null +++ b/config/dm/widget_types.yml @@ -0,0 +1,5 @@ +dmWidgetGoogleMap: + + show: + cache: false + public_name: Google Map \ No newline at end of file diff --git a/lib/dmWidget/dmWidgetGoogleMapShowForm.php b/lib/dmWidget/dmWidgetGoogleMapShowForm.php new file mode 100644 index 0000000..f83703c --- /dev/null +++ b/lib/dmWidget/dmWidgetGoogleMapShowForm.php @@ -0,0 +1,115 @@ +widgetSchema['address'] = new sfWidgetFormInputText(); + $this->validatorSchema['address'] = new sfValidatorString(); + $this->widgetSchema['address']->setLabel('Search a place'); + + $this->widgetSchema['mapTypeId'] = new sfWidgetFormSelect(array( + 'choices' => dmArray::valueToKey($this->getMapTypeIds()) + )); + $this->validatorSchema['mapTypeId'] = new sfValidatorChoice(array( + 'choices' => $this->getMapTypeIds() + )); + $this->widgetSchema['mapTypeId']->setLabel('Map type'); + + $this->widgetSchema['zoom'] = new sfWidgetFormSelect(array( + 'choices' => dmArray::valueToKey($this->getZooms()) + )); + $this->validatorSchema['zoom'] = new sfValidatorChoice(array( + 'choices' => $this->getZooms() + )); + + $this->widgetSchema['navigationControl'] = new sfWidgetFormInputCheckbox(); + $this->validatorSchema['navigationControl'] = new sfValidatorBoolean(); + $this->widgetSchema['navigationControl']->setLabel('Navigation'); + + $this->widgetSchema['mapTypeControl'] = new sfWidgetFormInputCheckbox(); + $this->validatorSchema['mapTypeControl'] = new sfValidatorBoolean(); + $this->widgetSchema['mapTypeControl']->setLabel('Map type'); + + $this->widgetSchema['scaleControl'] = new sfWidgetFormInputCheckbox(); + $this->validatorSchema['scaleControl'] = new sfValidatorBoolean(); + $this->widgetSchema['scaleControl']->setLabel('Scale'); + + $this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5)); + $this->validatorSchema['width'] = new dmValidatorCssSize(array( + 'required' => false + )); + + $this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5)); + $this->validatorSchema['height'] = new dmValidatorCssSize(array( + 'required' => false + )); + + $this->widgetSchema['splash'] = new sfWidgetFormInputText(); + $this->validatorSchema['splash'] = new sfValidatorString(array( + 'required' => false + )); + $this->widgetSchema->setHelp('splash', 'Display a message while the map is loading'); + + if(!$this->getDefault('width')) + { + $this->setDefault('width', '100%'); + } + if(!$this->getDefault('height')) + { + $this->setDefault('height', '300px'); + } + if(!$this->getDefault('mapTypeId')) + { + $this->setDefault('mapTypeId', 'hybrid'); + } + if(!$this->getDefault('zoom')) + { + $this->setDefault('zoom', '14'); + } + + parent::configure(); + } + + protected function getMapTypeIds() + { + return array('roadmap', 'satellite', 'hybrid', 'terrain'); + } + + protected function getZooms() + { + return range(2, 20); + } + + public function getStylesheets() + { + return array( + 'lib.ui-tabs' + ); + } + + public function getJavascripts() + { + return array( + 'lib.ui-tabs', + 'core.tabForm', + 'dmGoogleMapPlugin.widgetShowForm' + ); + } + + protected function renderContent($attributes) + { + return $this->getHelper()->renderPartial('dmWidgetGoogleMap', 'showForm', array( + 'form' => $this, + 'baseTabId' => 'dm_widget_google_map_'.$this->dmWidget->get('id') + )); + } + + public function getWidgetValues() + { + $values = parent::getWidgetValues(); + + return $values; + } +} \ No newline at end of file diff --git a/lib/dmWidget/dmWidgetGoogleMapShowView.php b/lib/dmWidget/dmWidgetGoogleMapShowView.php new file mode 100644 index 0000000..1b96f0e --- /dev/null +++ b/lib/dmWidget/dmWidgetGoogleMapShowView.php @@ -0,0 +1,53 @@ +addRequiredVar(array( + 'address', + 'mapTypeId', + 'zoom', + 'navigationControl', + 'mapTypeControl', + 'scaleControl', + 'width', + 'height')); + } + + protected function doRender() + { + $vars = $this->getViewVars(); + + $map = $this->getService('google_map_helper')->map() + ->address($vars['address']) + ->mapTypeId($vars['mapTypeId']) + ->zoom($vars['zoom']) + ->style(sprintf( + 'width: %s; height: %s;', + dmArray::get($vars, 'width', '100%'), + dmArray::get($vars, 'height', '300px') + )) + ->navigationControl($vars['navigationControl']) + ->mapTypeControl($vars['mapTypeControl']) + ->scaleControl($vars['scaleControl']) + ->splash($vars['splash']); + + $this + ->addJavascript($map->getJavascripts()) + ->addStylesheet($map->getStylesheets()); + + return $map; + } + + protected function doRenderForIndex() + { + $vars = $this->getViewVars(); + + return $vars['address']; + } + +} \ No newline at end of file diff --git a/lib/helper/DmGoogleMapHelper.php b/lib/helper/DmGoogleMapHelper.php new file mode 100644 index 0000000..8680748 --- /dev/null +++ b/lib/helper/DmGoogleMapHelper.php @@ -0,0 +1,17 @@ +get('google_map_helper')->map(); +} + +/* + * Alternative to £map + */ +function £map() +{ + return _map(); +} \ No newline at end of file diff --git a/lib/view/dmGoogleMapHelper.php b/lib/view/dmGoogleMapHelper.php new file mode 100644 index 0000000..c138a3d --- /dev/null +++ b/lib/view/dmGoogleMapHelper.php @@ -0,0 +1,55 @@ +context = $context; + + $this->initialize($options); + } + + public function initialize(array $options) + { + $this->configure($options); + } + + /* + * Get a dmGoogleMapTag instance + */ + public function map() + { + $map = $this->context->get('google_map_tag'); + + $response = $this->context->getResponse(); + + foreach($map->getStylesheets() as $stylesheet) + { + $response->addStylesheet($stylesheet); + } + + foreach($map->getJavascripts() as $javascript) + { + $response->addJavascript($javascript); + } + + /* + * Async loading won't work + * as the api itself uses async loading + */ + if(!$this->context->getRequest()->isXmlHttpRequest()) + { + $response->addJavascript('dmGoogleMapPlugin.api'); + } + + return $map; + } + + public function £map() + { + return $this->map(); + } +} \ No newline at end of file diff --git a/lib/view/html/dmGoogleMapTag.php b/lib/view/html/dmGoogleMapTag.php new file mode 100644 index 0000000..be1a82c --- /dev/null +++ b/lib/view/html/dmGoogleMapTag.php @@ -0,0 +1,127 @@ +initialize($options); + } + + public function initialize(array $options = array()) + { + parent::initialize($options); + + $this + ->addAttributeToRemove(array('splash')) + ->addClass('dm_google_map') + ->setOption('mapTypeId', 'hybrid') + ->setOption('zoom', 14) + ->setOption('splash', ''); + } + + public function getDefaultOptions() + { + return array_merge(parent::getDefaultOptions(), array( + 'address' => null, + 'coords' => null + )); + } + + /* + * Change the splash + */ + public function splash($splash) + { + return $this->setOption('splash', (string) $splash); + } + + public function address($location) + { + return $this->setOption('address', (string) $location); + } + + public function coords($latitude, $longitude) + { + return $this->setOption('coords', array($latitude, $longitude)); + } + + public function mapTypeId($mapType) + { + return $this->setOption('mapTypeId', (string) $mapType); + } + + public function zoom($zoom) + { + return $this->setOption('zoom', (int) $zoom); + } + + public function navigationControl($bool) + { + return $this->setOption('navigationControl', (bool) $bool); + } + + public function mapTypeControl($bool) + { + return $this->setOption('mapTypeControl', (bool) $bool); + } + + public function scaleControl($bool) + { + return $this->setOption('scaleControl', (bool) $bool); + } + + public function render() + { + $preparedAttributes = $this->prepareAttributesForHtml($this->options); + + $splash = $preparedAttributes['splash']; + unset($preparedAttributes['splash']); + + $tag = '