diff --git a/code/extension/GoogleMapController.php b/code/extension/GoogleMapController.php index f89fe29..b6f553d 100644 --- a/code/extension/GoogleMapController.php +++ b/code/extension/GoogleMapController.php @@ -33,19 +33,49 @@ public function onAfterInit() && !$this->owner->StaticMap ) { foreach ($this->owner->Maps() as $map) { + + // draw map $vars = array( 'MapID' => "google-map-dynamic-{$map->ID}", - 'Content' => $map->Content, - 'Address' => ($map->Address) ? str_replace('/n', ',', $map->Address) . ',' . $map->PostCode : 'false', 'Latitude' => ($map->Latitude) ? $map->Latitude : 'false', 'Longitude' => ($map->Longitude) ? $map->Longitude : 'false', 'Zoom' => $map->ZoomLevel ); - Requirements::javascriptTemplate( 'googlemaps/javascript/GoogleMap.js', $vars ); + + // draw markers + if ($map->Address) { + $vars = array( + 'MapID' => "google-map-dynamic-{$map->ID}", + 'Content' => $map->Content, + 'Address' => ($map->Address) ? str_replace(array('\r\n', '\n'), ', ', $map->Address) : 'false', + 'Latitude' => ($map->Latitude) ? $map->Latitude : 'false', + 'Longitude' => ($map->Longitude) ? $map->Longitude : 'false', + 'Zoom' => $map->Zoom + ); + Requirements::javascriptTemplate( + 'googlemaps/javascript/GoogleMapMarker.js', + $vars + ); + } + + // draw circle + if ($map->CircleRadius) { + $vars = array( + 'MapID' => "google-map-dynamic-{$map->ID}", + 'Radius' => $map->CircleRadius, + 'Color' => ($map->CircleColor) ? $map->CircleColor : '#FF0000', + 'Latitude' => ($map->Latitude) ? $map->Latitude : 'false', + 'Longitude' => ($map->Longitude) ? $map->Longitude : 'false' + ); + Requirements::javascriptTemplate( + 'googlemaps/javascript/GoogleMapCircle.js', + $vars + ); + } } } } diff --git a/code/model/GoogleMap.php b/code/model/GoogleMap.php index 4dd2529..0e61e93 100644 --- a/code/model/GoogleMap.php +++ b/code/model/GoogleMap.php @@ -16,13 +16,19 @@ class GoogleMap extends DataObject 'Latitude' => 'Varchar', 'Longitude' => 'Varchar', 'Zoom' => 'Int', - 'Sort' => 'Int' + 'Sort' => 'Int', + 'CircleRadius' => 'Int', + 'CircleColor' => 'Varchar', ); private static $has_one = array( 'Parent' => 'SiteTree' ); + private static $defaults = array( + 'CircleColor' => '#FF0000', + ); + private static $casting = array( 'FullAddress' => 'HTMLText', 'Location' => 'Text', @@ -59,6 +65,8 @@ public function getCMSFields() "Title" ); + $fields->replaceField('CircleRadius', TextField::create('CircleRadius', _t("GoogleMaps.CircleRadiusInMeter", "Circle Radius in meter (0 if no circle should be drawn)"))); + $fields->replaceField('CircleColor', TextField::create('CircleColor', _t("GoogleMaps.CircleColor", "Circle Color, i.e. #FF0000 (red will be used if empty)"))); $fields->addFieldsToTab( "Root.Map", diff --git a/javascript/GoogleMap.js b/javascript/GoogleMap.js index f813365..e939f27 100644 --- a/javascript/GoogleMap.js +++ b/javascript/GoogleMap.js @@ -6,18 +6,6 @@ jQuery(document).ready(function() { center: [$Latitude,$Longitude], zoom: $Zoom } - }, - marker: { - address: "$Address", - latLng: [$Latitude,$Longitude], - clickable: true - }, - infowindow:{ - margin: this.marker, - latLng: [$Latitude,$Longitude], - options:{ - content: '$Content' - } } }); }); diff --git a/javascript/GoogleMapCircle.js b/javascript/GoogleMapCircle.js new file mode 100644 index 0000000..b9c03a6 --- /dev/null +++ b/javascript/GoogleMapCircle.js @@ -0,0 +1,19 @@ +(function($) { + $(document).ready(function() { + + $('.$MapID').gmap3({ + circle:{ + options:{ + center: [$Latitude,$Longitude], + radius : $Radius, + fillColor : "$Color", + fillOpacity: 0.3, + strokeColor : "$Color", + strokeOpacity: 0.7, + strokeWeight: 1 + } + } + }); + + }); +}(jQuery)); \ No newline at end of file diff --git a/javascript/GoogleMapMarker.js b/javascript/GoogleMapMarker.js new file mode 100644 index 0000000..22a05a5 --- /dev/null +++ b/javascript/GoogleMapMarker.js @@ -0,0 +1,39 @@ +(function($) { + $(document).ready(function() { + + $('.$MapID').gmap3({ + marker: { + latLng: [$Latitude,$Longitude], + options: { + clickable: true, + visible: true + }, + events: { + click: function(marker, event, context){ + var map = $(this).gmap3("get"), + infowindow = $(this).gmap3({get:{name:"infowindow"}}); + if (infowindow){ + infowindow.open(map, marker); + } else { + $(this).gmap3({ + infowindow:{ + anchor:marker, + options:{content: '$Content'} + } + }); + } + + } + } + }, + infowindow: { + anchor: $(this).gmap3({get:{name:"marker"}}), + open: true, + options:{ + content: '$Content' + } + } + }); + + }); +}(jQuery)); \ No newline at end of file diff --git a/templates/Includes/GoogleMaps.ss b/templates/Includes/GoogleMaps.ss index b4bdaaa..9238799 100644 --- a/templates/Includes/GoogleMaps.ss +++ b/templates/Includes/GoogleMaps.ss @@ -2,7 +2,7 @@