BxDolLocationMapGoogleStatic.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolLocationMapGoogleStatic extends BxDolLocationMap
  10. {
  11. /**
  12. * Get location map for single address
  13. * @param $aLocation location array with the following indexes:
  14. * lat, lng, country, state, city, zip, street, street_number
  15. * @param $sLocationHtml formatted address string
  16. * @param $aParams some specific params
  17. */
  18. public function getMapSingle($aLocation, $sLocationHtml = '', $aParams = array())
  19. {
  20. $sMapSize = '1000x144';
  21. if (!empty($aParams['location_map_google_static_size']))
  22. $sMapSize = $aParams['location_map_google_static_size'];
  23. $sZoom = (int)getParam('sys_location_map_zoom_default');
  24. if (!$sZoom)
  25. $sZoom = '7';
  26. if (!empty($aParams['location_map_google_static_zoom']))
  27. $sZoom = $aParams['location_map_google_static_zoom'];
  28. $sMapType = 'roadmap';
  29. if (!empty($aParams['location_map_google_static_maptype']))
  30. $sMapType = $aParams['location_map_google_static_maptype'];
  31. $sMapKey = trim(getParam('sys_maps_api_key'));
  32. $sLocationEncoded = rawurlencode(trim(strip_tags($sLocationHtml)));
  33. $iScale = isset($_COOKIE['devicePixelRatio']) && (int)$_COOKIE['devicePixelRatio'] >= 2 ? 2 : 1;
  34. $sLang = bx_lang_name();
  35. $this->addCssJs();
  36. return $this->_oTemplate->parseHtmlByName('location_map_google_static.html', array (
  37. 'map_img' => bx_proto() . '://maps.googleapis.com/maps/api/staticmap?center=' . $sLocationEncoded . '&zoom=' . $sZoom . '&size=' . $sMapSize . '&maptype=' . $sMapType . '&markers=size:small%7C' . $sLocationEncoded . '&scale=' . $iScale . '&language=' . $sLang . ($sMapKey ? '&key=' . $sMapKey : ''),
  38. 'location_string' => $sLocationHtml,
  39. ));
  40. }
  41. public function addCssJs()
  42. {
  43. parent::addCssJs();
  44. $this->_oTemplate->addCss('location_map_google_static.css');
  45. }
  46. }
  47. /** @} */