/**
  * Renders the map info window for the DataObject.
  *
  * Be sure to define a template for that, named by the decorated class suffixed with _MapInfoWindow
  * e.g. MyPage_MapInfoWindow
  *
  * You can change the suffix globally by editing the MapExtension.map_info_window_suffix config val
  *
  * @return string
  */
 public function getMappableMapContent()
 {
     $defaultTemplate = 'MapInfoWindow';
     $classTemplate = SSViewer::get_templates_by_class($this->owner->ClassName, Config::inst()->get('MapExtension', 'map_info_window_suffix'));
     $template = count($classTemplate) ? $classTemplate : $defaultTemplate;
     return MapUtil::sanitize($this->owner->renderWith($template));
 }
Example #2
0
 /**
  * @covers MapUtil::get
  */
 public function testGet()
 {
     $map = array("name" => "user name", "age" => 24, "city" => array("Montpellier", "Toulouse", 34000, "Paris"), "phone" => "047839749347");
     $actual = \MapUtil::get($map, "age");
     $excepted = 24;
     $this->assertEquals($excepted, $actual);
     $actual = \MapUtil::get($map, "city");
     $excepted = array("Montpellier", "Toulouse", 34000, "Paris");
     $this->assertEquals($excepted, $actual);
     $actual = \MapUtil::get($map, "email", "*****@*****.**");
     $excepted = "*****@*****.**";
     $this->assertEquals($excepted, $actual);
 }
 public function getRenderableMap($width = null, $height = null)
 {
     $gmap = MapUtil::get_map($this->owner);
     $w = $width ? $width : MapUtil::$map_width;
     $h = $height ? $height : MapUtil::$map_height;
     $gmap->setSize($w, $h);
     if ($this->RenderMarkers == true) {
         foreach ($this->owner->getIterator() as $marker) {
             $gmap->addMarkerAsObject($marker);
         }
     }
     return $gmap;
 }
 public function getRenderableMap($width = null, $height = null, $zoom = 9)
 {
     $gmap = MapUtil::get_map(new ArrayList(array($this->owner)));
     $w = $width ? $width : MapUtil::$map_width;
     $h = $height ? $height : MapUtil::$map_height;
     $gmap->setSize($w, $h);
     $gmap->setZoom($zoom);
     $gmap->setEnableAutomaticCenterZoom(false);
     if ($this->owner->MapPinEdited) {
         $gmap->setLatLongCenter(array('200', '4', $this->owner->getMappableLatitude(), $this->owner->getMappableLongitude()));
     }
     MapUtil::set_map_already_rendered(true);
     return $gmap;
 }
 public static function parse_googlestreetview($arguments, $caption = null, $parser = null)
 {
     // each of latitude, longitude and heading are required at a bare minimum
     if (!isset($arguments['latitude'])) {
         return '';
     }
     if (!isset($arguments['longitude'])) {
         return '';
     }
     if (!isset($arguments['heading'])) {
         return '';
     }
     // defaults - these can be overriden by using zoom and pitch in the shortcode
     $defaults = array('Zoom' => 1, 'Pitch' => 0);
     // ensure JavaScript for the map service is only downloaded once
     $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
     MapUtil::set_map_already_rendered(true);
     // convert parameters to CamelCase as per standard template conventions
     $arguments['Latitude'] = $arguments['latitude'];
     $arguments['Longitude'] = $arguments['longitude'];
     $arguments['Heading'] = $arguments['heading'];
     // optional parameter caption
     if (isset($arguments['caption'])) {
         $arguments['Caption'] = $arguments['caption'];
     }
     // optional parameter pitch
     if (isset($arguments['pitch'])) {
         $arguments['Pitch'] = $arguments['pitch'];
     }
     // optional parameter zoom
     if (isset($arguments['zoom'])) {
         $arguments['Zoom'] = $arguments['zoom'];
     }
     // the id of the dom element to be used to render the street view
     $arguments['DomID'] = 'google_streetview_' . self::$gsv_ctr;
     // incrememt the counter to ensure a unique id for each map canvas
     self::$gsv_ctr++;
     // merge defaults and arguments
     $customised = array_merge($defaults, $arguments);
     // Include google maps JS at the end of the page
     Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised);
     //get streetview template template
     $template = new SSViewer('GoogleStreetView');
     //return the template customised with the parmameters
     return $template->process(new ArrayData($customised));
 }
 public static function parse_googlemap($arguments, $caption = null, $parser = null)
 {
     // each of latitude and longitude are required at a bare minimum
     if (!isset($arguments['latitude'])) {
         return '';
     }
     if (!isset($arguments['longitude'])) {
         return '';
     }
     // defaults - can be overriden by using zoom and FIXME in the shortcode
     $defaults = array('Zoom' => 5, 'MapType' => 'road');
     // ensure JavaScript for the map service is only downloaded once
     $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered();
     MapUtil::set_map_already_rendered(true);
     // convert parameters to CamelCase as per standard template conventions
     $arguments['Latitude'] = $arguments['latitude'];
     $arguments['Longitude'] = $arguments['longitude'];
     // optional parameter caption
     if (isset($arguments['caption'])) {
         $arguments['Caption'] = $arguments['caption'];
     }
     if (isset($arguments['maptype'])) {
         $arguments['MapType'] = $arguments['maptype'];
     }
     // optional parameter zoom
     if (isset($arguments['zoom'])) {
         $arguments['Zoom'] = $arguments['zoom'];
     }
     // the id of the dom element to be used to render the street view
     $arguments['DomID'] = 'google_sc_map_' . self::$gsv_ctr;
     // fullscreen
     $arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen');
     // incrememt the counter to ensure a unique id for each map canvas
     self::$gsv_ctr++;
     // merge defaults and arguments
     $customised = array_merge($defaults, $arguments);
     // include JavaScript to be appended at the end of the page, namely params for map rendering
     Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised);
     //get map view template and render the HTML
     $template = new SSViewer('GoogleMapShortCode');
     //return the template customised with the parmameters
     return $template->process(new ArrayData($customised));
 }
 public function getMappableMapContent()
 {
     return MapUtil::sanitize($this->renderWith('ContactPageGoogleMapInfoWindow'));
 }
