/** * Get a static map * * @param string $v Coordinates * @param int $w Width * @param int $h Height * @param int $z Zoom level * @param int $repeatCounter Repeat group counter * @param bool $tableView Is the static map in the table view * @param array $data Row / form data, needed for optional radius value * * @return string static map html */ protected function _staticMap($v, $w = null, $h = null, $z = null, $repeatCounter = 0, $tableView = false, $data = array()) { $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); /** * Width and height MUST be specified or static map call will fail. But as we allow for * leaving these params blank to get a 100% size full map, we have to set a default when * building a static map. Only real solution is to add YAFOs for "Static map width" and height. * But for now, just default to 200x150. */ if (is_null($w)) { $w = $params->get('fb_gm_mapwidth', '200'); $w = empty($w) || strstr($w, '%') ? '200' : $w; } if (is_null($h)) { $h = $params->get('fb_gm_mapheight', '150'); $h = empty($h) ? '150' : $h; } if (is_null($z)) { $z = $params->get('fb_gm_zoomlevel'); } $icon = urlencode($params->get('fb_gm_staticmap_icon')); $o = $this->_strToCoords($v, $z); $lat = trim($o->coords[0]); $lon = trim($o->coords[1]); switch ($params->get('fb_gm_maptype')) { case "G_SATELLITE_MAP": $type = 'satellite'; break; case "G_HYBRID_MAP": $type = 'hybrid'; break; case "TERRAIN": $type = 'terrain'; break; case "G_NORMAL_MAP": default: $type = 'roadmap'; break; } // New api3 url: $markers = ''; if ($icon !== '') { $markers .= 'icon:' . $icon . '|'; } $markers .= $lat . ',' . $lon; $uri = JURI::getInstance(); $src = $uri->getScheme() . '://maps.google.com/maps/api/staticmap?'; $attribs = array(); $attribs[] = 'center=' . $lat . ',' . $lon; $attribs[] = 'zoom=' . $z; $attribs[] = 'size=' . $w . 'x' . $h; $attribs[] = 'maptype=' . $type; $attribs[] = 'mobile=true'; $attribs[] = 'markers=' . $markers; $attribs[] = 'sensor=false'; $config = JComponentHelper::getParams('com_fabrik'); $apiKey = $config->get('google_api_key', ''); $client = $config->get('google_buisness_client_id', ''); $signature = $config->get('google_buisness_signature', ''); if ($client !== '') { if ($signature === '') { throw new Exception('You have entered a Google Maps Business Client id, but have not supplied a signature value'); } $attribs[] = 'client=' . $client; $attribs[] = 'signature=' . $signature; } elseif ($apiKey !== '') { $attribs[] = 'key=' . $apiKey; } if ($params->get('visual_refresh', false)) { $attribs[] = 'visual_refresh=true'; } // If radius widget is being used, build an encoded polyline representing a circle if ((int) $params->get('fb_gm_radius', '0') == 1) { require_once COM_FABRIK_FRONTEND . '/libs/googlemaps/polyline_encoder/class.polylineEncoder.php'; $polyEnc = new PolylineEncoder(); $radius = $this->_getFieldValue('fb_gm_radius_read_element', $data, $repeatCounter); if ($radius === false || !isset($radius)) { $radius = $params->get('fb_gm_radius_default', '50'); } $enc_str = $polyEnc->GMapCircle($lat, $lon, $radius); $attribs[] = 'path=weight:2%7Ccolor:black%7Cfillcolor:0x5599bb%7Cenc:' . $enc_str; } // Serve cached file from remote url require_once COM_FABRIK_FRONTEND . '/helpers/image.php'; $src .= implode('&', $attribs); $folder = 'cache/com_fabrik/staticmaps/'; $file = implode('.', $attribs) . '.png'; // If its not editable and there's no val don't show the map $layout = $this->getLayout('static'); $displayData = new stdClass(); if (!$tableView || $tableView && $params->get('fb_gm_staticmap_tableview', '0') === '1') { $displayData->src = Fabimage::cacheRemote($src, $folder, $file); // if cacheImage returned false, probably an issue with permissions on the cache folder, so punt to direct URL if ($displayData->src === false) { $displayData->src = $src; } } else { $displayData->src = $src; } $displayData->id = $id; $displayData->view = $tableView ? 'list' : 'details'; return $layout->render($displayData); }
/** * Get a static map * * @param string $v Coordinates * @param int $w Width * @param int $h Height * @param int $z Zoom level * @param int $repeatCounter Repeat group counter * @param bool $tableView Is the static map in the table view * @param array $data Row / form data, needed for optional radius value * * @return string static map html */ protected function _staticMap($v, $w = null, $h = null, $z = null, $repeatCounter = 0, $tableView = false, $data = array()) { $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); if (is_null($w)) { $w = $params->get('fb_gm_mapwidth'); } if (is_null($h)) { $h = $params->get('fb_gm_mapheight'); } if (is_null($z)) { $z = $params->get('fb_gm_zoomlevel'); } $icon = urlencode($params->get('fb_gm_staticmap_icon')); $o = $this->_strToCoords($v, $z); $lat = trim($o->coords[0]); $lon = trim($o->coords[1]); switch ($params->get('fb_gm_maptype')) { case "G_SATELLITE_MAP": $type = 'satellite'; break; case "G_HYBRID_MAP": $type = 'hybrid'; break; case "TERRAIN": $type = 'terrain'; break; case "G_NORMAL_MAP": default: $type = 'roadmap'; break; } // New api3 url: $markers = ''; if ($icon !== '') { $markers .= 'icon:' . $icon . '|'; } $markers .= $lat . ',' . $lon; $uri = JURI::getInstance(); $src = $uri->getScheme() . '://maps.google.com/maps/api/staticmap?'; $attribs = array(); $attribs[] = 'center=' . $lat . ',' . $lon; $attribs[] = 'zoom=' . $z; $attribs[] = 'size=' . $w . 'x' . $h; $attribs[] = 'maptype=' . $type; $attribs[] = 'mobile=true'; $attribs[] = 'markers=' . $markers; $attribs[] = 'sensor=false'; $config = JComponentHelper::getParams('com_fabrik'); $apiKey = $config->get('google_api_key', ''); $client = $config->get('google_buisness_client_id', ''); $signature = $config->get('google_buisness_signature', ''); if ($client !== '') { if ($signature === '') { throw new Exception('You have entered a Google Maps Business Client id, but have not supplied a signature value'); } $attribs[] = 'client=' . $client; $attribs[] = 'signature=' . $signature; } elseif ($apiKey !== '') { $attribs[] = 'key=' . $apiKey; } if ($params->get('visual_refresh', false)) { $attribs[] = 'visual_refresh=true'; } // If radius widget is being used, build an encoded polyline representing a circle if ((int) $params->get('fb_gm_radius', '0') == 1) { require_once COM_FABRIK_FRONTEND . '/libs/googlemaps/polyline_encoder/class.polylineEncoder.php'; $polyEnc = new PolylineEncoder(); $radius = $this->_getFieldValue('fb_gm_radius_read_element', $data, $repeatCounter); if ($radius === false || !isset($radius)) { $radius = $params->get('fb_gm_radius_default', '50'); } $enc_str = $polyEnc->GMapCircle($lat, $lon, $radius); $attribs[] = 'path=weight:2%7Ccolor:black%7Cfillcolor:0x5599bb%7Cenc:' . $enc_str; } // Serve cached file from remote url require_once COM_FABRIK_FRONTEND . '/helpers/image.php'; $src .= implode('&', $attribs); $folder = 'cache/com_fabrik/staticmaps/'; $file = implode('.', $attribs) . '.png'; $src = Fabimage::cacheRemote($src, $folder, $file); $id = $tableView ? '' : 'id="' . $id . '"'; $str = '<div ' . $id . 'class="gmStaticMap">'; $str .= '<img src="' . $src . '" alt="static map" />'; $str .= '</div>'; return $str; }