Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

added inside callback for geofences #294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions gmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ GMaps.prototype.createMarker = function(options) {
details = options.details,
fences = options.fences,
outside = options.outside,
inside = options.inside,
base_options = {
position: new google.maps.LatLng(options.lat, options.lng),
map: null
Expand All @@ -544,6 +545,7 @@ GMaps.prototype.createMarker = function(options) {
delete options.lng;
delete options.fences;
delete options.outside;
delete options.inside;

var marker_options = extend_object(base_options, options),
marker = new google.maps.Marker(marker_options);
Expand Down Expand Up @@ -622,7 +624,11 @@ GMaps.prototype.createMarker = function(options) {
if (marker.fences) {
google.maps.event.addListener(marker, 'dragend', function() {
self.checkMarkerGeofence(marker, function(m, f) {
outside(m, f);
if( typeof outside != "undefined")
outside(m, f);
}, function(m, f) {
if( typeof inside != "undefined")
inside(m, f);
});
});
}
Expand Down Expand Up @@ -1512,12 +1518,14 @@ GMaps.prototype.checkGeofence = function(lat, lng, fence) {
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
};

GMaps.prototype.checkMarkerGeofence = function(marker, outside_callback) {
GMaps.prototype.checkMarkerGeofence = function(marker, outside_callback, inside_callback) {
if (marker.fences) {
for (var i = 0, fence; fence = marker.fences[i]; i++) {
var pos = marker.getPosition();
if (!this.checkGeofence(pos.lat(), pos.lng(), fence)) {
outside_callback(marker, fence);
} else {
inside_callback(marker, fence);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/gmaps.geofences.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ GMaps.prototype.checkGeofence = function(lat, lng, fence) {
return fence.containsLatLng(new google.maps.LatLng(lat, lng));
};

GMaps.prototype.checkMarkerGeofence = function(marker, outside_callback) {
GMaps.prototype.checkMarkerGeofence = function(marker, outside_callback, inside_callback) {
if (marker.fences) {
for (var i = 0, fence; fence = marker.fences[i]; i++) {
var pos = marker.getPosition();
if (!this.checkGeofence(pos.lat(), pos.lng(), fence)) {
outside_callback(marker, fence);
} else {
inside_callback(marker, fence);
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/gmaps.markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ GMaps.prototype.createMarker = function(options) {
details = options.details,
fences = options.fences,
outside = options.outside,
inside = options.inside,
base_options = {
position: new google.maps.LatLng(options.lat, options.lng),
map: null
Expand All @@ -16,6 +17,7 @@ GMaps.prototype.createMarker = function(options) {
delete options.lng;
delete options.fences;
delete options.outside;
delete options.inside;

var marker_options = extend_object(base_options, options),
marker = new google.maps.Marker(marker_options);
Expand Down Expand Up @@ -94,7 +96,11 @@ GMaps.prototype.createMarker = function(options) {
if (marker.fences) {
google.maps.event.addListener(marker, 'dragend', function() {
self.checkMarkerGeofence(marker, function(m, f) {
outside(m, f);
if( typeof outside != "undefined")
outside(m, f);
}, function(m, f) {
if( typeof inside != "undefined")
inside(m, f);
});
});
}
Expand Down