Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions gmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,12 @@ GMaps.prototype.addControl = function(options) {
return control;
};

GMaps.prototype.createMarker = function(options) {
var initializeOptions = function(options) {
if (options.lat == undefined && options.lng == undefined && options.position == undefined) {
throw 'No latitude or longitude defined.';
}

var self = this,
details = options.details,
fences = options.fences,
outside = options.outside,
base_options = {
var base_options = {
position: new google.maps.LatLng(options.lat, options.lng),
map: null
};
Expand All @@ -529,8 +525,18 @@ GMaps.prototype.createMarker = function(options) {
delete options.fences;
delete options.outside;

var marker_options = extend_object(base_options, options),
marker = new google.maps.Marker(marker_options);
return extend_object(base_options, options);
}

var initializeMarker = function(marker, options) {
if (marker === null) {
marker = new google.maps.Marker(options);
}

var self = this,
details = options.details,
fences = options.fences,
outside = options.outside;

marker.fences = fences;

Expand All @@ -542,6 +548,7 @@ GMaps.prototype.createMarker = function(options) {
for (var ev = 0; ev < info_window_events.length; ev++) {
(function(object, name) {
if (options.infoWindow[name]) {
google.maps.event.clearListeners(object, name);
google.maps.event.addListener(object, name, function(e){
options.infoWindow[name].apply(this, [e]);
});
Expand All @@ -557,6 +564,7 @@ GMaps.prototype.createMarker = function(options) {
for (var ev = 0; ev < marker_events.length; ev++) {
(function(object, name) {
if (options[name]) {
google.maps.event.clearListeners(object, name);
google.maps.event.addListener(object, name, function(){
options[name].apply(this, [this]);
});
Expand All @@ -567,6 +575,7 @@ GMaps.prototype.createMarker = function(options) {
for (var ev = 0; ev < marker_events_with_mouse.length; ev++) {
(function(map, object, name) {
if (options[name]) {
google.maps.event.clearListeners(object, name);
google.maps.event.addListener(object, name, function(me){
if(!me.pixel){
me.pixel = map.getProjection().fromLatLngToPoint(me.latLng)
Expand All @@ -578,6 +587,7 @@ GMaps.prototype.createMarker = function(options) {
})(this.map, marker, marker_events_with_mouse[ev]);
}

google.maps.event.clearListeners(marker, 'click');
google.maps.event.addListener(marker, 'click', function() {
this.details = details;

Expand All @@ -591,6 +601,7 @@ GMaps.prototype.createMarker = function(options) {
}
});

google.maps.event.clearListeners(marker, 'rightclick');
google.maps.event.addListener(marker, 'rightclick', function(e) {
e.marker = this;

Expand All @@ -604,6 +615,7 @@ GMaps.prototype.createMarker = function(options) {
});

if (marker.fences) {
google.maps.event.clearListeners(marker, 'dragend');
google.maps.event.addListener(marker, 'dragend', function() {
self.checkMarkerGeofence(marker, function(m, f) {
outside(m, f);
Expand All @@ -612,6 +624,11 @@ GMaps.prototype.createMarker = function(options) {
}

return marker;
}

GMaps.prototype.createMarker = function(options) {
var marker_options = initializeOptions(options);
return initializeMarker(null, marker_options);
};

GMaps.prototype.addMarker = function(options) {
Expand Down Expand Up @@ -658,6 +675,22 @@ GMaps.prototype.hideInfoWindows = function() {
}
};

GMaps.prototype.changeMarker = function(marker, options) {
var marker_options = initializeOptions(options);
initializeMarker(marker, marker_options);

for (var i = 0; i < this.markers.length; i++) {
if (this.markers[i] === marker) {
marker.setMap(null);
marker.setOptions(marker_options);
marker.setMap(this.map);
break;
}
}

return marker;
}

GMaps.prototype.removeMarker = function(marker) {
for (var i = 0; i < this.markers.length; i++) {
if (this.markers[i] === marker) {
Expand Down