/** * AddressBook * * @copyright (c) AddressBook Development Team * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html * @package AddressBook */ function smarty_function_AddressShowGmap($params, &$smarty) { $dom = ZLanguage::getModuleDomain('AddressBook'); $assign = isset($params['assign']) ? $params['assign'] : null; $directions = ''; if (isset($params['directions'])) { $directions = '<a href="http://maps.google.com/maps?f=d&daddr=' . $params['lat_long']; if (isset($params['zoomlevel'])) { $directions .= '&z=' . $params['zoomlevel']; } $directions .= '" target="_blank">' . __('Get directions to this location', $dom) . '</a>'; } if (!empty($directions)) { $directions = '<div>' . $directions . '</div>'; } include_once 'modules/AddressBook/lib/vendor/GMaps/GoogleMapV3.php'; $map_id = 'googlemap'; if (isset($params['mapid'])) { $map_id .= $params['mapid']; } $app_id = 'ZikulaAddressBook'; $map = new GoogleMapAPI($map_id, $app_id); if (isset($params['maptype'])) { $map->setMapType($params['maptype']); // hybrid, satellite, terrain, roadmap } if (isset($params['zoomlevel'])) { $map->setZoomLevel($params['zoomlevel']); } $map->setTypeControlsStyle('dropdown'); $map->setWidth(isset($params['width']) && $params['width'] ? $params['width'] : '100%'); $map->setHeight(isset($params['height']) && $params['height'] ? $params['height'] : '400px'); // handle one (center) point if (isset($params['lat_long'])) { $arrLatLong = explode(',', $params['lat_long']); $map->setCenterCoords($arrLatLong[1], $arrLatLong[0]); $map->addMarkerByCoords($arrLatLong[1], $arrLatLong[0], $params['title'], $params['html'], $params['tooltip'], $params['icon'], $params['iconshadow']); } // API key if (isset($params['api_key'])) { $map->setApiKey($params['api_key']); } // handle array of points if (isset($params['points'])) { foreach ($params['points'] as $point) { $arrLatLong = explode(',', $point['lat_long']); $map->addMarkerByCoords($arrLatLong[1], $arrLatLong[0], $point['title'], $point['html'], $point['tooltip'], $point['icon'], $point['iconshadow']); } } // load the map $map->enableOnLoad(); if ($assign) { $result = $map->getHeaderJS() . $map->getMapJS() . $directions . $map->printMap() . $map->printOnLoad(); $smarty->assign($assign, $result); } else { PageUtil::addVar('rawtext', $map->getHeaderJS()); PageUtil::addVar('rawtext', $map->getMapJS()); return $directions . $map->printMap() . $map->printOnLoad(); } }
public function action_index() { require_once Kohana::find_file('vendor', 'php-googlemap/GoogleMap', 'php'); $this->before('/pages/maps'); $this->template->title = __('Map'); $height = Core::get('height', '100%'); $width = Core::get('width', '100%'); $map = new GoogleMapAPI(); $map->setWidth($width); $map->setHeight($height); $map->disableSidebar(); $map->setMapType('map'); $map->setZoomLevel(Core::get('zoom', core::config('advertisement.map_zoom'))); //$map->mobile = TRUE; $atributes = array("target='_blank'"); if (core::get('controls') == 0) { $map->disableMapControls(); $map->disableTypeControls(); $map->disableScaleControl(); $map->disableZoomEncompass(); $map->disableStreetViewControls(); $map->disableOverviewControl(); } //only 1 marker if (core::get('address') != '') { $map->addMarkerByAddress(core::get('address'), core::get('address')); } else { //last ads, you can modify this value at: general.feed_elements $ads = DB::select('a.seotitle')->select(array('c.seoname', 'category'), 'a.title', 'a.published', 'a.address')->from(array('ads', 'a'))->join(array('categories', 'c'), 'INNER')->on('a.id_category', '=', 'c.id_category')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->where('a.address', 'IS NOT', NULL)->order_by('published', 'desc')->limit(Core::config('general.map_elements'))->as_object()->cached()->execute(); foreach ($ads as $a) { //d($a); if (strlen($a->address) > 3) { $url = Route::url('ad', array('category' => $a->category, 'seotitle' => $a->seotitle)); $map->addMarkerByAddress($a->address, $a->title, HTML::anchor($url, $a->title, $atributes)); } } //only center if not a single ad $map->setCenterCoords(Core::get('lon', core::config('advertisement.center_lon')), Core::get('lat', core::config('advertisement.center_lat'))); } $this->template->map = $map; }