summaryrefslogtreecommitdiff
path: root/addons/website_google_map/static/src
diff options
context:
space:
mode:
authorRichard Mathot <rim@openerp.com>2014-06-03 16:34:30 +0200
committerRichard Mathot <rim@openerp.com>2014-06-03 16:34:30 +0200
commitf04e6de2e729c8d638f6589f77abdfa4535b110e (patch)
tree378d9d126eb95938c63f03fc539256e6924cbc3c /addons/website_google_map/static/src
parentc1ae43c80764fafd154f09bbff4c12543e881609 (diff)
[FIX][IMP] Make partner maps work properly
[FIX] website*: unfuck buggy controllers [IMP] website*: display GoogleMap in a human-usable interface [IMP] website_google_map: large module cleaning - There is now only one controller, data is sent once for all! - Map is now fully resizable in its hosting template - HTML/CSS cleaning - JavaScript is now human-readable ;-)
Diffstat (limited to 'addons/website_google_map/static/src')
-rw-r--r--addons/website_google_map/static/src/css/google-map.css28
-rw-r--r--addons/website_google_map/static/src/js/google_map.js143
2 files changed, 99 insertions, 72 deletions
diff --git a/addons/website_google_map/static/src/css/google-map.css b/addons/website_google_map/static/src/css/google-map.css
new file mode 100644
index 00000000000..3d5ec1d8f2d
--- /dev/null
+++ b/addons/website_google_map/static/src/css/google-map.css
@@ -0,0 +1,28 @@
+html {
+ height: 100%;
+}
+
+body {
+ margin: 0;
+ padding: 0;
+ height: 100%;
+}
+
+#odoo-google-map {
+ width: 100%;
+ height: 100%;
+}
+
+.marker {
+ font-size: 13px !important;
+}
+
+.marker a {
+ text-decoration: none;
+}
+
+.marker pre {
+ margin-top: 0;
+ margin-bottom: 0;
+ font-family: sans-serif !important;
+}
diff --git a/addons/website_google_map/static/src/js/google_map.js b/addons/website_google_map/static/src/js/google_map.js
index 19f4a5e6423..53e5342bbfc 100644
--- a/addons/website_google_map/static/src/js/google_map.js
+++ b/addons/website_google_map/static/src/js/google_map.js
@@ -1,84 +1,83 @@
-function initialize(pt) {
- var center = new google.maps.LatLng(10.91, 5.38);
- var Geocoder = new google.maps.Geocoder();
+function initialize_map() {
+ 'use strict';
- var map = new google.maps.Map(document.getElementById('map'), {
- zoom: 1,
- center: center,
- mapTypeId: google.maps.MapTypeId.ROADMAP
- });
+ // MAP CONFIG AND LOADING
+ var map = new google.maps.Map(document.getElementById('odoo-google-map'), {
+ zoom: 1,
+ center: {lat: 0.0, lng: 0.0},
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ });
- var infoWindow = new google.maps.InfoWindow();
+ // ENABLE ADRESS GEOCODING
+ var Geocoder = new google.maps.Geocoder();
- google.maps.event.addListener(map, 'click', function() {
- infoWindow.close();
- });
+ // INFO BUBBLES
+ var infoWindow = new google.maps.InfoWindow();
+ var partners = new google.maps.MarkerImage('/website_google_map/static/src/img/partners.png', new google.maps.Size(25, 25));
+ var partner_url = document.body.getAttribute('data-partner-url') || '';
+ var markers = [];
- var partners = new google.maps.MarkerImage("/website_google_map/static/src/img/partners.png",new google.maps.Size(25, 25));
+ google.maps.event.addListener(map, 'click', function() {
+ infoWindow.close();
+ });
- var markers = [];
+ // Display the bubble once clicked
+ var onMarkerClick = function() {
+ var marker = this;
+ var p = marker.partner;
+ infoWindow.setContent(
+ '<div class="marker">'+
+ (partner_url.length ? '<a target="_top" href="'+partner_url+p.id+'"><b>'+p.name +'</b></a>' : '<b>'+p.name+'</b>' )+
+ (p.type ? ' <b>' + p.type + '</b>' : '')+
+ ' <pre>' + p.address + '</pre>'+
+ '</div>'
+ );
+ infoWindow.open(map, marker);
+ };
- var onMarkerClick = function() {
- var marker = this;
- var p = marker.partner;
- infoWindow.setContent(
- '<div class="marker">'+
- (partner_url.length ? '<a target="_top" href="'+partner_url+p.id+'"><b>'+p.name +'</b></a>' : '<b>'+p.name+'</b>' )+ '<br/>'+
- (p.type ? ' <b>' + p.type + '</b>' : '')+
- ' <pre>' + p.address + '</pre>'+
- '</div>'
- );
- infoWindow.open(map, marker);
- };
-
- var set_marker = function(partner) {
- if (!partner.latitude && !partner.longitude) {
-
- Geocoder.geocode( { 'address': partner.address}, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- var location = results[0].geometry.location;
-
- $.post("/google_map/set_partner_position", {
- 'partner_id': partner.id,
- 'latitude': location.ob,
- 'longitude': location.pb
- });
- partner.latitude = location.ob;
- partner.longitude = location.pb;
-
- map.setCenter(results[0].geometry.location);
- var marker = new google.maps.Marker({
- partner: partner,
- map: map,
- icon: partners,
- position: location
- });
- google.maps.event.addListener(marker, 'click', onMarkerClick);
- markers.push(marker);
+ // Create a bubble for a partner
+ var set_marker = function(partner) {
+ // If no lat & long, geocode adress
+ // TODO: a server cronjob that will store these coordinates in database instead of resolving them on-the-fly
+ if (!partner.latitude && !partner.longitude) {
+ Geocoder.geocode({'address': partner.address}, function(results, status) {
+ if (status === google.maps.GeocoderStatus.OK) {
+ var location = results[0].geometry.location;
+ partner.latitude = location.ob;
+ partner.longitude = location.pb;
+ var marker = new google.maps.Marker({
+ partner: partner,
+ map: map,
+ icon: partners,
+ position: location
+ });
+ google.maps.event.addListener(marker, 'click', onMarkerClick);
+ markers.push(marker);
+ } else {
+ console.debug('Geocode was not successful for the following reason: ' + status);
+ }
+ });
} else {
- console.debug('Geocode was not successful for the following reason: ' + status);
+ var latLng = new google.maps.LatLng(partner.latitude, partner.longitude);
+ var marker = new google.maps.Marker({
+ partner: partner,
+ icon: partners,
+ map: map,
+ position: latLng
+ });
+ google.maps.event.addListener(marker, 'click', onMarkerClick);
+ markers.push(marker);
}
- });
+ };
- } else {
-
- var latLng = new google.maps.LatLng(partner.latitude, partner.longitude);
- var marker = new google.maps.Marker({
- partner: partner,
- icon: partners,
- position: latLng
- });
- google.maps.event.addListener(marker, 'click', onMarkerClick);
- markers.push(marker);
+ // Create the markers and cluster them on the map
+ if (odoo_partner_data){ /* odoo_partner_data special variable should have been defined in google_map.xml */
+ for (var i = 0; i < odoo_partner_data.counter; i++) {
+ set_marker(odoo_partner_data.partners[i]);
+ }
+ var markerCluster = new MarkerClusterer(map, markers);
}
-
- };
-
- if (data)
- for (var i = 0; i < data.counter; i++) {
- set_marker(data.partners[i]);
- }
- var markerCluster = new MarkerClusterer(map, markers);
}
-google.maps.event.addDomListener(window, 'load', initialize);
+// Initialize map once the DOM has been loaded
+google.maps.event.addDomListener(window, 'load', initialize_map);