Created
April 1, 2014 08:35
-
-
Save anonymous/9910241 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
GMaps.prototype.drawPolyline = function(options) { | |
var path = [], | |
points = options.path; | |
if (points.length) { | |
if (points[0][0] === undefined) { | |
path = points; | |
} | |
else { | |
for (var i=0, latlng; latlng=points[i]; i++) { | |
path.push(new google.maps.LatLng(latlng[0], latlng[1])); | |
} | |
} | |
} | |
var polyline_options = { | |
map: this.map, | |
path: path, | |
strokeColor: options.strokeColor, | |
strokeOpacity: options.strokeOpacity, | |
strokeWeight: options.strokeWeight, | |
geodesic: options.geodesic, | |
clickable: true, | |
editable: false, | |
visible: true | |
}; | |
if (options.hasOwnProperty("clickable")) { | |
polyline_options.clickable = options.clickable; | |
} | |
if (options.hasOwnProperty("editable")) { | |
polyline_options.editable = options.editable; | |
} | |
if (options.hasOwnProperty("icons")) { | |
polyline_options.icons = options.icons; | |
} | |
if (options.hasOwnProperty("zIndex")) { | |
polyline_options.zIndex = options.zIndex; | |
} | |
var polyline = new google.maps.Polyline(polyline_options); | |
var polyline_events = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseout', 'mouseover', 'mouseup', 'rightclick']; | |
for (var ev = 0; ev < polyline_events.length; ev++) { | |
(function(object, name) { | |
if (options[name]) { | |
google.maps.event.addListener(object, name, function(e){ | |
options[name].apply(this, [e]); | |
}); | |
} | |
})(polyline, polyline_events[ev]); | |
} | |
this.polylines.push(polyline); | |
GMaps.fire('polyline_added', polyline, this); | |
return polyline; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment