[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 ;-)
This commit is contained in:
Richard Mathot
2014-06-03 16:34:30 +02:00
parent c1ae43c807
commit f04e6de2e7
14 changed files with 231 additions and 194 deletions
@@ -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;
}
@@ -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);