Example #8
0
 /**
  * Get the path info, which is everything that follows the application
  * node in the URL. (without query info).
  * The returned pathinfo will not start or end with '/'.
  *
  * @return String
  */
 public static function getPathInfo()
 {
     $appRoot = self::getAppRoot();
     // Get the URL path (everything until the '?')
     $path = MapUtil::get($_SERVER, 'CONTEXT_PREFIX');
     // CONTEXT_PREFIX is aparently new to apache 2.3.13
     // If undefined, fall back to previous method. This one, though, is known
     // to have a problem when the URL is root. ('/').
     if ($path === null || $path === "") {
         $path = isset($_SERVER['SCRIPT_URL']) ? $_SERVER['SCRIPT_URL'] : $_SERVER['PHP_SELF'];
     }
     $pathInfo = substr($path, strlen($appRoot));
     if (beginsWith($pathInfo, '/')) {
         $pathInfo = substr($pathInfo, 1);
     }
     if (endsWith($pathInfo, '/')) {
         $pathInfo = substr($pathInfo, 0, -1);
     }
     return $pathInfo;
 }
 /**
  * Get a new GoogleMapAPI object and load it with the default settings
  *
  * @return GoogleMapAPI
  */
 public static function instance()
 {
     self::$instances++;
     if (self::$allow_full_screen == null) {
         self::$allow_full_screen = Config::inst()->get('Mappable', 'allow_full_screen');
     }
     // for JS
     if (self::$allow_full_screen === false) {
         self:
         $allow_full_screen = 'asdfsda';
     }
     $url = Director::absoluteBaseURL();
     // remove http and https
     $url = str_replace('http://', '', $url);
     $url = str_replace('https://', '', $url);
     $parts = explode('/', $url);
     $host = $parts[0];
     $key = self::$api_key;
     // if an array, get the key by an array keyed by host
     if (is_array($key)) {
         $key = $key[$host];
     }
     $gmap = new MapAPI($key);
     $gmap->setDivId(self::$div_id . "_" . self::$instances);
     $gmap->setEnableAutomaticCenterZoom(self::$automatic_center);
     $gmap->setDisplayDirectionFields(self::$direction_fields);
     $gmap->setSize(self::$map_width, self::$map_height);
     $gmap->setDefaultHideMarker(self::$hide_marker);
     $gmap->setMapType(self::$map_type);
     $gmap->setInfoWindowWidth(self::$info_window_width);
     $gmap->setCenter(self::$center);
     $gmap->setIconSize(self::$iconWidth, self::$iconHeight);
     $gmap->setIncludeDownloadJavascript(self::$map_already_rendered);
     $gmap->setAllowFullScreen(self::$allow_full_screen);
     return $gmap;
 }