Skip to content

Instantly share code, notes, and snippets.

@kyle-mccarthy
Last active February 7, 2018 17:35
Show Gist options
  • Save kyle-mccarthy/9b65aa68c5d0acc84e3ab8bb79b9cf02 to your computer and use it in GitHub Desktop.
Save kyle-mccarthy/9b65aa68c5d0acc84e3ab8bb79b9cf02 to your computer and use it in GitHub Desktop.
Modify Google Maps with Callrail numbers
var callrailGoogleMaps = {
getNumbers: function() {
var self = this;
window.CallTrk.getSwapNumbers(null, function(nums) {
self.swapNumbers(nums);
});
},
getMapPoints: function() {
if (mapping !== undefined) {
return mapping.mapPoint.alllocmap.points;
}
return [];
},
swapNumbers: function(nums) {
this.getMapPoints().forEach(function(p) {
var n = Number(p.appointments.replace(/-/g, ''));
if (nums[n] !== undefined) {
var fmtd = (nums[n] + "").replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
p.appointments = fmtd;
}
});
this.reloadMap();
},
reloadMap: function() {
mapping.load()
},
init: function() {
var self = this;
if (window.mapping === undefined || window.CallTrk === undefined) {
setTimeout(function() {
self.init();
}, 500)
} else {
this.getNumbers();
}
}
};
callrailGoogleMaps.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment