/********************************* *** Class: PPolyCreatorOptions *** *********************************/ PPolyCreatorOptions = function() { this.icon = new PIcon(); this.icon.image = "http://api.pushpin.com/api/1.3/kamap4p/htdocs/images/icon_polypoint.gif"; this.icon.iconSize = new PSize(10,10); this.icon.shadowSize = new PSize(0,0); this.icon.iconAnchor = new PPoint(5,5); this.line = new Object(); this.line.color = "#999999"; this.line.weight = 4; this.line.opacity = 0.7; this.poly = new Object(); this.poly.color = "#eb5920"; this.poly.weight = 4; this.poly.opacity = 0.7; this.poly.fill = "#eb7041"; // add more options later } var polycreatorurl = "http://pin.pushpin.com"; /************************** *** Class: PPolyCreator *** **************************/ PPolyCreator = function(options) { if (options) this.options = options; else this.options = new PPolyCreatorOptions(); this.click = null; this.points = []; this.savePoints = []; this.places = []; this.name = null; this.description = null; this.eventTypes = new Object(); this.eventTypes.addpoly = 'addpoly'; this.eventTypes.savepoly = 'savepoly'; this.eventManager = new _eventManager(); for (var ev in this.eventTypes) this.eventManager.registerEventID(ev); } PPolyCreator.prototype.addListener = function(eventId, func) { this.eventManager.registerForEvent(eventId, [], func); } PPolyCreator.prototype.removeListener = function(eventId, func) { this.eventManager.deregisterForEvent(eventId, [], func); } PPolyCreator.prototype.attachMap = function(map) { this.map = map; var polycreator = this; this.click = PEvent.addListener(this.map, 'click', function(overlay, point) { if (overlay) { polycreator.addPoly(overlay.point); } else if (point) { polycreator.addPointLine(point); } }); } PPolyCreator.prototype.detachMap = function() { if (this.map && this.click) this.map.removeListener(this.click); } PPolyCreator.prototype.cancelPoly = function() { this.reset() this.map.clearOverlays(); //this.detachMap(); } PPolyCreator.prototype.reset = function() { this.points = []; this.places = []; this.name = null; this.description = null; if (this.map) this.map.closeInfoWindow(); } PPolyCreator.prototype.addPoly = function(point) { if (point.equals(this.points[0])) { this.points.push(point); this.map.clearOverlays(); this.map.addOverlay(new PPolygon(this.points,this.options.poly.color,this.options.poly.weight,this.options.poly.opacity,this.options.poly.fill)); this.savePoints = this.points.slice(); this.points = []; this.eventManager.triggerEvent('addpoly', this.savePoints); } } PPolyCreator.prototype.addPointLine = function(point) { this.points.push(point); if (this.map) { this.map.addOverlay(new PMarker(point, this.options.icon)); if (this.points.length > 1) this.map.addOverlay(new PPolyline([point,this.points[this.points.length-2]],this.options.line.color,this.options.line.weight,this.options.line.opacity)); } } PPolyCreator.prototype.savePoly = function() { // send to servlet var query = "&vtc=POLYGON(("; // ensure polygon and closed if (this.savePoints.length < 3) return; if (!this.savePoints[0].equals(this.savePoints[this.savePoints.length-1])) this.savePoints.push(this.savePoints[0]); for (var i=0; i