diff --git a/README.md b/README.md
index 3c0ecaa..c6dbaed 100644
--- a/README.md
+++ b/README.md
@@ -5,4 +5,4 @@ Plugin jQuery : Create your own complet Google Map
For documentation and live demo : http://tilotiti.github.com/jQuery-Google-Map/
-For support : http://www.tiloblog.com/js/jquery/jquery-plugin-google-map-creez-votre-google-map-complete
+For support : http://www.tiloweb.com/js/jquery/jquery-plugin-google-map-creez-votre-google-map-complete
diff --git a/jquery.googlemap.js b/jquery.googlemap.js
index c42fa0f..e3b3403 100644
--- a/jquery.googlemap.js
+++ b/jquery.googlemap.js
@@ -6,7 +6,11 @@ $(function() {
coords : [48.895651, 2.290569],
type : "ROADMAP",
debug : false,
- langage : "english"
+ langage : "english",
+ overviewMapControl: false,
+ streetViewControl: false,
+ scrollwheel: false,
+ mapTypeControl: false
}, params);
switch(params.type) {
@@ -27,11 +31,11 @@ $(function() {
zoom: params.zoom,
center: new google.maps.LatLng(params.coords[0], params.coords[1]),
mapTypeId: params.type,
- scrollwheel: false,
- streetViewControl: false,
- overviewMapControl: false,
- mapTypeControl: false,
- draggable: false
+ scrollwheel: params.scrollwheel,
+ streetViewControl: params.streetViewControl,
+ overviewMapControl: params.overviewMapControl,
+ mapTypeControl: params.mapTypeControl
+
});
$(this).data('googleMap', map);
@@ -63,139 +67,173 @@ $(function() {
if(!$this.data('googleMap')) {
if($this.data('googleDebug'))
console.error("jQuery googleMap : Unable to add a marker where there is no map !");
+
return false;
}
if(!params.coords && !params.address) {
if($this.data('googleDebug'))
console.error("jQuery googleMap : Unable to add a marker if you don't tell us where !");
+
return false;
}
if(params.address && typeof params.address == "string") {
- geocoder = new google.maps.Geocoder();
-
- geocoder.geocode({
- address : params.address,
- bounds : $this.data('googleBound'),
- language : $this.data('googleLang')
- }, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- $this.data('googleBound').extend(results[0].geometry.location);
-
- if(params.icon) {
- var marker = new google.maps.Marker({
- map: $this.data('googleMap'),
- position: results[0].geometry.location,
- title: params.title,
- icon: params.icon,
- draggable: params.draggable
- });
- } else {
- var marker = new google.maps.Marker({
- map: $this.data('googleMap'),
- position: results[0].geometry.location,
- title: params.title,
- draggable: params.draggable
- });
- }
-
- if(params.draggable) {
- google.maps.event.addListener(marker, 'dragend', function() {
- var location = marker.getPosition();
-
- var coords = {};
-
- coords.lat = location.lat();
- coords.lon = location.lng();
-
- params.success(coords);
- });
- }
- if(params.title != "" && params.text != "" && !params.url) {
- var infowindow = new google.maps.InfoWindow({
- content: "
"+params.title+"
"+params.text
- });
+ var geocodeAsync = function($that) {
+
+ var geocoder = new google.maps.Geocoder();
+
+ geocoder.geocode({
+ address : params.address,
+ bounds : $that.data('googleBound'),
+ language : $that.data('googleLang')
+ }, function(results, status) {
+
+ if (status == google.maps.GeocoderStatus.OK) {
+ $that.data('googleBound').extend(results[0].geometry.location);
+
+ if(params.icon) {
+ var marker = new google.maps.Marker({
+ map: $this.data('googleMap'),
+ position: results[0].geometry.location,
+ title: params.title,
+ icon: params.icon,
+ draggable: params.draggable
+ });
+ } else {
+ var marker = new google.maps.Marker({
+ map: $that.data('googleMap'),
+ position: results[0].geometry.location,
+ title: params.title,
+ draggable: params.draggable
+ });
+ }
+
+ if(params.draggable) {
+ google.maps.event.addListener(marker, 'dragend', function() {
+ var location = marker.getPosition();
+
+ var coords = {};
+
+ coords.lat = location.lat();
+ coords.lon = location.lng();
+
+ params.success(coords, $this);
+ });
+ }
+
+ if(params.title != "" && params.text != "" && !params.url) {
+ var infowindow = new google.maps.InfoWindow({
+ content: ""+params.title+"
"+params.text
+ });
+
+ var map = $that.data('googleMap');
+ previous_infowindow = null;
+ google.maps.event.addListener(marker, 'click', function() {
+ if(previous_infowindow!==null)
+ previous_infowindow.close(map, marker);
+ infowindow.open(map, marker);
+ previous_infowindow=infowindow;
+ });
+ } else if(params.url) {
+ google.maps.event.addListener(marker, 'click', function() {
+ document.location = params.url;
+ });
+ }
+
+ if(!params.id) {
+ $that.data('googleMarker').push(marker);
+ } else {
+ $that.data('googleMarker')[params.id] = marker;
+ }
+
+ if($that.data('googleMarker').length == 1) {
+ $that.data('googleMap').setCenter(results[0].geometry.location);
+ $that.data('googleMap').setZoom($that.data('googleMap').getZoom());
+ } else {
+ $that.data('googleMap').fitBounds($that.data('googleBound'));
+ }
+
+ var coords = {};
+ coords.lat = results[0].geometry.location.lat();
+ coords.lon = results[0].geometry.location.lng();
+
+ for(var i in results[0].address_components) {
+ if(results[0].address_components[i].types.indexOf("postal_code") > -1) {
+ coords.zipcode = results[0].address_components[i].long_name;
+ }
+ }
+
+ params.success(coords, $this);
- var map = $this.data('googleMap');
-
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map, marker);
- });
- } else if(params.url) {
- google.maps.event.addListener(marker, 'click', function() {
- document.location = params.url;
- });
- }
-
- if(!params.id) {
- $this.data('googleMarker').push(marker);
} else {
- $this.data('googleMarker')[params.id] = marker;
+ if($this.data('googleDebug'))
+ console.error("jQuery googleMap : Unable to find the place asked for the marker ("+status+")");
}
-
- if($this.data('googleMarker').length == 1) {
- $this.data('googleMap').setCenter(results[0].geometry.location);
- $this.data('googleMap').setZoom($this.data('googleMap').getZoom());
- } else {
- $this.data('googleMap').fitBounds($this.data('googleBound'));
- }
-
- var coords = {};
- coords.lat = results[0].geometry.location.lat();
- coords.lon = results[0].geometry.location.lng();
-
- params.success(coords);
-
- } else {
- if($this.data('googleDebug'))
- console.error("jQuery googleMap : Unable to find the place asked for the marker ("+status+")");
- }
- });
+ });
+ }($this);
} else {
$this.data('googleBound').extend(new google.maps.LatLng(params.coords[0], params.coords[1]));
- if(params.icon) {
+ if(params.icon) {
var marker = new google.maps.Marker({
map: $this.data('googleMap'),
position: new google.maps.LatLng(params.coords[0], params.coords[1]),
title: params.title,
- icon: params.icon
+ icon: params.icon,
+ draggable: params.draggable
});
} else {
var marker = new google.maps.Marker({
map: $this.data('googleMap'),
position: new google.maps.LatLng(params.coords[0], params.coords[1]),
- title: params.title
+ title: params.title,
+ draggable: params.draggable
});
}
- if(params.title != "" && params.text != "" && !params.url) {
- var infowindow = new google.maps.InfoWindow({
+ if(params.title != "" && params.text != "" && !params.url) {
+ var infowindow = new google.maps.InfoWindow({
content: ""+params.title+"
"+params.text
});
var map = $this.data('googleMap');
-
- google.maps.event.addListener(marker, 'click', function() {
- infowindow.open(map, marker);
- });
+ previous_infowindow = null;
+ google.maps.event.addListener(marker, 'click', function() {
+ if(previous_infowindow!==null)
+ previous_infowindow.close(map, marker);
+ infowindow.open(map, marker);
+ previous_infowindow=infowindow;
+ });
} else if(params.url) {
- google.maps.event.addListener(marker, 'click', function() {
- document.location = params.url;
- });
+ google.maps.event.addListener(marker, 'click', function() {
+ document.location = params.url;
+ });
}
- if(!params.id) {
- $this.data('googleMarker').push(marker);
- } else {
- $this.data('googleMarker')[params.id] = marker;
- }
+ if(params.draggable) {
+ google.maps.event.addListener(marker, 'dragend', function() {
+ var location = marker.getPosition();
+
+ var coords = {};
+
+ coords.lat = location.lat();
+ coords.lon = location.lng();
+
+ params.success(coords, $this);
+ });
+ }
+
+ if(!params.id) {
+ $this.data('googleMarker').push(marker);
+ } else {
+ $this.data('googleMarker')[params.id] = marker;
+ }
if($this.data('googleMarker').length == 1) {
- $this.data('googleMap').setCenter(new google.maps.LatLng(params.coords[0], params.coords[1]));
- $this.data('googleMap').setZoom($this.data('googleMap').getZoom());
+ $this.data('googleMap').setCenter(new google.maps.LatLng(params.coords[0], params.coords[1]));
+ $this.data('googleMap').setZoom($this.data('googleMap').getZoom());
} else {
$this.data('googleMap').fitBounds($this.data('googleBound'));
}
@@ -203,7 +241,7 @@ $(function() {
params.success({
lat: params.coords[0],
lon: params.coords[1]
- });
+ }, $this);
}
});
@@ -214,23 +252,28 @@ $(function() {
this.each(function() {
var $this = $(this);
- if(!$this.data('googleMap')) {
- if($this.data('googleDebug'))
- console.log("jQuery googleMap : Unable to delete a marker where there is no map !");
- return false;
- }
-
- var $markers = $this.data('googleMarker');
-
- if(typeof $markers[id] != 'undefined') {
- $markers[id].setMap(null);
- if($this.data('googleDebug'))
- console.log('jQuery googleMap : marker deleted');
- } else {
- if($this.data('googleDebug'))
- console.error("jQuery googleMap : Unable to delete a marker if it not exists !");
- return false;
- }
+ if(!$this.data('googleMap')) {
+ if($this.data('googleDebug'))
+ console.log("jQuery googleMap : Unable to delete a marker where there is no map !");
+
+ return false;
+ }
+
+ var $markers = $this.data('googleMarker');
+
+ if(typeof $markers[id] != 'undefined') {
+ $markers[id].setMap(null);
+
+ if($this.data('googleDebug'))
+ console.log('jQuery googleMap : marker deleted');
+
+ return true;
+ } else {
+ if($this.data('googleDebug'))
+ console.error("jQuery googleMap : Unable to delete a marker if it not exists !");
+
+ return false;
+ }
});
}
@@ -253,55 +296,58 @@ $(function() {
panel: document.getElementById(params.route),
provideTripAlternatives: true
});
+
+ document.getElementById.innerHTML = "";
var waypoints = [];
- for(var i in params.step) {
- var step;
- if(typeof params.step[i] == "object") {
- step = new google.maps.LatLng(params.step[i][0], params.step[i][1]);
- } else {
- step = params.step[i];
- }
-
- waypoints.push({
- location: step,
- stopover: true
- });
- }
+ for(var i in params.step) {
+ var step;
+ if(typeof params.step[i] == "object") {
+ step = new google.maps.LatLng(params.step[i][0], params.step[i][1]);
+ } else {
+ step = params.step[i];
+ }
+
+ waypoints.push({
+ location: step,
+ stopover: true
+ });
+ }
if(typeof params.end != "object") {
- var geocoder = new google.maps.Geocoder();
-
- geocoder.geocode({
- address : params.end,
- bounds : $(this).data('googleBound'),
- language : params.langage
- }, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
-
- var request = {
- origin: params.start,
- destination: results[0].geometry.location,
- travelMode: google.maps.DirectionsTravelMode.DRIVING,
- region: "fr",
- waypoints: waypoints
- };
-
- direction.route(request, function(response, status) {
- if (status == google.maps.DirectionsStatus.OK) {
- way.setDirections(response);
- } else {
- if($(this).data('googleDebug'))
- console.error("jQuery googleMap : Unable to find the place asked for the route ("+response+")");
- }
- });
-
- } else {
- if($(this).data('googleDebug'))
- console.error("jQuery googleMap : Address not found");
- }
- });
+ var geocodeAsync = function($that) {
+ var geocoder = new google.maps.Geocoder();
+
+ geocoder.geocode({
+ address : params.end,
+ bounds : $that.data('googleBound'),
+ language : params.langage
+ }, function(results, status) {
+ if (status == google.maps.GeocoderStatus.OK) {
+ var request = {
+ origin: params.start,
+ destination: results[0].geometry.location,
+ travelMode: google.maps.DirectionsTravelMode.DRIVING,
+ region: "fr",
+ waypoints: waypoints
+ };
+
+ direction.route(request, function(response, status) {
+ if (status == google.maps.DirectionsStatus.OK) {
+ way.setDirections(response);
+ } else {
+ if($that.data('googleDebug'))
+ console.error("jQuery googleMap : Unable to find the place asked for the route ("+response+")");
+ }
+ });
+
+ } else {
+ if($that.data('googleDebug'))
+ console.error("jQuery googleMap : Address not found");
+ }
+ });
+ }($(this));
} else {
var request = {
origin: params.start,
@@ -316,7 +362,7 @@ $(function() {
way.setDirections(response);
} else {
if($(this).data('googleDebug'))
- console.error("jQuery googleMap : Address not found");
+ console.error("jQuery googleMap : Address not found");
}
});
}
diff --git a/googlemap.jquery.json b/package.json
similarity index 51%
rename from googlemap.jquery.json
rename to package.json
index 27ae407..f0623f8 100644
--- a/googlemap.jquery.json
+++ b/package.json
@@ -1,11 +1,11 @@
{
- "name": "googlemap",
+ "name": "jquery-googlemap",
"title": "Google Map",
- "version": "1.4.2",
+ "version": "1.5.0",
"author": {
- "name": "Thibault HENRY",
- "email": "thibaulthenry@tilotiti.com",
- "url": "http://www.tiloblog.com/"
+ "name": "Thibault HENRY",
+ "email": "thibault@henry.pro",
+ "url": "http://www.tiloweb.com/"
},
"licenses": [
{
@@ -15,19 +15,8 @@
],
"description": "A jQuery Plugin allows you to easely manipulate the Google Map API. You are now able to create maps, add some markers and create routes.",
"homepage": "http://tilotiti.github.com/jQuery-Google-Map/",
- "docs": "http://tilotiti.github.com/jQuery-Google-Map/",
- "demo": "http://tilotiti.github.com/jQuery-Google-Map/",
- "download": "https://github.com/tilotiti/jQuery-Google-Map/archive/master.zip",
- "keywords": [
- "grid",
- "datagrid",
- "table",
- "ui",
- "input",
- "ajax",
- "handsontable",
- "spreadsheet"
- ],
+ "repository": "https://github.com/Tilotiti/jQuery-Google-Map/",
+ "keywords": ["map", "googlemap", "google", "geocode", "route", "jquery-plugin", "ecosystem:jquery"],
"bugs": "http://tilotiti.github.com/jQuery-Google-Map/",
"dependencies": {
"jquery": ">=1.7"