@@ -9,58 +9,58 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | interface Mappable { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * An accessor method for the latitude field. |
|
| 14 | - * @example |
|
| 15 | - * <code> |
|
| 16 | - * return $this->Lat; |
|
| 17 | - * </code> |
|
| 18 | - * |
|
| 19 | - * @return string |
|
| 20 | - */ |
|
| 21 | - public function getMappableLatitude(); |
|
| 12 | + /** |
|
| 13 | + * An accessor method for the latitude field. |
|
| 14 | + * @example |
|
| 15 | + * <code> |
|
| 16 | + * return $this->Lat; |
|
| 17 | + * </code> |
|
| 18 | + * |
|
| 19 | + * @return string |
|
| 20 | + */ |
|
| 21 | + public function getMappableLatitude(); |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * An accessor method for the longitude field. |
|
| 26 | - * @example |
|
| 27 | - * <code> |
|
| 28 | - * return $this->Long; |
|
| 29 | - * </code> |
|
| 30 | - * |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - public function getMappableLongitude(); |
|
| 24 | + /** |
|
| 25 | + * An accessor method for the longitude field. |
|
| 26 | + * @example |
|
| 27 | + * <code> |
|
| 28 | + * return $this->Long; |
|
| 29 | + * </code> |
|
| 30 | + * |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + public function getMappableLongitude(); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * An accessor method for the path to the marker pin for this point on the map. |
|
| 38 | - * If null or false, use the default Google Maps icon. |
|
| 39 | - * @example |
|
| 40 | - * <code> |
|
| 41 | - * return "mysite/images/map_icon.png"; |
|
| 42 | - * </code> |
|
| 43 | - * |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - public function getMappableMapPin(); |
|
| 36 | + /** |
|
| 37 | + * An accessor method for the path to the marker pin for this point on the map. |
|
| 38 | + * If null or false, use the default Google Maps icon. |
|
| 39 | + * @example |
|
| 40 | + * <code> |
|
| 41 | + * return "mysite/images/map_icon.png"; |
|
| 42 | + * </code> |
|
| 43 | + * |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + public function getMappableMapPin(); |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * An accessor method that returns the content for the map bubble popup. |
|
| 51 | - * It is best to use the {@see ViewableData::renderWith()} method to take advantaging |
|
| 52 | - * of templating syntax when rendering the object's content. |
|
| 53 | - * |
|
| 54 | - * Note: it is critical that the content be sanitized for safe inclusino in the rendered |
|
| 55 | - * JavaScript code for the map. {@see GoogleMapsUtil::sanitize()} |
|
| 56 | - * |
|
| 57 | - * @example |
|
| 58 | - * <code> |
|
| 59 | - * return GoogleMapsUtil::sanitize($this->renderWith('MapBubble')); |
|
| 60 | - * </code> |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - */ |
|
| 64 | - public function getMappableMapContent(); |
|
| 49 | + /** |
|
| 50 | + * An accessor method that returns the content for the map bubble popup. |
|
| 51 | + * It is best to use the {@see ViewableData::renderWith()} method to take advantaging |
|
| 52 | + * of templating syntax when rendering the object's content. |
|
| 53 | + * |
|
| 54 | + * Note: it is critical that the content be sanitized for safe inclusino in the rendered |
|
| 55 | + * JavaScript code for the map. {@see GoogleMapsUtil::sanitize()} |
|
| 56 | + * |
|
| 57 | + * @example |
|
| 58 | + * <code> |
|
| 59 | + * return GoogleMapsUtil::sanitize($this->renderWith('MapBubble')); |
|
| 60 | + * </code> |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + */ |
|
| 64 | + public function getMappableMapContent(); |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -2,78 +2,78 @@ |
||
| 2 | 2 | |
| 3 | 3 | class GoogleStreetViewShortCodeHandler { |
| 4 | 4 | |
| 5 | - /* Counter used to ensure unique div ids to allow for multiple StreetViews on on page */ |
|
| 6 | - private static $gsv_ctr = 1; |
|
| 5 | + /* Counter used to ensure unique div ids to allow for multiple StreetViews on on page */ |
|
| 6 | + private static $gsv_ctr = 1; |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | - public static function parse_googlestreetview($arguments, $caption = null, $parser = null) { |
|
| 10 | - // each of latitude, longitude and heading are required at a bare minimum |
|
| 11 | - if(!isset($arguments['latitude'])){ |
|
| 12 | - return ''; |
|
| 13 | - } |
|
| 9 | + public static function parse_googlestreetview($arguments, $caption = null, $parser = null) { |
|
| 10 | + // each of latitude, longitude and heading are required at a bare minimum |
|
| 11 | + if(!isset($arguments['latitude'])){ |
|
| 12 | + return ''; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - if(!isset($arguments['longitude'])){ |
|
| 16 | - return ''; |
|
| 17 | - } |
|
| 15 | + if(!isset($arguments['longitude'])){ |
|
| 16 | + return ''; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - if(!isset($arguments['heading'])){ |
|
| 20 | - return ''; |
|
| 21 | - } |
|
| 19 | + if(!isset($arguments['heading'])){ |
|
| 20 | + return ''; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - // defaults - these can be overriden by using zoom and pitch in the shortcode |
|
| 24 | - $defaults = array( |
|
| 25 | - 'Zoom' => 1, |
|
| 26 | - 'Pitch' => 0 |
|
| 27 | - ); |
|
| 23 | + // defaults - these can be overriden by using zoom and pitch in the shortcode |
|
| 24 | + $defaults = array( |
|
| 25 | + 'Zoom' => 1, |
|
| 26 | + 'Pitch' => 0 |
|
| 27 | + ); |
|
| 28 | 28 | |
| 29 | - // ensure JavaScript for the map service is only downloaded once |
|
| 30 | - $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered(); |
|
| 31 | - MapUtil::set_map_already_rendered(true); |
|
| 29 | + // ensure JavaScript for the map service is only downloaded once |
|
| 30 | + $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered(); |
|
| 31 | + MapUtil::set_map_already_rendered(true); |
|
| 32 | 32 | |
| 33 | - // convert parameters to CamelCase as per standard template conventions |
|
| 34 | - $arguments['Latitude'] = $arguments['latitude']; |
|
| 35 | - $arguments['Longitude'] = $arguments['longitude']; |
|
| 36 | - $arguments['Heading'] = $arguments['heading']; |
|
| 33 | + // convert parameters to CamelCase as per standard template conventions |
|
| 34 | + $arguments['Latitude'] = $arguments['latitude']; |
|
| 35 | + $arguments['Longitude'] = $arguments['longitude']; |
|
| 36 | + $arguments['Heading'] = $arguments['heading']; |
|
| 37 | 37 | |
| 38 | - // optional parameter caption |
|
| 39 | - if (isset($arguments['caption'])) { |
|
| 40 | - $arguments['Caption'] = $arguments['caption']; |
|
| 41 | - } |
|
| 38 | + // optional parameter caption |
|
| 39 | + if (isset($arguments['caption'])) { |
|
| 40 | + $arguments['Caption'] = $arguments['caption']; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // optional parameter pitch |
|
| 44 | - if (isset($arguments['pitch'])) { |
|
| 45 | - $arguments['Pitch'] = $arguments['pitch']; |
|
| 46 | - } |
|
| 43 | + // optional parameter pitch |
|
| 44 | + if (isset($arguments['pitch'])) { |
|
| 45 | + $arguments['Pitch'] = $arguments['pitch']; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // optional parameter zoom |
|
| 49 | - if (isset($arguments['zoom'])) { |
|
| 50 | - $arguments['Zoom'] = $arguments['zoom']; |
|
| 51 | - } |
|
| 48 | + // optional parameter zoom |
|
| 49 | + if (isset($arguments['zoom'])) { |
|
| 50 | + $arguments['Zoom'] = $arguments['zoom']; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - // the id of the dom element to be used to render the street view |
|
| 54 | - $arguments['DomID'] = 'google_streetview_'.self::$gsv_ctr; |
|
| 53 | + // the id of the dom element to be used to render the street view |
|
| 54 | + $arguments['DomID'] = 'google_streetview_'.self::$gsv_ctr; |
|
| 55 | 55 | |
| 56 | - // incrememt the counter to ensure a unique id for each map canvas |
|
| 57 | - self::$gsv_ctr++; |
|
| 56 | + // incrememt the counter to ensure a unique id for each map canvas |
|
| 57 | + self::$gsv_ctr++; |
|
| 58 | 58 | |
| 59 | - // merge defaults and arguments |
|
| 60 | - $customised = array_merge($defaults, $arguments); |
|
| 59 | + // merge defaults and arguments |
|
| 60 | + $customised = array_merge($defaults, $arguments); |
|
| 61 | 61 | |
| 62 | - // Include google maps JS at the end of the page |
|
| 63 | - //Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised); |
|
| 62 | + // Include google maps JS at the end of the page |
|
| 63 | + //Requirements::javascriptTemplate("mappable/javascript/google/streetview.google.template.js", $customised); |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - //get streetview template template |
|
| 67 | - $template = new SSViewer('GoogleStreetView'); |
|
| 66 | + //get streetview template template |
|
| 67 | + $template = new SSViewer('GoogleStreetView'); |
|
| 68 | 68 | |
| 69 | - //return the template customised with the parmameters |
|
| 70 | - return $template->process(new ArrayData($customised)); |
|
| 71 | - } |
|
| 69 | + //return the template customised with the parmameters |
|
| 70 | + return $template->process(new ArrayData($customised)); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * This is only used for testing, otherwise the sequence of tests change the number returned |
|
| 75 | - */ |
|
| 76 | - public static function resetCounter() { |
|
| 77 | - self::$gsv_ctr = 1; |
|
| 78 | - } |
|
| 73 | + /** |
|
| 74 | + * This is only used for testing, otherwise the sequence of tests change the number returned |
|
| 75 | + */ |
|
| 76 | + public static function resetCounter() { |
|
| 77 | + self::$gsv_ctr = 1; |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -2,73 +2,73 @@ |
||
| 2 | 2 | |
| 3 | 3 | class GoogleMapShortCodeHandler { |
| 4 | 4 | |
| 5 | - /* Counter used to ensure unique div ids to allow for multiple maps on on page */ |
|
| 6 | - private static $gsv_ctr = 1; |
|
| 7 | - |
|
| 8 | - public static function parse_googlemap($arguments, $caption = null, $parser = null) { |
|
| 9 | - // each of latitude and longitude are required at a bare minimum |
|
| 10 | - if(!isset($arguments['latitude'])){ |
|
| 11 | - return ''; |
|
| 12 | - } |
|
| 13 | - |
|
| 14 | - if(!isset($arguments['longitude'])){ |
|
| 15 | - return ''; |
|
| 16 | - } |
|
| 17 | - |
|
| 18 | - // defaults - can be overriden by using zoom and FIXME in the shortcode |
|
| 19 | - $defaults = array( |
|
| 20 | - 'Zoom' => 5, |
|
| 21 | - 'MapType' => 'road' |
|
| 22 | - ); |
|
| 23 | - |
|
| 24 | - // ensure JavaScript for the map service is only downloaded once |
|
| 25 | - $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered(); |
|
| 26 | - MapUtil::set_map_already_rendered(true); |
|
| 27 | - |
|
| 28 | - // convert parameters to CamelCase as per standard template conventions |
|
| 29 | - $arguments['Latitude'] = $arguments['latitude']; |
|
| 30 | - $arguments['Longitude'] = $arguments['longitude']; |
|
| 31 | - |
|
| 32 | - // optional parameter caption |
|
| 33 | - if (isset($arguments['caption'])) { |
|
| 34 | - $arguments['Caption'] = $arguments['caption']; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - if (isset($arguments['maptype'])) { |
|
| 38 | - $arguments['MapType'] = $arguments['maptype']; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // optional parameter zoom |
|
| 42 | - if (isset($arguments['zoom'])) { |
|
| 43 | - $arguments['Zoom'] = $arguments['zoom']; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - // the id of the dom element to be used to render the street view |
|
| 47 | - $arguments['DomID'] = 'google_sc_map_'.self::$gsv_ctr; |
|
| 48 | - |
|
| 49 | - // fullscreen |
|
| 50 | - $arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 51 | - |
|
| 52 | - // incrememt the counter to ensure a unique id for each map canvas |
|
| 53 | - self::$gsv_ctr++; |
|
| 54 | - |
|
| 55 | - // merge defaults and arguments |
|
| 56 | - $customised = array_merge($defaults, $arguments); |
|
| 57 | - |
|
| 58 | - // include JavaScript to be appended at the end of the page, namely params for map rendering |
|
| 59 | - //Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised); |
|
| 60 | - |
|
| 61 | - //get map view template and render the HTML |
|
| 62 | - $template = new SSViewer('GoogleMapShortCode'); |
|
| 63 | - |
|
| 64 | - //return the template customised with the parmameters |
|
| 65 | - return $template->process(new ArrayData($customised)); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * This is only used for testing, otherwise the sequence of tests change the number returned |
|
| 70 | - */ |
|
| 71 | - public static function resetCounter() { |
|
| 72 | - self::$gsv_ctr = 1; |
|
| 73 | - } |
|
| 5 | + /* Counter used to ensure unique div ids to allow for multiple maps on on page */ |
|
| 6 | + private static $gsv_ctr = 1; |
|
| 7 | + |
|
| 8 | + public static function parse_googlemap($arguments, $caption = null, $parser = null) { |
|
| 9 | + // each of latitude and longitude are required at a bare minimum |
|
| 10 | + if(!isset($arguments['latitude'])){ |
|
| 11 | + return ''; |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + if(!isset($arguments['longitude'])){ |
|
| 15 | + return ''; |
|
| 16 | + } |
|
| 17 | + |
|
| 18 | + // defaults - can be overriden by using zoom and FIXME in the shortcode |
|
| 19 | + $defaults = array( |
|
| 20 | + 'Zoom' => 5, |
|
| 21 | + 'MapType' => 'road' |
|
| 22 | + ); |
|
| 23 | + |
|
| 24 | + // ensure JavaScript for the map service is only downloaded once |
|
| 25 | + $arguments['DownloadJS'] = !MapUtil::get_map_already_rendered(); |
|
| 26 | + MapUtil::set_map_already_rendered(true); |
|
| 27 | + |
|
| 28 | + // convert parameters to CamelCase as per standard template conventions |
|
| 29 | + $arguments['Latitude'] = $arguments['latitude']; |
|
| 30 | + $arguments['Longitude'] = $arguments['longitude']; |
|
| 31 | + |
|
| 32 | + // optional parameter caption |
|
| 33 | + if (isset($arguments['caption'])) { |
|
| 34 | + $arguments['Caption'] = $arguments['caption']; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + if (isset($arguments['maptype'])) { |
|
| 38 | + $arguments['MapType'] = $arguments['maptype']; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // optional parameter zoom |
|
| 42 | + if (isset($arguments['zoom'])) { |
|
| 43 | + $arguments['Zoom'] = $arguments['zoom']; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + // the id of the dom element to be used to render the street view |
|
| 47 | + $arguments['DomID'] = 'google_sc_map_'.self::$gsv_ctr; |
|
| 48 | + |
|
| 49 | + // fullscreen |
|
| 50 | + $arguments['AllowFullScreen'] = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 51 | + |
|
| 52 | + // incrememt the counter to ensure a unique id for each map canvas |
|
| 53 | + self::$gsv_ctr++; |
|
| 54 | + |
|
| 55 | + // merge defaults and arguments |
|
| 56 | + $customised = array_merge($defaults, $arguments); |
|
| 57 | + |
|
| 58 | + // include JavaScript to be appended at the end of the page, namely params for map rendering |
|
| 59 | + //Requirements::javascriptTemplate("mappable/javascript/google/map.google.template.js", $customised); |
|
| 60 | + |
|
| 61 | + //get map view template and render the HTML |
|
| 62 | + $template = new SSViewer('GoogleMapShortCode'); |
|
| 63 | + |
|
| 64 | + //return the template customised with the parmameters |
|
| 65 | + return $template->process(new ArrayData($customised)); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * This is only used for testing, otherwise the sequence of tests change the number returned |
|
| 70 | + */ |
|
| 71 | + public static function resetCounter() { |
|
| 72 | + self::$gsv_ctr = 1; |
|
| 73 | + } |
|
| 74 | 74 | } |
@@ -2,95 +2,95 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class LatLongField extends FieldGroup { |
| 4 | 4 | |
| 5 | - protected $latField; |
|
| 5 | + protected $latField; |
|
| 6 | 6 | |
| 7 | - protected $longField; |
|
| 7 | + protected $longField; |
|
| 8 | 8 | |
| 9 | - protected $zoomField; |
|
| 9 | + protected $zoomField; |
|
| 10 | 10 | |
| 11 | - protected $buttonText; |
|
| 11 | + protected $buttonText; |
|
| 12 | 12 | |
| 13 | - private $guidePoints = null; |
|
| 13 | + private $guidePoints = null; |
|
| 14 | 14 | |
| 15 | - private static $ctr = 0; |
|
| 15 | + private static $ctr = 0; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string[] $buttonText |
|
| 19 | - */ |
|
| 20 | - public function __construct($children = array(), $buttonText = null) { |
|
| 21 | - self::$ctr++; |
|
| 17 | + /** |
|
| 18 | + * @param string[] $buttonText |
|
| 19 | + */ |
|
| 20 | + public function __construct($children = array(), $buttonText = null) { |
|
| 21 | + self::$ctr++; |
|
| 22 | 22 | |
| 23 | - if ((sizeof($children) < 2) || (sizeof($children) > 3) || |
|
| 24 | - (!$children[0] instanceof FormField) || |
|
| 25 | - (!$children[1] instanceof FormField) |
|
| 26 | - ) user_error('LatLongField argument 1 must be an array containing at least two FormField '. |
|
| 27 | - 'objects for Lat/Long values, respectively.', E_USER_ERROR); |
|
| 23 | + if ((sizeof($children) < 2) || (sizeof($children) > 3) || |
|
| 24 | + (!$children[0] instanceof FormField) || |
|
| 25 | + (!$children[1] instanceof FormField) |
|
| 26 | + ) user_error('LatLongField argument 1 must be an array containing at least two FormField '. |
|
| 27 | + 'objects for Lat/Long values, respectively.', E_USER_ERROR); |
|
| 28 | 28 | |
| 29 | - parent::__construct($children); |
|
| 29 | + parent::__construct($children); |
|
| 30 | 30 | |
| 31 | - $this->buttonText = $buttonText ? $buttonText : _t('LatLongField.LOOKUP', 'Search'); |
|
| 32 | - $this->latField = $children[0]->getName(); |
|
| 33 | - $this->longField = $children[1]->getName(); |
|
| 31 | + $this->buttonText = $buttonText ? $buttonText : _t('LatLongField.LOOKUP', 'Search'); |
|
| 32 | + $this->latField = $children[0]->getName(); |
|
| 33 | + $this->longField = $children[1]->getName(); |
|
| 34 | 34 | |
| 35 | - if (sizeof($children) == 3) { |
|
| 36 | - $this->zoomField = $children[2]->getName(); |
|
| 37 | - } |
|
| 38 | - $name = ""; |
|
| 39 | - foreach ($children as $field) { |
|
| 40 | - $name .= $field->getName(); |
|
| 41 | - } |
|
| 35 | + if (sizeof($children) == 3) { |
|
| 36 | + $this->zoomField = $children[2]->getName(); |
|
| 37 | + } |
|
| 38 | + $name = ""; |
|
| 39 | + foreach ($children as $field) { |
|
| 40 | + $name .= $field->getName(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // hide the lat long and zoom fields from the interface |
|
| 44 | - foreach ($this->FieldList() as $fieldToHide) { |
|
| 45 | - $fieldToHide->addExtraClass('hide'); |
|
| 46 | - } |
|
| 43 | + // hide the lat long and zoom fields from the interface |
|
| 44 | + foreach ($this->FieldList() as $fieldToHide) { |
|
| 45 | + $fieldToHide->addExtraClass('hide'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $this->name = $name; |
|
| 49 | - } |
|
| 48 | + $this->name = $name; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - public function FieldHolder($properties = array()) { |
|
| 53 | - Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js'); |
|
| 54 | - Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js'); |
|
| 55 | - Requirements::javascript(THIRDPARTY_DIR.'/jquery-metadata/jquery.metadata.js'); |
|
| 56 | - Requirements::javascript(MAPPABLE_MODULE_PATH.'/javascript/mapField.js'); |
|
| 52 | + public function FieldHolder($properties = array()) { |
|
| 53 | + Requirements::javascript(THIRDPARTY_DIR.'/jquery/jquery.js'); |
|
| 54 | + Requirements::javascript(THIRDPARTY_DIR.'/jquery-livequery/jquery.livequery.js'); |
|
| 55 | + Requirements::javascript(THIRDPARTY_DIR.'/jquery-metadata/jquery.metadata.js'); |
|
| 56 | + Requirements::javascript(MAPPABLE_MODULE_PATH.'/javascript/mapField.js'); |
|
| 57 | 57 | |
| 58 | - $attributes = array( |
|
| 59 | - 'class' => 'editableMap', |
|
| 60 | - 'id' => 'GoogleMap', |
|
| 61 | - 'data-LatFieldName' => $this->latField, |
|
| 62 | - 'data-LonFieldName' => $this->longField, |
|
| 63 | - 'data-ZoomFieldName' => $this->zoomField, |
|
| 64 | - 'data-UseMapBounds' => false |
|
| 65 | - ); |
|
| 58 | + $attributes = array( |
|
| 59 | + 'class' => 'editableMap', |
|
| 60 | + 'id' => 'GoogleMap', |
|
| 61 | + 'data-LatFieldName' => $this->latField, |
|
| 62 | + 'data-LonFieldName' => $this->longField, |
|
| 63 | + 'data-ZoomFieldName' => $this->zoomField, |
|
| 64 | + 'data-UseMapBounds' => false |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - Requirements::css('mappable/css/mapField.css'); |
|
| 67 | + Requirements::css('mappable/css/mapField.css'); |
|
| 68 | 68 | |
| 69 | - // check for and if required add guide points |
|
| 70 | - if (!empty($this->guidePoints)) { |
|
| 71 | - $latlongps = array(); |
|
| 69 | + // check for and if required add guide points |
|
| 70 | + if (!empty($this->guidePoints)) { |
|
| 71 | + $latlongps = array(); |
|
| 72 | 72 | |
| 73 | - foreach ($this->guidePoints as $guidepoint) { |
|
| 74 | - array_push($latlongps, $guidepoint); |
|
| 75 | - } |
|
| 73 | + foreach ($this->guidePoints as $guidepoint) { |
|
| 74 | + array_push($latlongps, $guidepoint); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $guidePointsJSON = json_encode($latlongps); |
|
| 78 | - // convert the mappable guidepoints to lat lon |
|
| 77 | + $guidePointsJSON = json_encode($latlongps); |
|
| 78 | + // convert the mappable guidepoints to lat lon |
|
| 79 | 79 | |
| 80 | - $attributes['data-GuidePoints'] = $guidePointsJSON; |
|
| 80 | + $attributes['data-GuidePoints'] = $guidePointsJSON; |
|
| 81 | 81 | |
| 82 | - // we only wish to change the bounds to those of all the points iff |
|
| 83 | - // the item currently has no location |
|
| 84 | - $attributes['data-useMapBounds'] = true; |
|
| 85 | - } |
|
| 86 | - $content = '<div class="editableMapWrapper">'.$this->create_tag( |
|
| 87 | - "div", |
|
| 88 | - $attributes |
|
| 89 | - ).'</div>'; |
|
| 82 | + // we only wish to change the bounds to those of all the points iff |
|
| 83 | + // the item currently has no location |
|
| 84 | + $attributes['data-useMapBounds'] = true; |
|
| 85 | + } |
|
| 86 | + $content = '<div class="editableMapWrapper">'.$this->create_tag( |
|
| 87 | + "div", |
|
| 88 | + $attributes |
|
| 89 | + ).'</div>'; |
|
| 90 | 90 | |
| 91 | - $this->FieldList()->push(new LiteralField('locationEditor', $content)); |
|
| 91 | + $this->FieldList()->push(new LiteralField('locationEditor', $content)); |
|
| 92 | 92 | |
| 93 | - $content2 = <<<HTML |
|
| 93 | + $content2 = <<<HTML |
|
| 94 | 94 | <div id="mapSearch"> |
| 95 | 95 | <input name="location_search" id="location_search" size=80/> |
| 96 | 96 | <button class="action" id="searchLocationButton">Search Location Name</button> |
@@ -99,12 +99,12 @@ discard block |
||
| 99 | 99 | </div> |
| 100 | 100 | HTML; |
| 101 | 101 | |
| 102 | - $this->FieldList()->push(new LiteralField('mapSearch', $content2)); |
|
| 102 | + $this->FieldList()->push(new LiteralField('mapSearch', $content2)); |
|
| 103 | 103 | |
| 104 | - return parent::FieldHolder(); |
|
| 105 | - } |
|
| 104 | + return parent::FieldHolder(); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /* |
|
| 107 | + /* |
|
| 108 | 108 | Set guidance points for the map being edited. For example in a photographic set show the map |
| 109 | 109 | position of some other images so that subsequent photo edits do not start with a map centred |
| 110 | 110 | at the origin |
@@ -112,16 +112,16 @@ discard block |
||
| 112 | 112 | @var newGuidePoints array of points expressed as associative arrays containing keys latitude |
| 113 | 113 | and longitude mapping to geographical locations |
| 114 | 114 | */ |
| 115 | - public function setGuidePoints($newGuidePoints) { |
|
| 116 | - $this->guidePoints = $newGuidePoints; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Accessor to guidepoints. For testing purposes |
|
| 121 | - * @return array guidepoints |
|
| 122 | - */ |
|
| 123 | - public function getGuidePoints() { |
|
| 124 | - return $this->guidePoints; |
|
| 125 | - } |
|
| 115 | + public function setGuidePoints($newGuidePoints) { |
|
| 116 | + $this->guidePoints = $newGuidePoints; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Accessor to guidepoints. For testing purposes |
|
| 121 | + * @return array guidepoints |
|
| 122 | + */ |
|
| 123 | + public function getGuidePoints() { |
|
| 124 | + return $this->guidePoints; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -8,27 +8,27 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class MappableDataObjectSet extends Extension { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Optional template values for the map info windows |
|
| 13 | - */ |
|
| 14 | - private $MarkerTemplateValues = null; |
|
| 11 | + /** |
|
| 12 | + * Optional template values for the map info windows |
|
| 13 | + */ |
|
| 14 | + private $MarkerTemplateValues = null; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Pass through values to the markers so that when rendering the map info windows, these |
|
| 18 | - * parameters are available to the template. This is of course optional |
|
| 19 | - * |
|
| 20 | - * @param array $values hash array of template key to template value |
|
| 21 | - */ |
|
| 22 | - public function setMarkerTemplateValues($values) { |
|
| 23 | - $this->MarkerTemplateValues = $values; |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * Pass through values to the markers so that when rendering the map info windows, these |
|
| 18 | + * parameters are available to the template. This is of course optional |
|
| 19 | + * |
|
| 20 | + * @param array $values hash array of template key to template value |
|
| 21 | + */ |
|
| 22 | + public function setMarkerTemplateValues($values) { |
|
| 23 | + $this->MarkerTemplateValues = $values; |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - public function getRenderableMap($width = null, $height = null) { |
|
| 27 | - $gmap = MapUtil::get_map($this->owner, $this->MarkerTemplateValues); |
|
| 28 | - $w = $width ? $width : MapUtil::$map_width; |
|
| 29 | - $h = $height ? $height : MapUtil::$map_height; |
|
| 30 | - $gmap->setSize($w,$h); |
|
| 31 | - return $gmap; |
|
| 32 | - } |
|
| 26 | + public function getRenderableMap($width = null, $height = null) { |
|
| 27 | + $gmap = MapUtil::get_map($this->owner, $this->MarkerTemplateValues); |
|
| 28 | + $w = $width ? $width : MapUtil::$map_width; |
|
| 29 | + $h = $height ? $height : MapUtil::$map_height; |
|
| 30 | + $gmap->setSize($w,$h); |
|
| 31 | + return $gmap; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | } |
@@ -17,699 +17,699 @@ |
||
| 17 | 17 | class MapAPI extends ViewableData |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** GoogleMap key **/ |
|
| 21 | - protected $googleMapKey = ''; |
|
| 20 | + /** GoogleMap key **/ |
|
| 21 | + protected $googleMapKey = ''; |
|
| 22 | 22 | |
| 23 | - /** GoogleMap ID for the HTML DIV **/ |
|
| 24 | - protected $googleMapId = 'googlemapapi'; |
|
| 23 | + /** GoogleMap ID for the HTML DIV **/ |
|
| 24 | + protected $googleMapId = 'googlemapapi'; |
|
| 25 | 25 | |
| 26 | - /* Additional CSS classes to use when rendering the map */ |
|
| 27 | - protected $set_additional_css_classes = ''; |
|
| 26 | + /* Additional CSS classes to use when rendering the map */ |
|
| 27 | + protected $set_additional_css_classes = ''; |
|
| 28 | 28 | |
| 29 | - /** Width of the gmap **/ |
|
| 30 | - protected $width = 800; |
|
| 29 | + /** Width of the gmap **/ |
|
| 30 | + protected $width = 800; |
|
| 31 | 31 | |
| 32 | - /** Height of the gmap **/ |
|
| 33 | - protected $height = 600; |
|
| 32 | + /** Height of the gmap **/ |
|
| 33 | + protected $height = 600; |
|
| 34 | 34 | |
| 35 | - /* array of lines to be drawn on the map */ |
|
| 36 | - protected $lines = array(); |
|
| 35 | + /* array of lines to be drawn on the map */ |
|
| 36 | + protected $lines = array(); |
|
| 37 | 37 | |
| 38 | - /* kml file to be rendered */ |
|
| 39 | - protected $kmlFiles = array(); |
|
| 38 | + /* kml file to be rendered */ |
|
| 39 | + protected $kmlFiles = array(); |
|
| 40 | 40 | |
| 41 | - /** Default zoom of the gmap **/ |
|
| 42 | - protected $zoom = 9; |
|
| 41 | + /** Default zoom of the gmap **/ |
|
| 42 | + protected $zoom = 9; |
|
| 43 | 43 | |
| 44 | - /** Enable the zoom of the Infowindow **/ |
|
| 45 | - protected $enableWindowZoom = false; |
|
| 44 | + /** Enable the zoom of the Infowindow **/ |
|
| 45 | + protected $enableWindowZoom = false; |
|
| 46 | 46 | |
| 47 | - /** Default zoom of the Infowindow **/ |
|
| 48 | - protected $infoWindowZoom = 13; |
|
| 47 | + /** Default zoom of the Infowindow **/ |
|
| 48 | + protected $infoWindowZoom = 13; |
|
| 49 | 49 | |
| 50 | - /** Lang of the gmap **/ |
|
| 51 | - protected $lang = 'en'; |
|
| 50 | + /** Lang of the gmap **/ |
|
| 51 | + protected $lang = 'en'; |
|
| 52 | 52 | |
| 53 | - /**Center of the gmap **/ |
|
| 54 | - protected $center = 'Paris, France'; |
|
| 53 | + /**Center of the gmap **/ |
|
| 54 | + protected $center = 'Paris, France'; |
|
| 55 | 55 | |
| 56 | - /* |
|
| 56 | + /* |
|
| 57 | 57 | Additional CSS classes to render as a class attribute for the div of the |
| 58 | 58 | map. Use this if you want more fine grained control over your map using |
| 59 | 59 | CSS. If blank it will be ignored |
| 60 | 60 | */ |
| 61 | - protected $additional_css_classes = ''; |
|
| 61 | + protected $additional_css_classes = ''; |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | - /* Decided whether or not to show the inline map css style on div creation */ |
|
| 65 | - protected $show_inline_map_div_style = true; |
|
| 64 | + /* Decided whether or not to show the inline map css style on div creation */ |
|
| 65 | + protected $show_inline_map_div_style = true; |
|
| 66 | 66 | |
| 67 | - protected $latLongCenter = null; |
|
| 67 | + protected $latLongCenter = null; |
|
| 68 | 68 | |
| 69 | - protected $jsonMapStyles = '[]'; |
|
| 69 | + protected $jsonMapStyles = '[]'; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Type of the gmap, can be: |
|
| 73 | - * 'road' (roadmap), |
|
| 74 | - * 'satellite' (sattelite/aerial photographs) |
|
| 75 | - * 'hybrid' (hybrid of road and satellite) |
|
| 76 | - * 'terrain' (terrain) |
|
| 77 | - * The JavaScript for the mapping service will convert this into a suitable mapping type |
|
| 78 | - */ |
|
| 71 | + /** |
|
| 72 | + * Type of the gmap, can be: |
|
| 73 | + * 'road' (roadmap), |
|
| 74 | + * 'satellite' (sattelite/aerial photographs) |
|
| 75 | + * 'hybrid' (hybrid of road and satellite) |
|
| 76 | + * 'terrain' (terrain) |
|
| 77 | + * The JavaScript for the mapping service will convert this into a suitable mapping type |
|
| 78 | + */ |
|
| 79 | 79 | |
| 80 | - protected $mapType = 'road'; |
|
| 80 | + protected $mapType = 'road'; |
|
| 81 | 81 | |
| 82 | 82 | |
| 83 | - /** Content of the HTML generated **/ |
|
| 84 | - protected $content = ''; |
|
| 83 | + /** Content of the HTML generated **/ |
|
| 84 | + protected $content = ''; |
|
| 85 | 85 | |
| 86 | - protected $mapService = 'google'; |
|
| 86 | + protected $mapService = 'google'; |
|
| 87 | 87 | |
| 88 | - /** Hide the marker by default **/ |
|
| 89 | - protected $defaultHideMarker = false; |
|
| 88 | + /** Hide the marker by default **/ |
|
| 89 | + protected $defaultHideMarker = false; |
|
| 90 | 90 | |
| 91 | - /** Extra content (marker, etc...) **/ |
|
| 92 | - protected $contentMarker = ''; |
|
| 91 | + /** Extra content (marker, etc...) **/ |
|
| 92 | + protected $contentMarker = ''; |
|
| 93 | 93 | |
| 94 | - // a list of markers, markers being associative arrays |
|
| 95 | - protected $markers = array(); |
|
| 94 | + // a list of markers, markers being associative arrays |
|
| 95 | + protected $markers = array(); |
|
| 96 | 96 | |
| 97 | - /** Use clusterer to display a lot of markers on the gmap **/ |
|
| 98 | - protected $useClusterer = false; |
|
| 99 | - protected $gridSize = 50; |
|
| 100 | - protected $maxZoom = 17; |
|
| 101 | - protected $clustererLibraryPath = "/mappable/javascript/google/markerclusterer.js"; |
|
| 97 | + /** Use clusterer to display a lot of markers on the gmap **/ |
|
| 98 | + protected $useClusterer = false; |
|
| 99 | + protected $gridSize = 50; |
|
| 100 | + protected $maxZoom = 17; |
|
| 101 | + protected $clustererLibraryPath = "/mappable/javascript/google/markerclusterer.js"; |
|
| 102 | 102 | |
| 103 | - /** Enable automatic center/zoom **/ |
|
| 104 | - protected $enableAutomaticCenterZoom = false; |
|
| 103 | + /** Enable automatic center/zoom **/ |
|
| 104 | + protected $enableAutomaticCenterZoom = false; |
|
| 105 | 105 | |
| 106 | - /** maximum longitude of all markers **/ |
|
| 107 | - protected $maxLng = -1000000; |
|
| 106 | + /** maximum longitude of all markers **/ |
|
| 107 | + protected $maxLng = -1000000; |
|
| 108 | 108 | |
| 109 | - /** minimum longitude of all markers **/ |
|
| 110 | - protected $minLng = 1000000; |
|
| 109 | + /** minimum longitude of all markers **/ |
|
| 110 | + protected $minLng = 1000000; |
|
| 111 | 111 | |
| 112 | - /** max latitude of all markers **/ |
|
| 113 | - protected $maxLat = -1000000; |
|
| 112 | + /** max latitude of all markers **/ |
|
| 113 | + protected $maxLat = -1000000; |
|
| 114 | 114 | |
| 115 | - /** min latitude of all markers **/ |
|
| 116 | - protected $minLat = 1000000; |
|
| 115 | + /** min latitude of all markers **/ |
|
| 116 | + protected $minLat = 1000000; |
|
| 117 | 117 | |
| 118 | - /** map center latitude (horizontal), calculated automatically as markers |
|
| 118 | + /** map center latitude (horizontal), calculated automatically as markers |
|
| 119 | 119 | are added to the map **/ |
| 120 | - protected $centerLat = null; |
|
| 120 | + protected $centerLat = null; |
|
| 121 | 121 | |
| 122 | - /** map center longitude (vertical), calculated automatically as markers |
|
| 122 | + /** map center longitude (vertical), calculated automatically as markers |
|
| 123 | 123 | are added to the map **/ |
| 124 | - protected $centerLng = null; |
|
| 124 | + protected $centerLng = null; |
|
| 125 | 125 | |
| 126 | - /** factor by which to fudge the boundaries so that when we zoom encompass, |
|
| 126 | + /** factor by which to fudge the boundaries so that when we zoom encompass, |
|
| 127 | 127 | the markers aren't too close to the edge **/ |
| 128 | - protected $coordCoef = 0.01; |
|
| 129 | - |
|
| 130 | - /* set this to true to render button to maximize / minimize a map */ |
|
| 131 | - protected $allowFullScreen = null; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Class constructor |
|
| 135 | - * |
|
| 136 | - * @param string $googleMapKey the googleMapKey |
|
| 137 | - */ |
|
| 138 | - |
|
| 139 | - public function __construct($googleMapKey = '') { |
|
| 140 | - $this->googleMapKey = $googleMapKey; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function setShowInlineMapDivStyle($new_show_inline_map_div_style) { |
|
| 144 | - $this->show_inline_map_div_style = $new_show_inline_map_div_style; |
|
| 145 | - return $this; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - public function setAdditionalCSSClasses($new_additional_css_classes) { |
|
| 149 | - $this->additional_css_classes = $new_additional_css_classes; |
|
| 150 | - return $this; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - public function setMapStyle($newStyles) { |
|
| 155 | - $this->jsonMapStyles = $newStyles; |
|
| 156 | - return $this; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Set the useClusterer parameter (optimization to display a lot of marker) |
|
| 161 | - * |
|
| 162 | - * @param boolean $useClusterer use cluster or not |
|
| 163 | - * @param int $gridSize grid size |
|
| 164 | - * @param int $maxZoom max zoom to cluster at |
|
| 165 | - * |
|
| 166 | - * * @return MapAPI This same object, in order to enable chaining of methods |
|
| 167 | - */ |
|
| 168 | - |
|
| 169 | - public function setClusterer($useClusterer, $gridSize = 50, $maxZoom = 17, |
|
| 170 | - $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js') { |
|
| 171 | - $this->useClusterer = $useClusterer; |
|
| 172 | - $this->gridSize = $gridSize; |
|
| 173 | - $this->maxZoom = $maxZoom; |
|
| 174 | - $this->clustererLibraryPath = $clustererLibraryPath; |
|
| 175 | - return $this; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Set the ID of the default gmap DIV |
|
| 180 | - * |
|
| 181 | - * @param string $googleMapId the google div ID |
|
| 182 | - * |
|
| 183 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 184 | - */ |
|
| 185 | - |
|
| 186 | - public function setDivId($googleMapId) { |
|
| 187 | - $this->googleMapId = $googleMapId; |
|
| 188 | - return $this; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Set the size of the gmap. If these values are not provided |
|
| 193 | - * then CSS is used instead |
|
| 194 | - * |
|
| 195 | - * @param int $width GoogleMap width |
|
| 196 | - * @param int $height GoogleMap height |
|
| 197 | - * |
|
| 198 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 199 | - */ |
|
| 200 | - |
|
| 201 | - public function setSize($width, $height) { |
|
| 202 | - $this->width = $width; |
|
| 203 | - $this->height = $height; |
|
| 204 | - return $this; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Set the lang of the gmap |
|
| 209 | - * |
|
| 210 | - * @param string $lang GoogleMap lang : fr,en,.. |
|
| 211 | - * |
|
| 212 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 213 | - */ |
|
| 214 | - |
|
| 215 | - public function setLang($lang) { |
|
| 216 | - $this->lang = $lang; |
|
| 217 | - return $this; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Set the zoom of the gmap |
|
| 222 | - * |
|
| 223 | - * @param int $zoom GoogleMap zoom. |
|
| 224 | - * |
|
| 225 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 226 | - */ |
|
| 227 | - |
|
| 228 | - public function setZoom($zoom) { |
|
| 229 | - $this->zoom = $zoom; |
|
| 230 | - return $this; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Set the zoom of the infowindow |
|
| 235 | - * |
|
| 236 | - * @param int $infoWindowZoom GoogleMap information window zoom. |
|
| 237 | - * |
|
| 238 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 239 | - */ |
|
| 240 | - |
|
| 241 | - public function setInfoWindowZoom($infoWindowZoom) { |
|
| 242 | - $this->infoWindowZoom = $infoWindowZoom; |
|
| 243 | - return $this; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Enable the zoom on the marker when you click on it |
|
| 248 | - * |
|
| 249 | - * @param boolean $enableWindowZoom info window enabled zoom. |
|
| 250 | - * |
|
| 251 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 252 | - */ |
|
| 253 | - |
|
| 254 | - public function setEnableWindowZoom($enableWindowZoom) { |
|
| 255 | - $this->enableWindowZoom = $enableWindowZoom; |
|
| 256 | - return $this; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Enable theautomatic center/zoom at the gmap load |
|
| 261 | - * |
|
| 262 | - * @param boolean $enableAutomaticCenterZoom enable automatic centre zoom |
|
| 263 | - * |
|
| 264 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 265 | - */ |
|
| 266 | - |
|
| 267 | - public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) { |
|
| 268 | - $this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom; |
|
| 269 | - return $this; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Set the center of the gmap (an address) |
|
| 274 | - * |
|
| 275 | - * @param string $center GoogleMap center (an address) |
|
| 276 | - * |
|
| 277 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 278 | - */ |
|
| 279 | - |
|
| 280 | - public function setCenter($center) { |
|
| 281 | - $this->center = $center; |
|
| 282 | - return $this; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * Set the type of the gmap. Also takes into account legacy settings |
|
| 287 | - * |
|
| 288 | - * FIXME - allow other valid settings in config for map type |
|
| 289 | - * |
|
| 290 | - * @param string $mapType Can be one of road,satellite,hybrid or terrain. Defaults to road |
|
| 291 | - * |
|
| 292 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 293 | - */ |
|
| 294 | - |
|
| 295 | - public function setMapType($mapType) { |
|
| 296 | - $this->mapType = $mapType; |
|
| 297 | - |
|
| 298 | - // deal with legacy values for backwards compatbility |
|
| 299 | - switch ($mapType) { |
|
| 300 | - case 'google.maps.MapTypeId.SATELLITE': |
|
| 301 | - $this->mapType = "satellite"; |
|
| 302 | - break; |
|
| 303 | - case 'google.maps.MapTypeId.G_HYBRID_MAP': |
|
| 304 | - $this->mapType = "hybrid"; |
|
| 305 | - break; |
|
| 306 | - case 'google.maps.MapTypeId.G_PHYSICAL_MAP': |
|
| 307 | - $this->mapType = "terrain"; |
|
| 308 | - break; |
|
| 309 | - case 'google.maps.MapTypeId.ROADMAP': |
|
| 310 | - $this->mapType = "road"; |
|
| 311 | - break; |
|
| 312 | - } |
|
| 313 | - return $this; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /* |
|
| 128 | + protected $coordCoef = 0.01; |
|
| 129 | + |
|
| 130 | + /* set this to true to render button to maximize / minimize a map */ |
|
| 131 | + protected $allowFullScreen = null; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Class constructor |
|
| 135 | + * |
|
| 136 | + * @param string $googleMapKey the googleMapKey |
|
| 137 | + */ |
|
| 138 | + |
|
| 139 | + public function __construct($googleMapKey = '') { |
|
| 140 | + $this->googleMapKey = $googleMapKey; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function setShowInlineMapDivStyle($new_show_inline_map_div_style) { |
|
| 144 | + $this->show_inline_map_div_style = $new_show_inline_map_div_style; |
|
| 145 | + return $this; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + public function setAdditionalCSSClasses($new_additional_css_classes) { |
|
| 149 | + $this->additional_css_classes = $new_additional_css_classes; |
|
| 150 | + return $this; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + public function setMapStyle($newStyles) { |
|
| 155 | + $this->jsonMapStyles = $newStyles; |
|
| 156 | + return $this; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Set the useClusterer parameter (optimization to display a lot of marker) |
|
| 161 | + * |
|
| 162 | + * @param boolean $useClusterer use cluster or not |
|
| 163 | + * @param int $gridSize grid size |
|
| 164 | + * @param int $maxZoom max zoom to cluster at |
|
| 165 | + * |
|
| 166 | + * * @return MapAPI This same object, in order to enable chaining of methods |
|
| 167 | + */ |
|
| 168 | + |
|
| 169 | + public function setClusterer($useClusterer, $gridSize = 50, $maxZoom = 17, |
|
| 170 | + $clustererLibraryPath = '/mappable/javascript/google/markerclusterer.js') { |
|
| 171 | + $this->useClusterer = $useClusterer; |
|
| 172 | + $this->gridSize = $gridSize; |
|
| 173 | + $this->maxZoom = $maxZoom; |
|
| 174 | + $this->clustererLibraryPath = $clustererLibraryPath; |
|
| 175 | + return $this; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Set the ID of the default gmap DIV |
|
| 180 | + * |
|
| 181 | + * @param string $googleMapId the google div ID |
|
| 182 | + * |
|
| 183 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 184 | + */ |
|
| 185 | + |
|
| 186 | + public function setDivId($googleMapId) { |
|
| 187 | + $this->googleMapId = $googleMapId; |
|
| 188 | + return $this; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Set the size of the gmap. If these values are not provided |
|
| 193 | + * then CSS is used instead |
|
| 194 | + * |
|
| 195 | + * @param int $width GoogleMap width |
|
| 196 | + * @param int $height GoogleMap height |
|
| 197 | + * |
|
| 198 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 199 | + */ |
|
| 200 | + |
|
| 201 | + public function setSize($width, $height) { |
|
| 202 | + $this->width = $width; |
|
| 203 | + $this->height = $height; |
|
| 204 | + return $this; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Set the lang of the gmap |
|
| 209 | + * |
|
| 210 | + * @param string $lang GoogleMap lang : fr,en,.. |
|
| 211 | + * |
|
| 212 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 213 | + */ |
|
| 214 | + |
|
| 215 | + public function setLang($lang) { |
|
| 216 | + $this->lang = $lang; |
|
| 217 | + return $this; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Set the zoom of the gmap |
|
| 222 | + * |
|
| 223 | + * @param int $zoom GoogleMap zoom. |
|
| 224 | + * |
|
| 225 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 226 | + */ |
|
| 227 | + |
|
| 228 | + public function setZoom($zoom) { |
|
| 229 | + $this->zoom = $zoom; |
|
| 230 | + return $this; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Set the zoom of the infowindow |
|
| 235 | + * |
|
| 236 | + * @param int $infoWindowZoom GoogleMap information window zoom. |
|
| 237 | + * |
|
| 238 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 239 | + */ |
|
| 240 | + |
|
| 241 | + public function setInfoWindowZoom($infoWindowZoom) { |
|
| 242 | + $this->infoWindowZoom = $infoWindowZoom; |
|
| 243 | + return $this; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Enable the zoom on the marker when you click on it |
|
| 248 | + * |
|
| 249 | + * @param boolean $enableWindowZoom info window enabled zoom. |
|
| 250 | + * |
|
| 251 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 252 | + */ |
|
| 253 | + |
|
| 254 | + public function setEnableWindowZoom($enableWindowZoom) { |
|
| 255 | + $this->enableWindowZoom = $enableWindowZoom; |
|
| 256 | + return $this; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Enable theautomatic center/zoom at the gmap load |
|
| 261 | + * |
|
| 262 | + * @param boolean $enableAutomaticCenterZoom enable automatic centre zoom |
|
| 263 | + * |
|
| 264 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 265 | + */ |
|
| 266 | + |
|
| 267 | + public function setEnableAutomaticCenterZoom($enableAutomaticCenterZoom) { |
|
| 268 | + $this->enableAutomaticCenterZoom = $enableAutomaticCenterZoom; |
|
| 269 | + return $this; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Set the center of the gmap (an address) |
|
| 274 | + * |
|
| 275 | + * @param string $center GoogleMap center (an address) |
|
| 276 | + * |
|
| 277 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 278 | + */ |
|
| 279 | + |
|
| 280 | + public function setCenter($center) { |
|
| 281 | + $this->center = $center; |
|
| 282 | + return $this; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * Set the type of the gmap. Also takes into account legacy settings |
|
| 287 | + * |
|
| 288 | + * FIXME - allow other valid settings in config for map type |
|
| 289 | + * |
|
| 290 | + * @param string $mapType Can be one of road,satellite,hybrid or terrain. Defaults to road |
|
| 291 | + * |
|
| 292 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 293 | + */ |
|
| 294 | + |
|
| 295 | + public function setMapType($mapType) { |
|
| 296 | + $this->mapType = $mapType; |
|
| 297 | + |
|
| 298 | + // deal with legacy values for backwards compatbility |
|
| 299 | + switch ($mapType) { |
|
| 300 | + case 'google.maps.MapTypeId.SATELLITE': |
|
| 301 | + $this->mapType = "satellite"; |
|
| 302 | + break; |
|
| 303 | + case 'google.maps.MapTypeId.G_HYBRID_MAP': |
|
| 304 | + $this->mapType = "hybrid"; |
|
| 305 | + break; |
|
| 306 | + case 'google.maps.MapTypeId.G_PHYSICAL_MAP': |
|
| 307 | + $this->mapType = "terrain"; |
|
| 308 | + break; |
|
| 309 | + case 'google.maps.MapTypeId.ROADMAP': |
|
| 310 | + $this->mapType = "road"; |
|
| 311 | + break; |
|
| 312 | + } |
|
| 313 | + return $this; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /* |
|
| 317 | 317 | Set whether or not to allow the full screen tools |
| 318 | 318 | @return MapAPI This same object, in order to enable chaining of methods |
| 319 | 319 | */ |
| 320 | - public function setAllowFullScreen($allowed) { |
|
| 321 | - $this->allowFullScreen = $allowed; |
|
| 322 | - return $this; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Set the center of the gmap |
|
| 327 | - * |
|
| 328 | - * @return MapAPI This same object, in order to enable chaining of methods |
|
| 329 | - **/ |
|
| 330 | - public function setLatLongCenter($center) { |
|
| 331 | - // error check, we want an associative array with lat,lng keys numeric |
|
| 332 | - |
|
| 333 | - if (!is_array($center)) { |
|
| 334 | - throw new InvalidArgumentException('Center must be an associative array containing lat,lng'); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $keys = array_keys($center); |
|
| 338 | - sort($keys); |
|
| 339 | - if (implode(',', $keys) != 'lat,lng') { |
|
| 340 | - throw new InvalidArgumentException('Keys provided must be lat, lng'); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - $this->latLongCenter = $center; |
|
| 344 | - return $this; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Set the defaultHideMarker |
|
| 349 | - * |
|
| 350 | - * @param boolean $defaultHideMarker hide all the markers on the map by default |
|
| 351 | - * |
|
| 352 | - * @return MapAPI |
|
| 353 | - */ |
|
| 354 | - |
|
| 355 | - public function setDefaultHideMarker($defaultHideMarker) { |
|
| 356 | - $this->defaultHideMarker = $defaultHideMarker; |
|
| 357 | - return $this; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Get the google map content |
|
| 362 | - * |
|
| 363 | - * @return string the google map html code |
|
| 364 | - */ |
|
| 365 | - |
|
| 366 | - public function getGoogleMap() { |
|
| 367 | - return $this->content; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Get URL content using cURL. |
|
| 373 | - * |
|
| 374 | - * @param string $url the url |
|
| 375 | - * |
|
| 376 | - * @return string the html code |
|
| 377 | - * |
|
| 378 | - * @todo add proxy settings |
|
| 379 | - */ |
|
| 380 | - |
|
| 381 | - public function getContent($url) { |
|
| 382 | - $curl = curl_init(); |
|
| 383 | - curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
| 384 | - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
|
| 385 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|
| 386 | - curl_setopt($curl, CURLOPT_URL, $url); |
|
| 387 | - $data = curl_exec($curl); |
|
| 388 | - curl_close($curl); |
|
| 389 | - return $data; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Geocoding an address (address -> lat,lng) |
|
| 394 | - * |
|
| 395 | - * @param string $address an address |
|
| 396 | - * |
|
| 397 | - * @return string array with precision, lat & lng |
|
| 398 | - */ |
|
| 399 | - |
|
| 400 | - public function geocoding($address) { |
|
| 401 | - $geocoder = new MappableGoogleGeocoder(); |
|
| 402 | - $locations = $geocoder->getLocations($address); |
|
| 403 | - $result = null; |
|
| 404 | - if (!empty($locations)) { |
|
| 405 | - $place = $locations[0]; |
|
| 406 | - $location = $place['geometry']['location']; |
|
| 407 | - $result = array( |
|
| 408 | - 'lat' => $location['lat'], |
|
| 409 | - 'lon' => $location['lng'], |
|
| 410 | - 'geocoded' => true |
|
| 411 | - ); |
|
| 412 | - |
|
| 413 | - } else { |
|
| 414 | - $result = array(); // no results |
|
| 415 | - } |
|
| 416 | - return $result; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Add marker by his coord |
|
| 421 | - * |
|
| 422 | - * @param string $lat lat |
|
| 423 | - * @param string $lng lngs |
|
| 424 | - * @param string $html html code display in the info window |
|
| 425 | - * @param string $category marker category |
|
| 426 | - * @param string $icon an icon url |
|
| 427 | - * |
|
| 428 | - * @return MapAPI |
|
| 429 | - */ |
|
| 430 | - |
|
| 431 | - public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') { |
|
| 432 | - $m = array( |
|
| 433 | - 'latitude' => $lat, |
|
| 434 | - 'longitude' => $lng, |
|
| 435 | - 'html' => $html, |
|
| 436 | - 'category' => $category, |
|
| 437 | - 'icon' => $icon |
|
| 438 | - ); |
|
| 439 | - array_push($this->markers, $m); |
|
| 440 | - return $this; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Add marker by his address |
|
| 446 | - * |
|
| 447 | - * @param string $address an ddress |
|
| 448 | - * @param string $content html code display in the info window |
|
| 449 | - * @param string $category marker category |
|
| 450 | - * @param string $icon an icon url |
|
| 451 | - * |
|
| 452 | - * @return MapAPI |
|
| 453 | - */ |
|
| 454 | - |
|
| 455 | - public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') { |
|
| 456 | - $point = $this->geocoding($address); |
|
| 457 | - if ($point !== null) { |
|
| 458 | - $this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon); |
|
| 459 | - } |
|
| 460 | - return $this; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Add marker by an array of coord |
|
| 465 | - * |
|
| 466 | - * @param array $coordtab an array of lat,lng,content |
|
| 467 | - * @param string $category marker category |
|
| 468 | - * @param string $icon an icon url |
|
| 469 | - * |
|
| 470 | - * @return MapAPI |
|
| 471 | - */ |
|
| 472 | - |
|
| 473 | - public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') { |
|
| 474 | - foreach ($coordtab as $coord) { |
|
| 475 | - $this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon); |
|
| 476 | - } |
|
| 477 | - return $this; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Adds a {@link ViewableData} object that implements {@link Mappable} |
|
| 483 | - * to the map. |
|
| 484 | - * @param $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
| 485 | - * |
|
| 486 | - * @param ViewableData $obj |
|
| 487 | - */ |
|
| 488 | - public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) { |
|
| 489 | - $extensionsImplementMappable = false; |
|
| 490 | - $extensions = Object::get_extensions(get_class($obj)); |
|
| 491 | - if (is_array($extensions)) { |
|
| 492 | - |
|
| 493 | - foreach ($extensions as $extension) { |
|
| 494 | - $class = new ReflectionClass($extension); |
|
| 495 | - if ($class->implementsInterface('Mappable')) { |
|
| 496 | - $extensionsImplementMappable = true; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if ($extensionsImplementMappable || |
|
| 503 | - ($obj instanceof Mappable) || |
|
| 504 | - (Object::has_extension($obj->ClassName, 'MapExtension')) |
|
| 505 | - ) { |
|
| 506 | - $cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : "default"; |
|
| 507 | - if ($infowindowtemplateparams !== null) { |
|
| 508 | - foreach ($infowindowtemplateparams as $key => $value) { |
|
| 509 | - $obj->{$key} = $value; |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - $this->addMarkerByCoords( |
|
| 513 | - $obj->getMappableLatitude(), |
|
| 514 | - $obj->getMappableLongitude(), |
|
| 515 | - $obj->getMappableMapContent(), |
|
| 516 | - $cat, |
|
| 517 | - $obj->getMappableMapPin() |
|
| 518 | - ); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - return $this; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Draws a line between two {@link ViewableData} objects |
|
| 527 | - * |
|
| 528 | - * @param ViewableData $one The first point |
|
| 529 | - * @param ViewableData $two The second point |
|
| 530 | - * @param string $color The hexidecimal color of the line |
|
| 531 | - */ |
|
| 532 | - public function connectPoints(ViewableData $one, ViewableData $two, $color = "#FF3300") { |
|
| 533 | - $this->addLine( |
|
| 534 | - array($one->getMappableLatitude(), $one->getMappableLongitude()), |
|
| 535 | - array($two->getMappableLatitude(), $two->getMappableLongitude()), |
|
| 536 | - $color |
|
| 537 | - ); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - public function forTemplate() { |
|
| 541 | - $this->generate(); |
|
| 542 | - MapUtil::set_map_already_rendered(true); |
|
| 543 | - return $this->getGoogleMap(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Add a KML file which will be rendered on this map. Normally used for likes |
|
| 548 | - * of GPS traces from activities |
|
| 549 | - * |
|
| 550 | - * @param string $url url of the kml file compatible with gmap and gearth |
|
| 551 | - * |
|
| 552 | - * @return MapAPI |
|
| 553 | - */ |
|
| 554 | - |
|
| 555 | - public function addKML($url) { |
|
| 556 | - array_push($this->kmlFiles, $url); |
|
| 557 | - return $this; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /* |
|
| 320 | + public function setAllowFullScreen($allowed) { |
|
| 321 | + $this->allowFullScreen = $allowed; |
|
| 322 | + return $this; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Set the center of the gmap |
|
| 327 | + * |
|
| 328 | + * @return MapAPI This same object, in order to enable chaining of methods |
|
| 329 | + **/ |
|
| 330 | + public function setLatLongCenter($center) { |
|
| 331 | + // error check, we want an associative array with lat,lng keys numeric |
|
| 332 | + |
|
| 333 | + if (!is_array($center)) { |
|
| 334 | + throw new InvalidArgumentException('Center must be an associative array containing lat,lng'); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $keys = array_keys($center); |
|
| 338 | + sort($keys); |
|
| 339 | + if (implode(',', $keys) != 'lat,lng') { |
|
| 340 | + throw new InvalidArgumentException('Keys provided must be lat, lng'); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + $this->latLongCenter = $center; |
|
| 344 | + return $this; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Set the defaultHideMarker |
|
| 349 | + * |
|
| 350 | + * @param boolean $defaultHideMarker hide all the markers on the map by default |
|
| 351 | + * |
|
| 352 | + * @return MapAPI |
|
| 353 | + */ |
|
| 354 | + |
|
| 355 | + public function setDefaultHideMarker($defaultHideMarker) { |
|
| 356 | + $this->defaultHideMarker = $defaultHideMarker; |
|
| 357 | + return $this; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Get the google map content |
|
| 362 | + * |
|
| 363 | + * @return string the google map html code |
|
| 364 | + */ |
|
| 365 | + |
|
| 366 | + public function getGoogleMap() { |
|
| 367 | + return $this->content; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Get URL content using cURL. |
|
| 373 | + * |
|
| 374 | + * @param string $url the url |
|
| 375 | + * |
|
| 376 | + * @return string the html code |
|
| 377 | + * |
|
| 378 | + * @todo add proxy settings |
|
| 379 | + */ |
|
| 380 | + |
|
| 381 | + public function getContent($url) { |
|
| 382 | + $curl = curl_init(); |
|
| 383 | + curl_setopt($curl, CURLOPT_TIMEOUT, 10); |
|
| 384 | + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); |
|
| 385 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); |
|
| 386 | + curl_setopt($curl, CURLOPT_URL, $url); |
|
| 387 | + $data = curl_exec($curl); |
|
| 388 | + curl_close($curl); |
|
| 389 | + return $data; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Geocoding an address (address -> lat,lng) |
|
| 394 | + * |
|
| 395 | + * @param string $address an address |
|
| 396 | + * |
|
| 397 | + * @return string array with precision, lat & lng |
|
| 398 | + */ |
|
| 399 | + |
|
| 400 | + public function geocoding($address) { |
|
| 401 | + $geocoder = new MappableGoogleGeocoder(); |
|
| 402 | + $locations = $geocoder->getLocations($address); |
|
| 403 | + $result = null; |
|
| 404 | + if (!empty($locations)) { |
|
| 405 | + $place = $locations[0]; |
|
| 406 | + $location = $place['geometry']['location']; |
|
| 407 | + $result = array( |
|
| 408 | + 'lat' => $location['lat'], |
|
| 409 | + 'lon' => $location['lng'], |
|
| 410 | + 'geocoded' => true |
|
| 411 | + ); |
|
| 412 | + |
|
| 413 | + } else { |
|
| 414 | + $result = array(); // no results |
|
| 415 | + } |
|
| 416 | + return $result; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Add marker by his coord |
|
| 421 | + * |
|
| 422 | + * @param string $lat lat |
|
| 423 | + * @param string $lng lngs |
|
| 424 | + * @param string $html html code display in the info window |
|
| 425 | + * @param string $category marker category |
|
| 426 | + * @param string $icon an icon url |
|
| 427 | + * |
|
| 428 | + * @return MapAPI |
|
| 429 | + */ |
|
| 430 | + |
|
| 431 | + public function addMarkerByCoords($lat, $lng, $html = '', $category = '', $icon = '') { |
|
| 432 | + $m = array( |
|
| 433 | + 'latitude' => $lat, |
|
| 434 | + 'longitude' => $lng, |
|
| 435 | + 'html' => $html, |
|
| 436 | + 'category' => $category, |
|
| 437 | + 'icon' => $icon |
|
| 438 | + ); |
|
| 439 | + array_push($this->markers, $m); |
|
| 440 | + return $this; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Add marker by his address |
|
| 446 | + * |
|
| 447 | + * @param string $address an ddress |
|
| 448 | + * @param string $content html code display in the info window |
|
| 449 | + * @param string $category marker category |
|
| 450 | + * @param string $icon an icon url |
|
| 451 | + * |
|
| 452 | + * @return MapAPI |
|
| 453 | + */ |
|
| 454 | + |
|
| 455 | + public function addMarkerByAddress($address, $content = '', $category = '', $icon = '') { |
|
| 456 | + $point = $this->geocoding($address); |
|
| 457 | + if ($point !== null) { |
|
| 458 | + $this->addMarkerByCoords($point['lat'], $point['lon'], $content, $category, $icon); |
|
| 459 | + } |
|
| 460 | + return $this; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Add marker by an array of coord |
|
| 465 | + * |
|
| 466 | + * @param array $coordtab an array of lat,lng,content |
|
| 467 | + * @param string $category marker category |
|
| 468 | + * @param string $icon an icon url |
|
| 469 | + * |
|
| 470 | + * @return MapAPI |
|
| 471 | + */ |
|
| 472 | + |
|
| 473 | + public function addArrayMarkerByCoords($coordtab, $category = '', $icon = '') { |
|
| 474 | + foreach ($coordtab as $coord) { |
|
| 475 | + $this->addMarkerByCoords($coord[0], $coord[1], $coord[2], $category, $icon); |
|
| 476 | + } |
|
| 477 | + return $this; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Adds a {@link ViewableData} object that implements {@link Mappable} |
|
| 483 | + * to the map. |
|
| 484 | + * @param $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
| 485 | + * |
|
| 486 | + * @param ViewableData $obj |
|
| 487 | + */ |
|
| 488 | + public function addMarkerAsObject(ViewableData $obj, $infowindowtemplateparams = null) { |
|
| 489 | + $extensionsImplementMappable = false; |
|
| 490 | + $extensions = Object::get_extensions(get_class($obj)); |
|
| 491 | + if (is_array($extensions)) { |
|
| 492 | + |
|
| 493 | + foreach ($extensions as $extension) { |
|
| 494 | + $class = new ReflectionClass($extension); |
|
| 495 | + if ($class->implementsInterface('Mappable')) { |
|
| 496 | + $extensionsImplementMappable = true; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if ($extensionsImplementMappable || |
|
| 503 | + ($obj instanceof Mappable) || |
|
| 504 | + (Object::has_extension($obj->ClassName, 'MapExtension')) |
|
| 505 | + ) { |
|
| 506 | + $cat = $obj->hasMethod('getMappableMapCategory') ? $obj->getMappableMapCategory() : "default"; |
|
| 507 | + if ($infowindowtemplateparams !== null) { |
|
| 508 | + foreach ($infowindowtemplateparams as $key => $value) { |
|
| 509 | + $obj->{$key} = $value; |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + $this->addMarkerByCoords( |
|
| 513 | + $obj->getMappableLatitude(), |
|
| 514 | + $obj->getMappableLongitude(), |
|
| 515 | + $obj->getMappableMapContent(), |
|
| 516 | + $cat, |
|
| 517 | + $obj->getMappableMapPin() |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + return $this; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Draws a line between two {@link ViewableData} objects |
|
| 527 | + * |
|
| 528 | + * @param ViewableData $one The first point |
|
| 529 | + * @param ViewableData $two The second point |
|
| 530 | + * @param string $color The hexidecimal color of the line |
|
| 531 | + */ |
|
| 532 | + public function connectPoints(ViewableData $one, ViewableData $two, $color = "#FF3300") { |
|
| 533 | + $this->addLine( |
|
| 534 | + array($one->getMappableLatitude(), $one->getMappableLongitude()), |
|
| 535 | + array($two->getMappableLatitude(), $two->getMappableLongitude()), |
|
| 536 | + $color |
|
| 537 | + ); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + public function forTemplate() { |
|
| 541 | + $this->generate(); |
|
| 542 | + MapUtil::set_map_already_rendered(true); |
|
| 543 | + return $this->getGoogleMap(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Add a KML file which will be rendered on this map. Normally used for likes |
|
| 548 | + * of GPS traces from activities |
|
| 549 | + * |
|
| 550 | + * @param string $url url of the kml file compatible with gmap and gearth |
|
| 551 | + * |
|
| 552 | + * @return MapAPI |
|
| 553 | + */ |
|
| 554 | + |
|
| 555 | + public function addKML($url) { |
|
| 556 | + array_push($this->kmlFiles, $url); |
|
| 557 | + return $this; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /* |
|
| 562 | 562 | Add a line to the map |
| 563 | 563 | |
| 564 | 564 | */ |
| 565 | - public function addLine($from = array(), $to = array(), $color = "#FF3300") { |
|
| 566 | - $line = array( |
|
| 567 | - 'lat1' => $from[0], |
|
| 568 | - 'lon1' => $from[1], |
|
| 569 | - 'lat2' => $to[0], |
|
| 570 | - 'lon2' => $to[1], |
|
| 571 | - 'color' => $color |
|
| 572 | - ); |
|
| 565 | + public function addLine($from = array(), $to = array(), $color = "#FF3300") { |
|
| 566 | + $line = array( |
|
| 567 | + 'lat1' => $from[0], |
|
| 568 | + 'lon1' => $from[1], |
|
| 569 | + 'lat2' => $to[0], |
|
| 570 | + 'lon2' => $to[1], |
|
| 571 | + 'color' => $color |
|
| 572 | + ); |
|
| 573 | 573 | |
| 574 | - array_push($this->lines, $line); |
|
| 575 | - return $this; |
|
| 576 | - } |
|
| 574 | + array_push($this->lines, $line); |
|
| 575 | + return $this; |
|
| 576 | + } |
|
| 577 | 577 | |
| 578 | 578 | |
| 579 | - /* |
|
| 579 | + /* |
|
| 580 | 580 | For php 5.3 |
| 581 | 581 | */ |
| 582 | - public static function jsonRemoveUnicodeSequences($struct) { |
|
| 583 | - return preg_replace("/\\\\u([a-f0-9]{4})/e", |
|
| 584 | - "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", |
|
| 585 | - json_encode($struct)); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Generate the gmap |
|
| 591 | - * |
|
| 592 | - * @return void |
|
| 593 | - */ |
|
| 594 | - |
|
| 595 | - public function generate() { |
|
| 596 | - // from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php |
|
| 597 | - $jsonMarkers = null; |
|
| 598 | - $linesJson = null; |
|
| 599 | - $kmlJson = null; |
|
| 600 | - |
|
| 601 | - // prior to PHP version 5.4, one needs to use regex |
|
| 602 | - if (PHP_VERSION_ID < 50400) { |
|
| 603 | - $jsonMarkers = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->markers)); |
|
| 604 | - $linesJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->lines)); |
|
| 605 | - $kmlJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->kmlFiles)); |
|
| 606 | - } else { |
|
| 607 | - $jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE)); |
|
| 608 | - $linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE)); |
|
| 609 | - $kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE)); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - // Center of the GMap - text centre takes precedence |
|
| 613 | - $geocodeCentre = ($this->latLongCenter) ? |
|
| 614 | - $this->latLongCenter : $this->geocoding($this->center); |
|
| 615 | - |
|
| 616 | - $latlngCentre = null; |
|
| 617 | - // coordinates for centre depending on which method used |
|
| 618 | - if (isset($geocodeCentre['geocoded'])) { |
|
| 619 | - $latlngCentre = array( |
|
| 620 | - 'lat' => $geocodeCentre['lat'], |
|
| 621 | - 'lng' => $geocodeCentre['lon'] |
|
| 622 | - ); |
|
| 623 | - } else if (is_array($this->latLongCenter)) { |
|
| 624 | - $latlngCentre = $this->latLongCenter; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre)); |
|
| 628 | - |
|
| 629 | - $lenLng = $this->maxLng - $this->minLng; |
|
| 630 | - $lenLat = $this->maxLat - $this->minLat; |
|
| 631 | - $this->minLng -= $lenLng * $this->coordCoef; |
|
| 632 | - $this->maxLng += $lenLng * $this->coordCoef; |
|
| 633 | - $this->minLat -= $lenLat * $this->coordCoef; |
|
| 634 | - $this->maxLat += $lenLat * $this->coordCoef; |
|
| 635 | - |
|
| 636 | - // add the css class mappable as a handle onto the map styling |
|
| 637 | - $this->additional_css_classes .= ' mappable'; |
|
| 638 | - |
|
| 639 | - if (!$this->enableAutomaticCenterZoom) { |
|
| 640 | - $this->enableAutomaticCenterZoom = 'false'; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if (!$this->useClusterer) { |
|
| 644 | - $this->useClusterer = 'false'; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - if (!$this->defaultHideMarker) { |
|
| 648 | - $this->defaultHideMarker = 'false'; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // initialise full screen as the config value if not already set |
|
| 652 | - if ($this->allowFullScreen === null) { |
|
| 653 | - $this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - if (!$this->allowFullScreen) { |
|
| 657 | - $this->allowFullScreen = 'false'; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - if (!$this->enableWindowZoom) { |
|
| 661 | - $this->enableWindowZoom = 'false'; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - $vars = new ArrayData(array( |
|
| 665 | - |
|
| 666 | - 'JsonMapStyles' => $this->jsonMapStyles, |
|
| 667 | - 'AdditionalCssClasses' => $this->additional_css_classes, |
|
| 668 | - 'Width' => $this->width, |
|
| 669 | - 'Height' => $this->height, |
|
| 670 | - 'ShowInlineMapDivStyle' => $this->show_inline_map_div_style, |
|
| 671 | - 'InfoWindowZoom' => $this->infoWindowZoom, |
|
| 672 | - 'EnableWindowZoom' => $this->enableWindowZoom, |
|
| 673 | - 'MapMarkers' => $jsonMarkers, |
|
| 674 | - 'DefaultHideMarker' => $this->defaultHideMarker, |
|
| 675 | - 'LatLngCentre' => $this->LatLngCentreJSON, |
|
| 676 | - 'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom, |
|
| 677 | - 'Zoom' => $this->zoom, |
|
| 678 | - 'MaxZoom' => $this->maxZoom, |
|
| 679 | - 'GridSize' => $this->gridSize, |
|
| 680 | - 'MapType' => $this->mapType, |
|
| 681 | - 'GoogleMapID' => $this->googleMapId, |
|
| 682 | - 'Lang'=>$this->lang, |
|
| 683 | - 'UseClusterer'=>$this->useClusterer, |
|
| 684 | - 'ClustererLibraryPath' => $this->clustererLibraryPath, |
|
| 685 | - 'ClustererMaxZoom' => $this->maxZoom, |
|
| 686 | - 'ClustererGridSize' => $this->gridSize, |
|
| 687 | - 'Lines' => $linesJson, |
|
| 688 | - 'KmlFiles' => $kmlJson, |
|
| 689 | - 'AllowFullScreen' => $this->allowFullScreen, |
|
| 690 | - 'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets') |
|
| 691 | - ) |
|
| 692 | - ); |
|
| 693 | - |
|
| 694 | - if (!MapUtil::get_map_already_rendered()) { |
|
| 695 | - $vars->setField('GoogleMapKey', $this->googleMapKey); |
|
| 696 | - $vars->setField('GoogleMapLang', $this->lang); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - // HTML component of the map |
|
| 700 | - $this->content = $this->processTemplateHTML('Map', $vars); |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * @param string $templateName |
|
| 705 | - * @param ArrayData $templateVariables |
|
| 706 | - */ |
|
| 707 | - public function processTemplateHTML($templateName, $templateVariables = null) { |
|
| 708 | - if (!$templateVariables) { |
|
| 709 | - $templateVariables = new ArrayList(); |
|
| 710 | - } |
|
| 711 | - $mappingService = Config::inst()->get('Mappable', 'mapping_service'); |
|
| 712 | - $result = $templateVariables->renderWith($templateName.$mappingService.'HTML'); |
|
| 713 | - return $result; |
|
| 714 | - } |
|
| 582 | + public static function jsonRemoveUnicodeSequences($struct) { |
|
| 583 | + return preg_replace("/\\\\u([a-f0-9]{4})/e", |
|
| 584 | + "iconv('UCS-4LE','UTF-8',pack('V', hexdec('U$1')))", |
|
| 585 | + json_encode($struct)); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Generate the gmap |
|
| 591 | + * |
|
| 592 | + * @return void |
|
| 593 | + */ |
|
| 594 | + |
|
| 595 | + public function generate() { |
|
| 596 | + // from http://stackoverflow.com/questions/3586401/cant-decode-json-string-in-php |
|
| 597 | + $jsonMarkers = null; |
|
| 598 | + $linesJson = null; |
|
| 599 | + $kmlJson = null; |
|
| 600 | + |
|
| 601 | + // prior to PHP version 5.4, one needs to use regex |
|
| 602 | + if (PHP_VERSION_ID < 50400) { |
|
| 603 | + $jsonMarkers = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->markers)); |
|
| 604 | + $linesJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->lines)); |
|
| 605 | + $kmlJson = stripslashes(MapAPI::jsonRemoveUnicodeSequences($this->kmlFiles)); |
|
| 606 | + } else { |
|
| 607 | + $jsonMarkers = stripslashes(json_encode($this->markers, JSON_UNESCAPED_UNICODE)); |
|
| 608 | + $linesJson = stripslashes(json_encode($this->lines, JSON_UNESCAPED_UNICODE)); |
|
| 609 | + $kmlJson = stripslashes(json_encode($this->kmlFiles, JSON_UNESCAPED_UNICODE)); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + // Center of the GMap - text centre takes precedence |
|
| 613 | + $geocodeCentre = ($this->latLongCenter) ? |
|
| 614 | + $this->latLongCenter : $this->geocoding($this->center); |
|
| 615 | + |
|
| 616 | + $latlngCentre = null; |
|
| 617 | + // coordinates for centre depending on which method used |
|
| 618 | + if (isset($geocodeCentre['geocoded'])) { |
|
| 619 | + $latlngCentre = array( |
|
| 620 | + 'lat' => $geocodeCentre['lat'], |
|
| 621 | + 'lng' => $geocodeCentre['lon'] |
|
| 622 | + ); |
|
| 623 | + } else if (is_array($this->latLongCenter)) { |
|
| 624 | + $latlngCentre = $this->latLongCenter; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $this->LatLngCentreJSON = stripslashes(json_encode($latlngCentre)); |
|
| 628 | + |
|
| 629 | + $lenLng = $this->maxLng - $this->minLng; |
|
| 630 | + $lenLat = $this->maxLat - $this->minLat; |
|
| 631 | + $this->minLng -= $lenLng * $this->coordCoef; |
|
| 632 | + $this->maxLng += $lenLng * $this->coordCoef; |
|
| 633 | + $this->minLat -= $lenLat * $this->coordCoef; |
|
| 634 | + $this->maxLat += $lenLat * $this->coordCoef; |
|
| 635 | + |
|
| 636 | + // add the css class mappable as a handle onto the map styling |
|
| 637 | + $this->additional_css_classes .= ' mappable'; |
|
| 638 | + |
|
| 639 | + if (!$this->enableAutomaticCenterZoom) { |
|
| 640 | + $this->enableAutomaticCenterZoom = 'false'; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if (!$this->useClusterer) { |
|
| 644 | + $this->useClusterer = 'false'; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + if (!$this->defaultHideMarker) { |
|
| 648 | + $this->defaultHideMarker = 'false'; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // initialise full screen as the config value if not already set |
|
| 652 | + if ($this->allowFullScreen === null) { |
|
| 653 | + $this->allowFullScreen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + if (!$this->allowFullScreen) { |
|
| 657 | + $this->allowFullScreen = 'false'; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + if (!$this->enableWindowZoom) { |
|
| 661 | + $this->enableWindowZoom = 'false'; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + $vars = new ArrayData(array( |
|
| 665 | + |
|
| 666 | + 'JsonMapStyles' => $this->jsonMapStyles, |
|
| 667 | + 'AdditionalCssClasses' => $this->additional_css_classes, |
|
| 668 | + 'Width' => $this->width, |
|
| 669 | + 'Height' => $this->height, |
|
| 670 | + 'ShowInlineMapDivStyle' => $this->show_inline_map_div_style, |
|
| 671 | + 'InfoWindowZoom' => $this->infoWindowZoom, |
|
| 672 | + 'EnableWindowZoom' => $this->enableWindowZoom, |
|
| 673 | + 'MapMarkers' => $jsonMarkers, |
|
| 674 | + 'DefaultHideMarker' => $this->defaultHideMarker, |
|
| 675 | + 'LatLngCentre' => $this->LatLngCentreJSON, |
|
| 676 | + 'EnableAutomaticCenterZoom' => $this->enableAutomaticCenterZoom, |
|
| 677 | + 'Zoom' => $this->zoom, |
|
| 678 | + 'MaxZoom' => $this->maxZoom, |
|
| 679 | + 'GridSize' => $this->gridSize, |
|
| 680 | + 'MapType' => $this->mapType, |
|
| 681 | + 'GoogleMapID' => $this->googleMapId, |
|
| 682 | + 'Lang'=>$this->lang, |
|
| 683 | + 'UseClusterer'=>$this->useClusterer, |
|
| 684 | + 'ClustererLibraryPath' => $this->clustererLibraryPath, |
|
| 685 | + 'ClustererMaxZoom' => $this->maxZoom, |
|
| 686 | + 'ClustererGridSize' => $this->gridSize, |
|
| 687 | + 'Lines' => $linesJson, |
|
| 688 | + 'KmlFiles' => $kmlJson, |
|
| 689 | + 'AllowFullScreen' => $this->allowFullScreen, |
|
| 690 | + 'UseCompressedAssets' => Config::inst()->get('Mappable', 'use_compressed_assets') |
|
| 691 | + ) |
|
| 692 | + ); |
|
| 693 | + |
|
| 694 | + if (!MapUtil::get_map_already_rendered()) { |
|
| 695 | + $vars->setField('GoogleMapKey', $this->googleMapKey); |
|
| 696 | + $vars->setField('GoogleMapLang', $this->lang); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + // HTML component of the map |
|
| 700 | + $this->content = $this->processTemplateHTML('Map', $vars); |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * @param string $templateName |
|
| 705 | + * @param ArrayData $templateVariables |
|
| 706 | + */ |
|
| 707 | + public function processTemplateHTML($templateName, $templateVariables = null) { |
|
| 708 | + if (!$templateVariables) { |
|
| 709 | + $templateVariables = new ArrayList(); |
|
| 710 | + } |
|
| 711 | + $mappingService = Config::inst()->get('Mappable', 'mapping_service'); |
|
| 712 | + $result = $templateVariables->renderWith($templateName.$mappingService.'HTML'); |
|
| 713 | + return $result; |
|
| 714 | + } |
|
| 715 | 715 | } |
@@ -2,31 +2,31 @@ |
||
| 2 | 2 | |
| 3 | 3 | class MapMarkerSetsExtension extends DataExtension { |
| 4 | 4 | |
| 5 | - static $many_many = array( |
|
| 6 | - 'MapMarkerSets' => 'MapMarkerSet' |
|
| 7 | - ); |
|
| 8 | - |
|
| 9 | - |
|
| 10 | - static $belongs_many_many_extraFields = array( |
|
| 11 | - 'MapMarkerSets' => array( |
|
| 12 | - 'SortOrder' => "Int" |
|
| 13 | - ) |
|
| 14 | - ); |
|
| 15 | - |
|
| 16 | - |
|
| 17 | - public function updateCMSFields(FieldList $fields) { |
|
| 18 | - $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
| 19 | - $gridConfig2->getComponentByType( |
|
| 20 | - 'GridFieldAddExistingAutocompleter')->setSearchFields(array('Title') |
|
| 21 | - ); |
|
| 22 | - $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
| 23 | - |
|
| 24 | - $gridField2 = new GridField("MapMarkerSets", |
|
| 25 | - "MapMarker Sets", |
|
| 26 | - $this->owner->MapMarkerSets(), |
|
| 27 | - $gridConfig2 |
|
| 28 | - ); |
|
| 29 | - $fields->addFieldToTab("Root.MapMarkerSets", $gridField2); |
|
| 30 | - } |
|
| 5 | + static $many_many = array( |
|
| 6 | + 'MapMarkerSets' => 'MapMarkerSet' |
|
| 7 | + ); |
|
| 8 | + |
|
| 9 | + |
|
| 10 | + static $belongs_many_many_extraFields = array( |
|
| 11 | + 'MapMarkerSets' => array( |
|
| 12 | + 'SortOrder' => "Int" |
|
| 13 | + ) |
|
| 14 | + ); |
|
| 15 | + |
|
| 16 | + |
|
| 17 | + public function updateCMSFields(FieldList $fields) { |
|
| 18 | + $gridConfig2 = GridFieldConfig_RelationEditor::create(); |
|
| 19 | + $gridConfig2->getComponentByType( |
|
| 20 | + 'GridFieldAddExistingAutocompleter')->setSearchFields(array('Title') |
|
| 21 | + ); |
|
| 22 | + $gridConfig2->getComponentByType('GridFieldPaginator')->setItemsPerPage(100); |
|
| 23 | + |
|
| 24 | + $gridField2 = new GridField("MapMarkerSets", |
|
| 25 | + "MapMarker Sets", |
|
| 26 | + $this->owner->MapMarkerSets(), |
|
| 27 | + $gridConfig2 |
|
| 28 | + ); |
|
| 29 | + $fields->addFieldToTab("Root.MapMarkerSets", $gridField2); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | } |
@@ -4,52 +4,52 @@ |
||
| 4 | 4 | */ |
| 5 | 5 | class MapField extends DatalessField { |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2 |
|
| 9 | - */ |
|
| 10 | - protected $headingLevel = 2; |
|
| 11 | - private $divId; |
|
| 7 | + /** |
|
| 8 | + * @var int $headingLevel The level of the <h1> to <h6> HTML tag. Default: 2 |
|
| 9 | + */ |
|
| 10 | + protected $headingLevel = 2; |
|
| 11 | + private $divId; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param string $name |
|
| 15 | - * @param string $title |
|
| 16 | - */ |
|
| 17 | - function __construct($name, $title = null, $headingLevel = 2, $allowHTML = false, $form = null) { |
|
| 18 | - $this->divId = $name; |
|
| 19 | - // legacy handling for old parameters: $title, $heading, ... |
|
| 20 | - // instead of new handling: $name, $title, $heading, ... |
|
| 21 | - $args = func_get_args(); |
|
| 22 | - if(!isset($args[1]) || is_numeric($args[1])) { |
|
| 23 | - $title = (isset($args[0])) ? $args[0] : null; |
|
| 24 | - // Use "HeaderField(title)" as the default field name for a HeaderField; |
|
| 25 | - // if it's just set to title then we risk causing accidental duplicate-field creation. |
|
| 13 | + /** |
|
| 14 | + * @param string $name |
|
| 15 | + * @param string $title |
|
| 16 | + */ |
|
| 17 | + function __construct($name, $title = null, $headingLevel = 2, $allowHTML = false, $form = null) { |
|
| 18 | + $this->divId = $name; |
|
| 19 | + // legacy handling for old parameters: $title, $heading, ... |
|
| 20 | + // instead of new handling: $name, $title, $heading, ... |
|
| 21 | + $args = func_get_args(); |
|
| 22 | + if(!isset($args[1]) || is_numeric($args[1])) { |
|
| 23 | + $title = (isset($args[0])) ? $args[0] : null; |
|
| 24 | + // Use "HeaderField(title)" as the default field name for a HeaderField; |
|
| 25 | + // if it's just set to title then we risk causing accidental duplicate-field creation. |
|
| 26 | 26 | |
| 27 | - // this means i18nized fields won't be easily accessible through fieldByName() |
|
| 28 | - $name = 'MapField' . $title; |
|
| 29 | - $headingLevel = (isset($args[1])) ? $args[1] : null; |
|
| 30 | - $allowHTML = (isset($args[2])) ? $args[2] : null; |
|
| 31 | - $form = (isset($args[3])) ? $args[3] : null; |
|
| 32 | - } |
|
| 27 | + // this means i18nized fields won't be easily accessible through fieldByName() |
|
| 28 | + $name = 'MapField' . $title; |
|
| 29 | + $headingLevel = (isset($args[1])) ? $args[1] : null; |
|
| 30 | + $allowHTML = (isset($args[2])) ? $args[2] : null; |
|
| 31 | + $form = (isset($args[3])) ? $args[3] : null; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if($headingLevel) $this->headingLevel = $headingLevel; |
|
| 35 | - $this->allowHTML = $allowHTML; |
|
| 36 | - parent::__construct($name, $title, null, $allowHTML, $form); |
|
| 37 | - } |
|
| 34 | + if($headingLevel) $this->headingLevel = $headingLevel; |
|
| 35 | + $this->allowHTML = $allowHTML; |
|
| 36 | + parent::__construct($name, $title, null, $allowHTML, $form); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - function Field($properties = array()) { |
|
| 40 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 41 | - Requirements::javascript('framework/thirdparty/jquery-livequery/jquery.livequery.js'); |
|
| 42 | - $attributes = array( |
|
| 43 | - 'class' => 'middleColumn', |
|
| 44 | - 'id' => $this->divId, |
|
| 45 | - 'style' => "width:100%;height:300px;margin:5px 0px 5px 5px;position:relative;" |
|
| 46 | - ); |
|
| 39 | + function Field($properties = array()) { |
|
| 40 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 41 | + Requirements::javascript('framework/thirdparty/jquery-livequery/jquery.livequery.js'); |
|
| 42 | + $attributes = array( |
|
| 43 | + 'class' => 'middleColumn', |
|
| 44 | + 'id' => $this->divId, |
|
| 45 | + 'style' => "width:100%;height:300px;margin:5px 0px 5px 5px;position:relative;" |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - Requirements::css('mappable/css/mapField.css'); |
|
| 48 | + Requirements::css('mappable/css/mapField.css'); |
|
| 49 | 49 | |
| 50 | - return '<div class="editableMap">' . $this->createTag( |
|
| 51 | - "div", |
|
| 52 | - $attributes |
|
| 53 | - ) . '</div>'; |
|
| 54 | - } |
|
| 50 | + return '<div class="editableMap">' . $this->createTag( |
|
| 51 | + "div", |
|
| 52 | + $attributes |
|
| 53 | + ) . '</div>'; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -3,221 +3,221 @@ |
||
| 3 | 3 | class MapUtil |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - /** |
|
| 7 | - * @var string The Google Maps API key |
|
| 8 | - */ |
|
| 9 | - protected static $api_key; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * @var int Number of active {@see GoogleMapsAPI} instances (for the HTML ID) |
|
| 13 | - */ |
|
| 14 | - protected static $instances = 0; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @var int The default width of a Google Map |
|
| 18 | - */ |
|
| 19 | - public static $map_width = '100%'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var int The default height of a Google Map |
|
| 23 | - */ |
|
| 24 | - public static $map_height = '400px'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var int Prefix for the div ID of the map |
|
| 28 | - */ |
|
| 29 | - public static $div_id = "google_map"; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var boolean Automatic center/zoom for the map |
|
| 33 | - */ |
|
| 34 | - public static $automatic_center = true; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var boolean Show the marker fields on the map |
|
| 38 | - */ |
|
| 39 | - public static $hide_marker = false; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var boolean Show the marker fields on the map |
|
| 43 | - */ |
|
| 44 | - public static $map_type = 'google.maps.MapTypeId.ROADMAP'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $center Center of map (adress) |
|
| 48 | - */ |
|
| 49 | - public static $center = 'Paris, France'; |
|
| 50 | - |
|
| 51 | - /* Signals whether at least one map has already been rendered */ |
|
| 52 | - private static $map_already_rendered = false; |
|
| 53 | - |
|
| 54 | - /* Whether or not to allow full screen */ |
|
| 55 | - private static $allow_full_screen = null; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - public static function reset() { |
|
| 59 | - self::$api_key = null; |
|
| 60 | - self::$instances = 0; |
|
| 61 | - self::$map_width = '100%'; |
|
| 62 | - self::$map_height = '400px'; |
|
| 63 | - self::$div_id = "google_map"; |
|
| 64 | - self::$automatic_center = true; |
|
| 65 | - self::$hide_marker = false; |
|
| 66 | - self::$map_type = 'google.maps.MapTypeId.ROADMAP'; |
|
| 67 | - self::$center = 'Paris, France'; |
|
| 68 | - self::$map_already_rendered = false; |
|
| 69 | - self::$allow_full_screen = null; |
|
| 70 | - Config::inst()->update('Mappable', 'language', 'en'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Set the API key for Google Maps |
|
| 75 | - * |
|
| 76 | - * @param string $key |
|
| 77 | - */ |
|
| 78 | - public static function set_api_key($key) { |
|
| 79 | - self::$api_key = $key; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param boolean $new_map_already_rendered |
|
| 84 | - */ |
|
| 85 | - public static function set_map_already_rendered($new_map_already_rendered) { |
|
| 86 | - self::$map_already_rendered = $new_map_already_rendered; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - public static function get_map_already_rendered() { |
|
| 90 | - return self::$map_already_rendered; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Set the default size of the map |
|
| 95 | - * |
|
| 96 | - * @param int $width |
|
| 97 | - * @param int $height |
|
| 98 | - */ |
|
| 99 | - public static function set_map_size($width, $height) { |
|
| 100 | - self:: $map_width = $width; |
|
| 101 | - self::$map_height = $height; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * FIXME - NOT USED? |
|
| 106 | - * Set the type of the gmap |
|
| 107 | - * |
|
| 108 | - * @param string $mapType (can be 'google.maps.MapTypeId.ROADMAP', 'G_SATELLITE_MAP', |
|
| 109 | - * 'G_HYBRID_MAP', 'G_PHYSICAL_MAP') |
|
| 110 | - * |
|
| 111 | - * @return void |
|
| 112 | - */ |
|
| 113 | - public static function set_map_type($mapType) { |
|
| 114 | - self::$map_type = $mapType; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Set the center of the gmap (an address, using text geocoder query) |
|
| 119 | - * |
|
| 120 | - * @param string $center GoogleMap center (an address) |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public static function set_center($center) |
|
| 125 | - { |
|
| 126 | - self::$center = $center; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Get a new GoogleMapAPI object and load it with the default settings |
|
| 131 | - * |
|
| 132 | - * @return MapAPI |
|
| 133 | - */ |
|
| 134 | - public static function instance() |
|
| 135 | - { |
|
| 136 | - self::$instances++; |
|
| 137 | - |
|
| 138 | - if (self::$allow_full_screen == null) { |
|
| 139 | - self::$allow_full_screen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $url = Director::absoluteBaseURL(); |
|
| 143 | - |
|
| 144 | - // remove http and https |
|
| 145 | - $url = str_replace('http://', '', $url); |
|
| 146 | - $url = str_replace('https://', '', $url); |
|
| 147 | - $parts = explode('/', $url); |
|
| 148 | - $host = $parts[0]; |
|
| 149 | - |
|
| 150 | - $key = self::$api_key; |
|
| 151 | - |
|
| 152 | - // if an array, get the key by an array keyed by host |
|
| 153 | - if (is_array($key)) { |
|
| 154 | - $key = $key[$host]; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $gmap = new MapAPI($key); |
|
| 158 | - $gmap->setDivId(self::$div_id."_".self::$instances); |
|
| 159 | - $gmap->setEnableAutomaticCenterZoom(self::$automatic_center); |
|
| 160 | - $gmap->setSize(self::$map_width, self::$map_height); |
|
| 161 | - $gmap->setDefaultHideMarker(self::$hide_marker); |
|
| 162 | - $gmap->setMapType(self::$map_type); |
|
| 163 | - $gmap->setCenter(self::$center); |
|
| 164 | - $gmap->setAllowFullScreen(self::$allow_full_screen); |
|
| 165 | - $language = Config::inst()->get('Mappable', 'language'); |
|
| 166 | - $gmap->setLang($language); |
|
| 167 | - return $gmap; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Sanitize a string of HTML content for safe inclusion in the JavaScript |
|
| 173 | - * for a Google Map |
|
| 174 | - * |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public static function sanitize($content) { |
|
| 178 | - return addslashes(str_replace(array("\n", "\r", "\t"), '', $content)); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Creates a new {@link GoogleMapsAPI} object loaded with the default settings |
|
| 184 | - * and places all of the items in a {@link SS_List} |
|
| 185 | - * e.g. {@link DataList} or {@link ArrayList} on the map |
|
| 186 | - * |
|
| 187 | - * @param SS_List list of objects to display on a map |
|
| 188 | - * @param array $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
| 189 | - * @return MapAPI |
|
| 190 | - */ |
|
| 191 | - public static function get_map(SS_List $list, $infowindowtemplateparams) { |
|
| 192 | - $gmap = self::instance(); |
|
| 193 | - if ($list) { |
|
| 194 | - foreach ($list as $mappable) { |
|
| 195 | - if (self::ChooseToAddDataobject($mappable)) |
|
| 196 | - $gmap->addMarkerAsObject($mappable, $infowindowtemplateparams); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - return $gmap; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Determines if the current DataObject should be included to the map |
|
| 204 | - * Checks if it has Mappable interface implemented |
|
| 205 | - * If it has MapExtension included, the value of MapPinEdited is also checked |
|
| 206 | - * |
|
| 207 | - * @param DataObject $do |
|
| 208 | - * @return bool |
|
| 209 | - */ |
|
| 210 | - private static function ChooseToAddDataobject(DataObject $do) { |
|
| 211 | - $isMappable = $do->is_a('Mappable'); |
|
| 212 | - |
|
| 213 | - foreach ($do->getExtensionInstances() as $extension) { |
|
| 214 | - $isMappable = $isMappable || $extension instanceof Mappable; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $filterMapPinEdited = $do->hasExtension('MapExtension') |
|
| 218 | - ? $do->MapPinEdited |
|
| 219 | - : true; |
|
| 220 | - |
|
| 221 | - return $isMappable && $filterMapPinEdited; |
|
| 222 | - } |
|
| 6 | + /** |
|
| 7 | + * @var string The Google Maps API key |
|
| 8 | + */ |
|
| 9 | + protected static $api_key; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @var int Number of active {@see GoogleMapsAPI} instances (for the HTML ID) |
|
| 13 | + */ |
|
| 14 | + protected static $instances = 0; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @var int The default width of a Google Map |
|
| 18 | + */ |
|
| 19 | + public static $map_width = '100%'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var int The default height of a Google Map |
|
| 23 | + */ |
|
| 24 | + public static $map_height = '400px'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var int Prefix for the div ID of the map |
|
| 28 | + */ |
|
| 29 | + public static $div_id = "google_map"; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var boolean Automatic center/zoom for the map |
|
| 33 | + */ |
|
| 34 | + public static $automatic_center = true; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var boolean Show the marker fields on the map |
|
| 38 | + */ |
|
| 39 | + public static $hide_marker = false; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var boolean Show the marker fields on the map |
|
| 43 | + */ |
|
| 44 | + public static $map_type = 'google.maps.MapTypeId.ROADMAP'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $center Center of map (adress) |
|
| 48 | + */ |
|
| 49 | + public static $center = 'Paris, France'; |
|
| 50 | + |
|
| 51 | + /* Signals whether at least one map has already been rendered */ |
|
| 52 | + private static $map_already_rendered = false; |
|
| 53 | + |
|
| 54 | + /* Whether or not to allow full screen */ |
|
| 55 | + private static $allow_full_screen = null; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + public static function reset() { |
|
| 59 | + self::$api_key = null; |
|
| 60 | + self::$instances = 0; |
|
| 61 | + self::$map_width = '100%'; |
|
| 62 | + self::$map_height = '400px'; |
|
| 63 | + self::$div_id = "google_map"; |
|
| 64 | + self::$automatic_center = true; |
|
| 65 | + self::$hide_marker = false; |
|
| 66 | + self::$map_type = 'google.maps.MapTypeId.ROADMAP'; |
|
| 67 | + self::$center = 'Paris, France'; |
|
| 68 | + self::$map_already_rendered = false; |
|
| 69 | + self::$allow_full_screen = null; |
|
| 70 | + Config::inst()->update('Mappable', 'language', 'en'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Set the API key for Google Maps |
|
| 75 | + * |
|
| 76 | + * @param string $key |
|
| 77 | + */ |
|
| 78 | + public static function set_api_key($key) { |
|
| 79 | + self::$api_key = $key; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param boolean $new_map_already_rendered |
|
| 84 | + */ |
|
| 85 | + public static function set_map_already_rendered($new_map_already_rendered) { |
|
| 86 | + self::$map_already_rendered = $new_map_already_rendered; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + public static function get_map_already_rendered() { |
|
| 90 | + return self::$map_already_rendered; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Set the default size of the map |
|
| 95 | + * |
|
| 96 | + * @param int $width |
|
| 97 | + * @param int $height |
|
| 98 | + */ |
|
| 99 | + public static function set_map_size($width, $height) { |
|
| 100 | + self:: $map_width = $width; |
|
| 101 | + self::$map_height = $height; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * FIXME - NOT USED? |
|
| 106 | + * Set the type of the gmap |
|
| 107 | + * |
|
| 108 | + * @param string $mapType (can be 'google.maps.MapTypeId.ROADMAP', 'G_SATELLITE_MAP', |
|
| 109 | + * 'G_HYBRID_MAP', 'G_PHYSICAL_MAP') |
|
| 110 | + * |
|
| 111 | + * @return void |
|
| 112 | + */ |
|
| 113 | + public static function set_map_type($mapType) { |
|
| 114 | + self::$map_type = $mapType; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Set the center of the gmap (an address, using text geocoder query) |
|
| 119 | + * |
|
| 120 | + * @param string $center GoogleMap center (an address) |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public static function set_center($center) |
|
| 125 | + { |
|
| 126 | + self::$center = $center; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Get a new GoogleMapAPI object and load it with the default settings |
|
| 131 | + * |
|
| 132 | + * @return MapAPI |
|
| 133 | + */ |
|
| 134 | + public static function instance() |
|
| 135 | + { |
|
| 136 | + self::$instances++; |
|
| 137 | + |
|
| 138 | + if (self::$allow_full_screen == null) { |
|
| 139 | + self::$allow_full_screen = Config::inst()->get('Mappable', 'allow_full_screen'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $url = Director::absoluteBaseURL(); |
|
| 143 | + |
|
| 144 | + // remove http and https |
|
| 145 | + $url = str_replace('http://', '', $url); |
|
| 146 | + $url = str_replace('https://', '', $url); |
|
| 147 | + $parts = explode('/', $url); |
|
| 148 | + $host = $parts[0]; |
|
| 149 | + |
|
| 150 | + $key = self::$api_key; |
|
| 151 | + |
|
| 152 | + // if an array, get the key by an array keyed by host |
|
| 153 | + if (is_array($key)) { |
|
| 154 | + $key = $key[$host]; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $gmap = new MapAPI($key); |
|
| 158 | + $gmap->setDivId(self::$div_id."_".self::$instances); |
|
| 159 | + $gmap->setEnableAutomaticCenterZoom(self::$automatic_center); |
|
| 160 | + $gmap->setSize(self::$map_width, self::$map_height); |
|
| 161 | + $gmap->setDefaultHideMarker(self::$hide_marker); |
|
| 162 | + $gmap->setMapType(self::$map_type); |
|
| 163 | + $gmap->setCenter(self::$center); |
|
| 164 | + $gmap->setAllowFullScreen(self::$allow_full_screen); |
|
| 165 | + $language = Config::inst()->get('Mappable', 'language'); |
|
| 166 | + $gmap->setLang($language); |
|
| 167 | + return $gmap; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Sanitize a string of HTML content for safe inclusion in the JavaScript |
|
| 173 | + * for a Google Map |
|
| 174 | + * |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public static function sanitize($content) { |
|
| 178 | + return addslashes(str_replace(array("\n", "\r", "\t"), '', $content)); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Creates a new {@link GoogleMapsAPI} object loaded with the default settings |
|
| 184 | + * and places all of the items in a {@link SS_List} |
|
| 185 | + * e.g. {@link DataList} or {@link ArrayList} on the map |
|
| 186 | + * |
|
| 187 | + * @param SS_List list of objects to display on a map |
|
| 188 | + * @param array $infowindowtemplateparams Optional array of extra parameters to pass to the map info window |
|
| 189 | + * @return MapAPI |
|
| 190 | + */ |
|
| 191 | + public static function get_map(SS_List $list, $infowindowtemplateparams) { |
|
| 192 | + $gmap = self::instance(); |
|
| 193 | + if ($list) { |
|
| 194 | + foreach ($list as $mappable) { |
|
| 195 | + if (self::ChooseToAddDataobject($mappable)) |
|
| 196 | + $gmap->addMarkerAsObject($mappable, $infowindowtemplateparams); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + return $gmap; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Determines if the current DataObject should be included to the map |
|
| 204 | + * Checks if it has Mappable interface implemented |
|
| 205 | + * If it has MapExtension included, the value of MapPinEdited is also checked |
|
| 206 | + * |
|
| 207 | + * @param DataObject $do |
|
| 208 | + * @return bool |
|
| 209 | + */ |
|
| 210 | + private static function ChooseToAddDataobject(DataObject $do) { |
|
| 211 | + $isMappable = $do->is_a('Mappable'); |
|
| 212 | + |
|
| 213 | + foreach ($do->getExtensionInstances() as $extension) { |
|
| 214 | + $isMappable = $isMappable || $extension instanceof Mappable; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $filterMapPinEdited = $do->hasExtension('MapExtension') |
|
| 218 | + ? $do->MapPinEdited |
|
| 219 | + : true; |
|
| 220 | + |
|
| 221 | + return $isMappable && $filterMapPinEdited; |
|
| 222 | + } |
|
| 223 | 223 | } |