Last active
December 15, 2015 00:49
-
-
Save fwg/5175648 to your computer and use it in GitHub Desktop.
melanie349's survivor class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Survivor Class | |
function Survivor() { | |
this.markers = []; | |
this.path = []; | |
this.labels = []; | |
this.polyline = null; | |
this.auditPoints = []; | |
// array to keep the functions that will be called when the data is loaded | |
this.callbacks = []; | |
// keep `this` value around for the asynchronous code | |
var that = this; | |
$.getJSON('/Audit/WayPoints', function (data) { | |
for (i = 0; i < data.length; i++) { | |
that.auditPoints.push(new AuditPoint(data[i].ID, data[i].X, data[i].Y)); | |
} | |
Init(); | |
}); | |
var myIcon = new google.maps.MarkerImage('Images/pin1.png', | |
new google.maps.Size(100, 100), | |
new google.maps.Point(0, 0), | |
new google.maps.Point(3, 3) | |
); | |
function CreateMarkers() { | |
for (var i = 0, max = that.auditPoints.length; i < max; i++) { | |
var pathmarker = new google.maps.Marker({ | |
position: that.auditPoints[i].GoogleLatLong, | |
icon: myIcon | |
}); | |
that.markers.push(pathmarker); | |
that.path.push(that.auditPoints[i].GoogleLatLong); | |
var label = new Label({ | |
}); | |
label.bindTo('position', that.markers[i], 'position'); | |
label.text = i; | |
that.labels.push(label); | |
} | |
}; | |
function CreatePolyline() { | |
that.polyline = new google.maps.Polyline({ | |
path: that.path, | |
strokeColor: "#FF0000", | |
strokeOpacity: 1.0, | |
strokeWeight: 2 | |
}); | |
} | |
// here we need the current `this` value saved, otherwise the Init() | |
// from the getJSON callback would lose it. | |
function Init() { | |
CreateMarkers(); | |
CreatePolyline(); | |
// notify all callbacks | |
for (var i = 0, l = that.callbacks.length; i < l; i++) { | |
that.callbacks[i].call(); | |
} | |
}; | |
}; | |
Survivor.prototype.onLoaded = function (funct) { | |
this.callbacks.push(funct); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment