/** * Generate content element */ public function generate() { if (TL_MODE == 'BE') { // get map data $objMap = \delahaye\googlemaps\MapModel::findByPk($this->dlh_googlemap); return '<h1>' . $objMap->title . '</h1>'; } return parent::generate(); }
/** * Get the center coordinates of the map * @param string * @return string */ public function getDefaultCoords($varValue) { if ($varValue) { return $varValue; } $objElement = \delahaye\googlemaps\ElementModel::findByPk(\Input::get('id')); $objMap = \delahaye\googlemaps\MapModel::findByPk($objElement->pid); $objElement->singleCoords = $objMap->center; $objElement->save(); return $objMap->center; }
/** * Links to the map for edit mode * @param obkject * @return array */ public function mapOptions(DataContainer $dc) { $objMaps = \delahaye\googlemaps\MapModel::findAll(); if (!$objMaps) { return array(); } while ($objMaps->next()) { $return[$objMaps->id] = sprintf('%s <a href="contao/main.php?do=dlh_googlemaps&act=edit&popup=1&id=%s&rt=%s"><img src="system/themes/default/images/edit.gif" width="12" height="12"></a>', $objMaps->title, $objMaps->id, REQUEST_TOKEN); } return $return; }
/** * Display a wildcard in the back end * @return string */ public function generate() { if (TL_MODE == 'BE') { $objMap = \delahaye\googlemaps\MapModel::findByPk($this->dlh_googlemap); $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['dlh_googlemaps'][0]) . ' ###'; $objTemplate->title = $this->headline; $objTemplate->id = $this->dlh_googlemap; $objTemplate->link = $objMap->title; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } return parent::generate(); }
/** * Get the map configuration * @param int * @param string * @param array * @return array */ public static function getMapData($intMap, $strFormat = '', $arrParams = false) { // set tag ending $strTagEnding = $strFormat == 'xhtml' ? ' />' : '>'; // get map data $objMap = \delahaye\googlemaps\MapModel::findByPk($intMap); if (!$objMap) { return false; } $arrMap = $objMap->row(); $arrMap['language'] = $GLOBALS['TL_LANGUAGE']; $arrMap['mapSize'] = deserialize($arrMap['mapSize']); $arrMap['mapSize'][2] = $arrMap['mapSize'][2] == 'pcnt' ? '%' : $arrMap['mapSize'][2]; $arrMap['mapTypesAvailable'] = deserialize($arrMap['mapTypesAvailable']); $arrMap['center'] = str_replace(' ', '', $arrMap['center']); $arrMap['draggable'] = $arrMap['draggable'] ? 'true' : 'false'; $arrMap['scrollwheel'] = $arrMap['scrollwheel'] ? 'true' : 'false'; $arrMap['disableDoubleClickZoom'] = $arrMap['disableDoubleClickZoom'] ? 'true' : 'false'; // parameters overwritten? if (is_array($arrParams) && count($arrParams) > 0) { foreach ($arrParams as $k => $v) { switch ($k) { case 'mapSize': if (is_array($v) && $v[0] > 0 && $v[1] > 0) { $arrMap[$k] = $v; } break; case 'zoom': if ($v > 0) { $arrMap[$k] = $v; } break; default: $arrMap[$k] = $v; break; } } } // generate static map begin $arrMap['staticMap'] = '<img src="http' . (\Environment::get('ssl') ? 's' : '') . '://maps.google.com/maps/api/staticmap?center=' . $arrMap['center'] . '&zoom=' . $arrMap['zoom'] . '&maptype=' . strtolower($arrMap['mapTypeId']) . '&sensor=' . ($arrMap['sensor'] ? 'true' : 'false') . '&language=' . $arrMap['language'] . '&size='; if ($arrMap['mapSize'][2] == 'px') { $arrMap['staticMap'] .= $arrMap['mapSize'][0] . 'x' . $arrMap['mapSize'][1]; } else { $arrMap['staticMap'] .= '800x600'; } // get elements data $arrMap['elements'] = array(); $objElements = \delahaye\googlemaps\ElementModel::findBy('pid', $intMap); if (is_object($objElements)) { $intCount = -1; while ($objElements->next()) { if ($objElements->published) { $intCount++; $tmpElement = self::getInstance()->getElementData($intMap, $intCount, $objElements->row()); $arrMap['staticMap'] .= $tmpElement['staticMapPart']; unset($tmpElement['staticMapPart']); $arrMap['elements'][] = $tmpElement; } } } // bundle the markers to positions in static maps, max 5 icons $intIcon = 1; foreach (self::$arrMarkers as $k => $v) { if ($intIcon <= 5) { $arrMap['staticMap'] .= '&' . $k . implode('|', $v); $intIcon++; } } // generate static map end $arrMap['staticMap'] .= '" alt="' . $GLOBALS['TL_LANG']['tl_dlh_googlemaps']['labels']['noscript'] . '"' . $strTagEnding; $arrMap['tabsCode'] = self::getTabsCode($intMap); return $arrMap; }