--- gmap_foswiki.js 2017-05-09 20:17:33.588520658 -0400
+++ gmap_foswiki_edit.js 2017-05-09 21:03:19.186883909 -0400
@@ -6,55 +6,59 @@
opts = $this.data();
if (typeof(opts.marker) !== 'undefined') {
- $.each(opts.marker.values, function(index, item) {
- opts.marker.events = {
- "click": function(marker) {
- var $this = $(this),
- infowindow = $this.gmap3({get:{name:"infowindow"}}),
- content;
-
- if (item.address) {
- content = item.address.replace(/, */g, '
');
-
- if (infowindow) {
- infowindow.open($this.gmap3("get"), marker);
- infowindow.setContent(content);
- } else {
- $this.gmap3({
- infowindow: {
- anchor:marker,
- options:{ content: content }
- }
- });
- }
+ opts.marker.events = {
+ "click": function(marker, event, context) {
+ var $this = $(this);
+ var map = $this.gmap3("get");
+ var infowindow = $this.gmap3({get:{name:"infowindow"}});
+ var content = "";
+
+ if ( context !== undefined && context.hasOwnProperty('address') ) {
+ if ( context.hasOwnProperty('data') {
+ content = context.data;
+ } else {
+ content = context.address.replace(/, */g, '
');
+ }
+ }
+
+ if ( content.trim().length > 0 ) {
+ if (infowindow) {
+ infowindow.open(map, marker);
+ infowindow.setContent(content);
} else {
$this.gmap3({
- getaddress: {
- latLng:marker.getPosition(),
- callback:function(results){
- var content = results && results[0] ? results[0].formatted_address : "no address";
-
- if (infowindow){
- infowindow.open($this.gmap3("get"), marker);
- infowindow.setContent(content);
- } else {
- $this.gmap3({
- infowindow: {
- anchor:marker,
- options:{ content: content }
- }
- });
- }
- }
+ infowindow: {
+ anchor: marker,
+ options:{ content: content }
}
});
}
+ } else {
+ $this.gmap3({
+ getaddress: {
+ latLng: marker.getPosition(),
+ callback: function(results) {
+ var content = results && results[0] ? results[0].formatted_address : "No address or data provided.";
+
+ if (infowindow) {
+ infowindow.open(map, marker);
+ infowindow.setContent(content);
+ } else {
+ $this.gmap3({
+ infowindow: {
+ anchor:marker,
+ options:{ content: content }
+ }
+ });
+ }
+ }
+ }
+ });
}
- };
- });
+ }
+ };
}
-
$this.gmap3(opts);
});
});