GSVectorGraphicsConstants={resourceURL:(document.location.protocol.indexOf("http")==-1?"http:":document.location.protocol)+"//api.geosmart.co.nz/images/svg-v1-rc3/"};GSUtil.extend(GSVectorGraphics,GSMapFeature);function GSVectorGraphics(a){GSVectorGraphics.baseConstructor.call(this);this.textEl=undefined;if(_browser.svg){this.textEl=document.createElementNS(_globals.svgns,"text");this.textEl.setAttributeNS(null,"pointer-events","none")}else{if(_browser.isIE6up){this.textEl=document.createElement(_globals.vmlnsPrefix,":textbox")}}this.textStyle={"font-family":"Arial, Helvetica, Sans-serif","font-size":"12px","font-weight":"normal","font-style":"normal",color:"black"};this.setText(a.text,a["text-position"],a["text-style"]);this.resizeToLayer=false;this.isShowingInfo=false}GSVectorGraphics.prototype.setText=function(e,b,c){this.text=e;this.textPosition=b;if(this.text){while(this.textEl.firstChild){this.textEl.removeChild(this.textEl.firstChild)}var a=document.createTextNode(this.text);this.textEl.appendChild(a)}for(var d in c){this.textStyle[d]=c[d]}if(_browser.svg){this.textEl.setAttributeNS(null,"font-family",this.textStyle["font-family"]);this.textEl.setAttributeNS(null,"font-size",this.textStyle["font-size"]);this.textEl.setAttributeNS(null,"font-weight",this.textStyle["font-weight"]);this.textEl.setAttributeNS(null,"font-style",this.textStyle["font-style"]);this.textEl.setAttributeNS(null,"fill",this.textStyle.color)}else{if(_browser.isIE6up){this.textEl.style.fontFamily=this.textStyle["font-family"];this.textEl.style.fontSize=this.textStyle["font-size"];this.textEl.style.fontWeight=this.textStyle["font-weight"];this.textEl.style.fontStyle=this.textStyle["font-style"];this.textEl.style.color=this.textStyle.color}}if(this.onmap&&this.text){this.renderText()}};GSVectorGraphics.prototype.renderText=function(){var a=this.getBounds();var j=this.map.translateToMapCoordinate(new GSPoint(a.minX,a.maxY));var h=this.map.translateToMapCoordinate(new GSPoint(a.maxX,a.maxY));var b=this.map.translateToMapCoordinate(new GSPoint(a.minX,a.minY));if(_browser.svg){if(this.textStyle["display-threshold"]<this.map.scaleIdx){this.textEl.setAttributeNS(null,"visibility","hidden");return}else{this.textEl.setAttributeNS(null,"visibility","visible")}if(this.textStyle["text-align"]){var e=0;switch(this.textStyle["text-align"]){case"left":break;case"center":var g=this.textEl.getComputedTextLength();var f=h.x-j.x;e=(f-g)/2;break;case"right":this.textEl.setAttributeNS(null,"text-anchor","end");e=h.x-j.x;break}this.textEl.setAttributeNS(null,"x",j.x+e)}else{this.textEl.setAttributeNS(null,"x",j.x+this.textPosition.x)}if(this.textStyle["vertical-align"]){switch(this.textStyle["vertical-align"]){case"top":this.textEl.setAttributeNS(null,"y",j.y+this.textEl.getBBox().height);break;case"middle":var i=this.textEl.getBBox().height;var c=b.y-j.y;var d=(c-i)/2;this.textEl.setAttributeNS(null,"y",j.y+this.textEl.getBBox().height+d);break;case"bottom":this.textEl.setAttributeNS(null,"y",b.y);break}}else{this.textEl.setAttributeNS(null,"y",j.y+this.textEl.getBBox().height+this.textPosition.y)}}else{if(_browser.isIE6up){if(this.textStyle["display-threshold"]<this.map.scaleIdx){this.textEl.style.visibility="hidden";return}else{this.textEl.style.visibility="visible"}this.textEl.style.position="relative";this.textEl.style.left=0;this.textEl.style.top=0;var f=Math.round(h.x)-Math.round(j.x);var c=Math.round(b.y)-Math.round(j.y);this.textEl.style.height=c+"px";if(this.textStyle["text-align"]){this.graphicsEl.style.textAlign=this.textStyle["text-align"]}else{this.textEl.style.paddingLeft=this.textPosition.x+"px"}if(this.textStyle["vertical-align"]){var i=parseInt(this.textStyle["font-size"]);switch(this.textStyle["vertical-align"]){case"top":this.textEl.style.top=0;break;case"middle":this.textEl.style.top=((c-i)/2)>=0?((c-i)/2):0;break;case"bottom":this.textEl.style.top=(c-i);break}}else{this.textEl.style.top=this.textPosition.y}}}};GSVectorGraphics.prototype.getBounds=function(){};GSVectorGraphics.prototype.getStyle=function(){return this.style};GSVectorGraphics.prototype.setStyle=function(a){for(var c in a){var b=a[c];switch(c){case"stroke":this.setStroke(b);break;case"stroke-width":this.setStrokeWidth(b);break;case"stroke-opacity":this.setStrokeOpacity(b);break;case"stroke-linecap":this.setStrokeLinecap(b);break;case"stroke-linejoin":this.setStrokeLinejoin(b);break;case"stroke-style":this.setStrokeStyle(b);break;case"fill":this.setFill(b);break;case"fill-opacity":this.setFillOpacity(b);break;case"opacity":this.setOpacity(b);break;default:this.graphicsEl.style[c]=b;break}}};GSVectorGraphics.prototype.getStroke=function(){return this.style.stroke};GSVectorGraphics.prototype.setStroke=function(a){this.style.stroke=a;return this._setStroke(a)};GSVectorGraphics.prototype._setStroke=function(a){if(_browser.svg){this.setStyleProperty("stroke",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");if(b=="none"){this.setStyleProperty("on",false,b)}else{this.setStyleProperty("color",a,b)}}}return this};GSVectorGraphics.prototype.getStrokeWidth=function(){return parseInt(this.style["stroke-width"])};GSVectorGraphics.prototype.setStrokeWidth=function(a){this.style["stroke-width"]=a;return this._setStrokeWidth(a)};GSVectorGraphics.prototype._setStrokeWidth=function(a){if(_browser.svg){this.setStyleProperty("stroke-width",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");var c=""+a;if(isNaN(parseInt(c.charAt(c.length-1),10))==false){a+="px"}this.setStyleProperty("weight",a,b)}}return this};GSVectorGraphics.prototype.getStrokeOpacity=function(){return parseFloat(this.style["stroke-opacity"])};GSVectorGraphics.prototype.setStrokeOpacity=function(a){this.style["stroke-opacity"]=a;return this._setStrokeOpacity(a)};GSVectorGraphics.prototype._setStrokeOpacity=function(a){if(_browser.svg){this.setStyleProperty("stroke-opacity",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");this.setStyleProperty("opacity",a,b)}}return this};GSVectorGraphics.prototype.getStrokeLinecap=function(){return this.style["stroke-linecap"]};GSVectorGraphics.prototype.setStrokeLinecap=function(a){this.style["stroke-linecap"]=a;return this._setStrokeLinecap(a)};GSVectorGraphics.prototype._setStrokeLinecap=function(a){if(_browser.svg){this.setStyleProperty("stroke-linecap",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");this.setStyleProperty("endcap",a,b)}}return this};GSVectorGraphics.prototype.getStrokeLinejoin=function(){return this.style["stroke-linejoin"]};GSVectorGraphics.prototype.setStrokeLinejoin=function(a){this.style["stroke-linejoin"]=a;return this._setStrokeLinejoin(a)};GSVectorGraphics.prototype._setStrokeLinejoin=function(a){if(_browser.svg){this.setStyleProperty("stroke-linejoin",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");this.setStyleProperty("joinstyle",a,b)}}return this};GSVectorGraphics.prototype.getStrokeStyle=function(){return this.style["stroke-style"]};GSVectorGraphics.prototype.setStrokeStyle=function(a){this.style["stroke-style"]=a;return this._setStrokeStyle(a)};GSVectorGraphics.prototype._setStrokeStyle=function(a){if(_browser.svg){if(a=="solid"){this.setStyleProperty("stroke-dasharray","none")}else{this.setStyleProperty("stroke-dasharray",this.style["stroke-width"])}}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"stroke");if(a=="solid"){this.setStyleProperty("stroke-dasharray","1",b)}else{this.setStyleProperty("dashstyle","1 1",b)}}}return this};GSVectorGraphics.prototype.getFill=function(){return this.style.fill};GSVectorGraphics.prototype.setFill=function(a){this.style.fill=a;return this._setFill(a)};GSVectorGraphics.prototype._setFill=function(a){if(_browser.svg){this.setStyleProperty("fill",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"fill");if(a=="none"){this.setStyleProperty("on",false,b)}else{this.setStyleProperty("color",a,b)}}}return this};GSVectorGraphics.prototype.getFillOpacity=function(){return parseFloat(this.style["fill-opacity"])};GSVectorGraphics.prototype.setFillOpacity=function(a){this.style["fill-opacity"]=a;return this._setFillOpacity(a)};GSVectorGraphics.prototype._setFillOpacity=function(a){if(_browser.svg){this.setStyleProperty("fill-opacity",a)}else{if(_browser.isIE6up){var b=this.getChildElement(this.graphicsEl,"fill");this.setStyleProperty("opacity",a,b)}}return this};GSVectorGraphics.prototype.getOpacity=function(){return parseFloat(this.style.opacity)};GSVectorGraphics.prototype.setOpacity=function(a){this.style.opacity=a;return this._setOpacity(a)};GSVectorGraphics.prototype._setOpacity=function(c){if(_browser.svg){this.setStyleProperty("opacity",c)}else{if(_browser.isIE6up){var a=GSUtil.roundNumber(c*this.style["fill-opacity"],2);this._setFillOpacity(a);var b=GSUtil.roundNumber(c*this.style["stroke-opacity"],2);this._setStrokeOpacity(b)}}return this};GSVectorGraphics.prototype.setStyleProperty=function(b,d,c){if(!c){c=this.graphicsEl}var a="";if(_browser.svg){a=c.getAttributeNS(null,b);c.setAttributeNS(null,b,d)}else{if(_browser.isIE6up){a=c.getAttribute(b);c.setAttribute(b,d)}}if(this.onmap){this.map.container.scrollLeft=this.map.container.scrollLeft}this.broadcastMessage("shapeStyleChanged",this,b,a,d)};GSVectorGraphics.prototype.getChildElement=function(c,a){var b=null;if(_browser.svg){b=c.getElementsByTagNameNS(_globals.svgns,a)[0]}else{if(_browser.isIE6up){b=c.getElementsByTagName(a)[0]}}if(!b){if(_browser.svg){b=document.createElementNS(_globals.svgns,a)}else{if(_browser.isIE6up){b=document.createElement(_globals.vmlnsPrefix+":"+a)}}c.appendChild(b)}return b};GSVectorGraphics.prototype.setVisible=function(a){this.visible=a;if(this.graphicsEl){if(_browser.svg){this.graphicsEl.setAttributeNS(null,"visibility",(a===true?"visible":"hidden"))}else{if(_browser.isIE6up){this.graphicsEl.style.visibility=(a===true?"visible":"hidden")}}}if(this.onmap&&this.visible){this.render()}};GSVectorGraphics.prototype.addToLayer=function(a){if(!a.vectorContainer){a.vectorContainer=a.createVectorContainer()}if(_browser.svg){GSUtil.makeUnselectable(this.graphicsEl);GSUtil.makeUnselectable(this.textEl);a.vectorContainer.appendChild(this.graphicsEl);a.vectorContainer.appendChild(this.textEl)}else{if(_browser.isIE6up){if(this.resizeToLayer){this.graphicsEl.style.width=a.map.pxWidth;this.graphicsEl.style.height=a.map.pxHeight;this.graphicsEl.coordsize=a.map.pxWidth+" "+a.map.pxHeight}this.graphicsEl.setAttribute("unselectable","on");this.textEl.setAttribute("unselectable","on");a.vectorContainer.appendChild(this.graphicsEl);this.graphicsEl.appendChild(this.textEl)}}GSVectorGraphics.superClass.addToLayer.call(this,a)};GSVectorGraphics.prototype.render=function(){if(this.text){this.renderText()}};GSVectorGraphics.prototype.mapResized=function(a){if(_browser.isIE6up){if(this.resizeToLayer){this.graphicsEl.style.width=a.pxWidth;this.graphicsEl.style.height=a.pxHeight;this.graphicsEl.coordsize=a.pxWidth+" "+a.pxHeight}}this.render()};GSVectorGraphics.prototype.getInfoWindowOptions=function(){return{title:this.type}};GSVectorGraphics.prototype.remove=function(){if(this.snappable){this.layer.map.removeSnappable(this)}try{if(_browser.svg){this.layer.vectorContainer.removeChild(this.graphicsEl);this.layer.vectorContainer.removeChild(this.textEl)}else{if(_browser.isIE6up){this.graphicsEl.removeChild(this.textEl);this.layer.vectorContainer.removeChild(this.graphicsEl)}}}catch(a){}GSVectorGraphics.superClass.remove.call(this)};if(_browser.isIE6up){document.write('<style type="text/css">v\\:group, v\\:oval, v\\:line, v\\:shape, v\\:rect, v\\:roundrect, v\\:textbox, v\\:stroke, v\\:fill { behavior: url(#default#VML);</style>');(function(){var b=false;for(var a=0;a<document.namespaces.length;a++){if(document.namespaces[a].name=="v"){b=true;break}}if(!b){document.namespaces.add("v","urn:schemas-microsoft-com:vml")}})()}GSUtil.extend(GSPolyline,GSVectorGraphics);function GSPolyline(a){GSPolyline.baseConstructor.apply(this,[a]);this.type="GSPolyline";this.resizeToLayer=true;this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"polyline")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":shape")}}this.points=a.points?a.points:[];this.points.indexOf=function(c){for(var d=0,b=this.length;d<b;d++){if(this[d]==c){return d}}return -1};this.style={fill:"none",stroke:"black","stroke-width":"1px","stroke-opacity":1,"stroke-linejoin":"round"};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSPolyline.prototype.setPoints=function(a){this.points=a;this.render()};GSPolyline.prototype.getPoints=function(){return this.points};GSPolyline.prototype.addPoint=function(a){this.points.push(a);this.render()};GSPolyline.prototype.addPointAt=function(b,a){this.points.splice(a,0,b);this.render()};GSPolyline.prototype.replacePoint=function(b,c){var a=this.points.indexOf(c);this.points.splice(a,1,b);this.render()};GSPolyline.prototype.removePoint=function(a){for(var c=0,b=this.points.length;c<b;c++){if(a.equals(this.points[c])){this.points.splice(c,1);if(this.onmap){this.render()}return true}}return false};GSPolyline.prototype.removePointAt=function(a){this.points.splice(a,1);if(this.onmap){this.render()}return true};GSPolyline.prototype.render=function(){if(this.isVisible()){GSPolyline.superClass.render.call(this);if(this.points){var c=this.translateToMapPoints();if(_browser.svg){this.graphicsEl.setAttributeNS(null,"points",c);this.layer.map.container.scrollLeft=this.layer.map.container.scrollLeft}else{if(_browser.isIE6up){var b=c[0];var a=c[1];c.splice(0,2);var d="m "+b+","+a+" l "+c.join(",")+" e";this.graphicsEl.style.display="none";this.graphicsEl.path=d;this.graphicsEl.style.display=""}}}}};GSPolyline.prototype.translateToMapPoints=function(){var d=[];for(var c=0,b=this.points.length;c<b;c++){var a=this.points[c];var e=this.map.translateToMapCoordinate(a);d.push(Math.round(e.x));d.push(Math.round(e.y))}return d};GSPolyline.prototype.getBounds=function(){var a=GSUtil.getMinimum(GSUtil.getPropertyArray(this.points,"x"));var d=GSUtil.getMinimum(GSUtil.getPropertyArray(this.points,"y"));var c=GSUtil.getMaximum(GSUtil.getPropertyArray(this.points,"x"));var b=GSUtil.getMaximum(GSUtil.getPropertyArray(this.points,"y"));return new GSBounds(a,d,c,b)};GSPolyline.prototype.getInfoWindowPosition=function(){return this.points[Math.round(this.points.length/2)-1]};GSPolyline.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),points:this.getPoints(),visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSPolyline.prototype.toWKT=function(){var d=[];for(var c=0,b=this.points.length;c<b;c++){var a=this.points[c];d.push(a.x+" "+a.y)}return"LINESTRING("+d.join(",")+")"};GSPolyline.prototype.toGML=function(){var d=[];for(var c=0,b=this.points.length;c<b;c++){var a=this.points[c];d.push(a.x+", "+a.y)}var e=[];e.push('<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:27200">');e.push("<gml:coordinates>"+d.join(" ")+"</gml:coordinates>");e.push("</gml:LineString>");return e.join("")};GSPolyline.prototype.clone=function(){var a=new GSPolyline({points:GSUtil.clone(this.points),style:GSUtil.clone(this.style)});return a};GSPolyline.prototype.projectPoint=function(b){var e=null;var a=null;if(this.points.length<2){throw new Exception("Polyline must contain at least two points to project a point onto it.")}for(var d=0,c=this.points.length-1;d<c;d++){var f=this._projectPointOnLineSegment(b,this.points[d],this.points[d+1]);if(e===null||f.distance<e){e=f.distance;a=f;a.start=this.points[d];a.end=this.points[d+1];if(e<=1){break}}}return a};GSPolyline.prototype._projectPointOnLineSegment=function(g,f,d){var b=f.distanceFrom(d);if(b<1){return{distance:g.distanceFrom(f),coordinate:f}}var e=((g.x-f.x)*(d.x-f.x)+(g.y-f.y)*(d.y-f.y))/Math.pow(b,2);if(e<1e-7){return{distance:g.distanceFrom(f),coordinate:f}}if(e>0.9999999){return{distance:g.distanceFrom(d),coordinate:d}}var c=new GSPoint(f.x+e*(d.x-f.x),f.y+e*(d.y-f.y));return{distance:g.distanceFrom(c),coordinate:c}};GSUtil.extend(GSPolygon,GSVectorGraphics);function GSPolygon(a){GSPolygon.baseConstructor.call(this,a);this.type="GSPolygon";this.resizeToLayer=true;this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"polygon")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":shape")}}this.snapHandles=a.snapHandles?a.snapHandles:false;this.handleSelectModifier=a.handleSelectModifier;this.handles=[];this.handles.indexOf=function(c){for(var d=0,b=this.length;d<b;d++){if(this[d]==c){return d}}return -1};this.createHandles(a.points);this.selectedHandles=[];this.style={fill:"white",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style);this.insertHandles=[];this.insertHandles.indexOf=function(c){for(var d=0,b=this.length;d<b;d++){if(this[d]==c){return d}}return -1};this.createInsertHandles();this.editing=false;GSEventManager.bind(this.graphicsEl,"click",this,this.deselectHandles)}GSPolygon.prototype.getPoints=function(){var c=[];for(var b=0,a=this.handles.length;b<a;b++){c.push(this.handles[b].point)}return c};GSPolygon.prototype.getHandles=function(){return this.handles};GSPolygon.prototype.getSelectedHandles=function(){return this.selectedHandles};GSPolygon.prototype.createHandles=function(c){if(c){for(var b=0,a=c.length;b<a;b++){var d=this.createHandle(c[b]);this.handles.push(d)}}};GSPolygon.prototype.removeHandles=function(){for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].remove()}this.handles.length=0};GSPolygon.prototype.createInsertHandles=function(){for(var d=0,a=this.handles.length;d<a;d++){var c=this.handles[d];var b=this.handles[(d+1)%a];var f=this.getIntermediatePoint(c.point,b.point);var e=this.createInsertHandle(f,c,b);this.insertHandles.push(e)}};GSPolygon.prototype.updateInsertHandles=function(){for(var c=0,a=this.handles.length;c<a;c++){var b=this.insertHandles[c];var f=this.handles[c].point;var e=this.handles[(c+1)%a].point;var d=this.getIntermediatePoint(f,e);b.point=d;b.render()}};GSPolygon.prototype.removeInsertHandles=function(){for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].remove()}this.insertHandles.length=0};GSPolygon.prototype.recreateInsertHandles=function(){this.removeInsertHandles();this.createInsertHandles();this.addHandles(this.layer,this.insertHandles);for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].setVisible(true)}};GSPolygon.prototype.isCreating=function(){return this.creating};GSPolygon.prototype.startCreating=function(){if(this.editing){return}for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].setVisible(true)}for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].setVisible(true)}this.editing=true};GSPolygon.prototype.stopEditing=function(){if(!this.editing){return}for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].setVisible(false)}for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].setVisible(false)}this.editing=false};GSPolygon.prototype.isEditing=function(){return this.editing};GSPolygon.prototype.startEditing=function(){if(this.editing){return}for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].setVisible(true)}for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].setVisible(true)}this.editing=true};GSPolygon.prototype.stopEditing=function(){if(!this.editing){return}this.deselectHandles();for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].setVisible(false)}for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].setVisible(false)}this.editing=false};GSPolygon.prototype.showHandles=function(){this.startEditing()};GSPolygon.prototype.addHandles=function(d,c){for(var b=0,a=c.length;b<a;b++){c[b].addToLayer(d)}};GSPolygon.prototype.addPoint=function(a){var b=this.createHandle(a);this.addHandle(b)};GSPolygon.prototype.addPointAt=function(b,a){var c=this.createHandle(b);this.addHandleAt(c,a)};GSPolygon.prototype.replacePoint=function(c,f){var a=0;for(var d=0,b=this.handles.length;d<b;d++){if(handles[d].point.equals(f)){a=d;break}}var e=this.createHandle(c);this.addHandleAt(e,a)};GSPolygon.prototype.createHandle=function(a){var b=new GSHandle({point:a,parent:this,modifierKey:this.handleSelectModifier});b.addListener(this);return b};GSPolygon.prototype.createInsertHandle=function(a,c,b){var d=new GSHandle({isInsertHandle:true,point:a,parent:this,selectable:false,beforeHandle:c,afterHandle:b});d.addListener(this);return d};GSPolygon.prototype.addHandle=function(a){this.handles.push(a);this._addHandle(a)};GSPolygon.prototype.addHandleAt=function(b,a){this.handles.splice(a,0,b);this._addHandle(b)};GSPolygon.prototype.replaceHandle=function(c,b){var a=this.handles.indexOf(b);this.handles.splice(a,1,c);this._addHandle(c)};GSPolygon.prototype.removeHandle=function(c){for(var b=0,a=this.handles.length;b<a;b++){if(c.point.equals(this.handles[b].point)){this.handles.splice(b,1);c.remove();this.recreateInsertHandles();if(this.onmap){this.render()}return true}}return false};GSPolygon.prototype._addHandle=function(a){this.recreateInsertHandles();if(this.onmap){a.addToLayer(this.layer);this.render()}};GSPolygon.prototype.selectHandle=function(d){switch(this.selectedHandles.length){case 0:this.selectedHandles.push(d);return true;case 1:var c=this.selectedHandles[0];for(var b=0,a=this.handles.length;b<a;b++){if(this.handles[b]===d){if((this.handles[b+1]===c)||((b>0)&&this.handles[b-1]===c)||((b===0)&&this.handles[a-1]===c)||((b==a-1)&&this.handles[0]===c)){this.selectedHandles.push(d);return true}}}return false;default:return false}};GSPolygon.prototype.deselectHandle=function(c){for(var b=0,a=this.selectedHandles.length;b<a;b++){if(this.selectedHandles[b].point===c.point){this.selectedHandles.splice(b,1);return true}}return false};GSPolygon.prototype.deselectHandles=function(){for(var b=0,a=this.handles.length;b<a;b++){var c=this.handles[b];c.setStyle(c.style);c.tip.hide();c.selected=false}this.selectedHandles.length=0};GSPolygon.prototype.hideHandles=function(){this.stopEditing()};GSPolygon.prototype.insertPoint=function(){if(this.selectedHandles.length!=2){return false}var f=this.selectedHandles[0].point;var e=this.selectedHandles[1].point;var a=this.getIntermediatePoint(f,e);var d=this.createHandle(a);d.setVisible(true);var c=this.handles.indexOf(this.selectedHandles[0]);var b=this.handles.indexOf(this.selectedHandles[1]);if((c===0||b===0)&&(c===this.handles.length-1||b===this.handles.length-1)){this.addHandle(d)}else{this.addHandleAt(d,Math.min(c,b)+1)}this.deselectHandles();this.render();this.broadcastMessage("shapeGeometryChanged",this);return a};GSPolygon.prototype.removePoint=function(a){for(var c=0,b=this.handles.length;c<b;c++){if(a.equals(this.handles[c].point)){return this.removeHandle(this.handles[c])}}return false};GSPolygon.prototype.removePointAt=function(a){var b=this.handles.splice(a,1)[0];b.remove();this.recreateInsertHandles();if(this.onmap){this.render()}return true};GSPolygon.prototype.setPoints=function(a){this.removeHandles();this.createHandles(a);this.render()};GSPolygon.prototype.addToLayer=function(a){this.addHandles(a,this.handles);this.addHandles(a,this.insertHandles);GSPolygon.superClass.addToLayer.call(this,a)};GSPolygon.prototype.render=function(){if(this.isVisible()){GSPolygon.superClass.render.call(this);if(this.handles){var c=this.translateToMapPoints();if(_browser.svg){this.graphicsEl.setAttributeNS(null,"points",c);this.layer.map.container.scrollLeft=this.layer.map.container.scrollLeft}else{if(_browser.isIE6up){var b=c[0];var a=c[1];c.splice(0,2);var d="m "+b+","+a+" l "+c.join(",")+" x e";this.graphicsEl.style.display="none";this.graphicsEl.path=d;this.graphicsEl.style.display=""}}}}};GSPolygon.prototype.getIntermediatePoint=function(i,h){var d=Math.min(i.x,h.x);var c=Math.min(i.y,h.y);var b=Math.max(i.x,h.x);var a=Math.max(i.y,h.y);var f=d+((b-d)/2);var e=c+((a-c)/2);var g=new GSPoint(f,e);return g};GSPolygon.prototype.translateToMapPoints=function(){var d=[];for(var c=0,b=this.handles.length;c<b;c++){var a=this.handles[c].point;var e=this.map.translateToMapCoordinate(a);d.push(Math.round(e.x));d.push(Math.round(e.y))}return d};GSPolygon.prototype.closestPoint=function(g,f){var b=null;var j=this.getPoints();for(var e=(j.length-1),h=null;h=j[e];e--){var a=this.map.translateToMapCoordinate(h);var d=Math.abs(a.x-g.x);var c=Math.abs(a.y-g.y);if(d<f&&c<f){if(!b||Math.min(d,c)<b.delta){b={point:h,delta:Math.min(d,c)}}}}return b};GSPolygon.prototype.getBounds=function(){var d=[];for(var c=0,b=this.handles.length;c<b;c++){d.push(this.handles[c].point)}var a=GSUtil.getMinimum(GSUtil.getPropertyArray(d,"x"));var g=GSUtil.getMinimum(GSUtil.getPropertyArray(d,"y"));var f=GSUtil.getMaximum(GSUtil.getPropertyArray(d,"x"));var e=GSUtil.getMaximum(GSUtil.getPropertyArray(d,"y"));return new GSBounds(a,g,f,e)};GSPolygon.prototype.getInfoWindowPosition=function(){var d=this.getBounds();var b=d.maxX-d.minX;var c=d.maxY-d.minY;var a=new GSPoint(d.minX+(b/2),d.minY+(c/2));return a};GSPolygon.prototype.remove=function(){for(var b=0,a=this.handles.length;b<a;b++){this.handles[b].remove()}for(var b=0,a=this.insertHandles.length;b<a;b++){this.insertHandles[b].remove()}GSPolygon.superClass.remove.call(this)};GSPolygon.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),points:this.getPoints(),visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSPolygon.prototype.toGML=function(){var e=[];var d=this.getPoints();for(var c=0,b=d.length;c<b;c++){var a=d[c];e.push(a.x+", "+a.y)}var f=[];f.push('<gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:27200">');f.push("<gml:outerBoundaryIs>");f.push("<gml:LinearRing>");f.push("<gml:coordinates>"+e.join(" ")+"</gml:coordinates>");f.push("</gml:LinearRing>");f.push("</gml:outerBoundaryIs>");f.push("</gml:Polygon>");return f.join("")};GSPolygon.prototype.toWKT=function(){var e=[];var d=this.getPoints();for(var c=0,b=d.length;c<b;c++){var a=d[c];e.push(a.x+" "+a.y)}return"POLYGON(("+e.join(",")+"))"};GSPolygon.prototype.handleDragging=function(a){this.render();if(!a.isInsertHandle){this.updateInsertHandles()}};GSPolygon.prototype.handleDragEnd=function(b){if(b.isInsertHandle){var c=this.createHandle(b.point);c.setVisible(true);var a=this.insertHandles.indexOf(b);this.addHandleAt(c,a+1)}else{this.render();this.updateInsertHandles()}this.broadcastMessage("shapeGeometryChanged",this)};GSPolygon.prototype.handleSelected=function(a){this.selectHandle(a)};GSPolygon.prototype.handleMoved=function(a){this.render();this.updateInsertHandles()};GSPolygon.prototype.handleDeselected=function(a){this.deselectHandle(a)};GSPolygon.prototype.pointDeleted=function(a){this.removePoint(a);this.broadcastMessage("shapeGeometryChanged",this)};GSUtil.extend(GSPolygonDrawingHandler,GSDrawingHandler);GSPolygon.drawingHandler=GSPolygonDrawingHandler;function GSPolygonDrawingHandler(b,a){GSPolygonDrawingHandler.baseConstructor.call(this,b,a)}GSPolygonDrawingHandler.prototype.createDrawFeature=function(){this.drawFeature=new GSPolyline({style:this.drawStyle});this.layer.addFeature(this.drawFeature);map.customCursor="crosshair";this.map.setCursor("")};GSPolygonDrawingHandler.prototype.mapClicked=function(b,c,a){if(this.drawing){this.addPoint(this.snapPoint(c))}};GSPolygonDrawingHandler.prototype.addPoint=function(d){if(this.drawing){var a=this;this.updatingLine=false;this.drawFeature.addPoint(d);if(this.drawFeature.getPoints().length==1){this.drawFeature.addPoint(d);var b=new GSIcon();b.imageSrc=GSVectorGraphicsConstants.resourceURL+"close.png";b.imageSize=new GSDimension(15,15);b.iconOffset=new GSPoint(-8,-8);var c={coordinate:d,icon:b};this.closeFeature=new GSPointFeature(c);this.closeFeature.setTip("Click here to close the polygon",{showDelay:0,hideDelay:0});this.closeFeature.addEventHandler("click",GSUtil.bindAsEventListener(function(f){this.stopDrawing();GSUtil.cancelEvent(f)},this));this.layer.addFeature(this.closeFeature)}if(!this.eventListeners.mouseMoveListenerToken){this.eventListeners.mouseMoveListenerToken=GSEventManager.addEventListener(document,"mousemove",GSUtil.bindAsEventListener(this.updateLine,this))}}};GSPolygonDrawingHandler.prototype.updateLine=function(c){var a=this.map.getMouseCoordinate(c);if(!this.updatingLine){this.updatingLine=true}else{var b=this.drawFeature.getPoints();this.drawFeature.removePointAt(b.length-1);this.drawFeature.addPoint(a)}GSUtil.cancelEvent(c)};GSPolygonDrawingHandler.prototype.removeDrawFeature=function(){if(this.drawing){GSEventManager.removeEventListener(this.eventListeners.mouseMoveListenerToken);this.eventListeners.mouseMoveListenerToken=null;this.drawFeature.removePointAt(this.drawFeature.getPoints().length-1);var a=this.drawFeature.getPoints();this.layer.removeFeature(this.drawFeature);this.drawFeature=null;this.layer.removeFeature(this.closeFeature);this.closeFeature=null;map.customCursor=null;map.setCursor();return a}else{throw new Error("GSPolygonDrawingHandler.closePolygon called while not drawing.")}};GSPolygonDrawingHandler.prototype.createViewFeature=function(b){var a=new GSPolygon({points:b,style:this.viewStyle,snapHandles:this.snapHandles});a.snappable=this.snappable;this.layer.addFeature(a);return a};GSUtil.extend(GSCircle,GSVectorGraphics);function GSCircle(a){GSCircle.baseConstructor.apply(this,[a]);this.type="GSCircle";this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"circle")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":oval")}}this.center=a.center?a.center:this.map.getMapCenter();this.radius=a.radius?a.radius:0;this.style={fill:"white",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSCircle.prototype.setCenter=function(a){this.center=a;this.render()};GSCircle.prototype.setRadius=function(a){this.radius=a;this.render()};GSCircle.prototype.render=function(){if(this.isVisible()){GSCircle.superClass.render.call(this);var a=this.map.translateToMapCoordinate(this.center);var b=this.radius/this.map.mpx;if(_browser.svg){this.graphicsEl.setAttributeNS(null,"cx",a.x);this.graphicsEl.setAttributeNS(null,"cy",a.y);this.graphicsEl.setAttributeNS(null,"r",b)}else{if(_browser.isIE6up){this.graphicsEl.style.left=a.x-b;this.graphicsEl.style.top=a.y-b;this.graphicsEl.style.width=b*2;this.graphicsEl.style.height=b*2}}}};GSCircle.prototype.getBounds=function(){var a=this.center.x-this.radius;var d=this.center.y-this.radius;var c=this.center.x+this.radius;var b=this.center.y+this.radius;return new GSBounds(a,d,c,b)};GSCircle.prototype.getInfoWindowPosition=function(){return this.center};GSCircle.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),center:this.center,radius:this.radius,visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSCircle.prototype.toGML=function(){throw new Error("GML output not supported for this shape type")};GSCircle.prototype.toWKT=function(){throw new Error("WKT output not supported for this shape type")};GSUtil.extend(GSEllipse,GSVectorGraphics);function GSEllipse(a){GSEllipse.baseConstructor.apply(this,[a]);this.type="GSEllipse";this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"ellipse")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":oval")}}this.center=a.center?a.center:this.map.getMapCenter();this.rx=a.rx?a.rx:0;this.ry=a.ry?a.ry:0;this.style={fill:"white",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSEllipse.prototype.setCenter=function(a){this.center=a;this.render()};GSEllipse.prototype.setRadii=function(b,a){this.rx=b;this.ry=a;this.render()};GSEllipse.prototype.render=function(){if(this.isVisible()){GSEllipse.superClass.render.call(this);var a=this.map.translateToMapCoordinate(this.center);var c=this.rx/this.map.mpx;var b=this.ry/this.map.mpx;if(_browser.svg){this.graphicsEl.setAttributeNS(null,"cx",a.x);this.graphicsEl.setAttributeNS(null,"cy",a.y);this.graphicsEl.setAttributeNS(null,"rx",c);this.graphicsEl.setAttributeNS(null,"ry",b)}else{if(_browser.isIE6up){this.graphicsEl.style.left=a.x-c;this.graphicsEl.style.top=a.y-b;this.graphicsEl.style.width=c*2;this.graphicsEl.style.height=b*2}}}};GSEllipse.prototype.getBounds=function(){var a=this.center.x-this.rx;var d=this.center.y-this.ry;var c=this.center.x+this.rx;var b=this.center.y+this.ry;return new GSBounds(a,d,c,b)};GSEllipse.prototype.getInfoWindowPosition=function(){return this.center};GSEllipse.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),center:this.center,rx:this.rx,ry:this.ry,visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=this.textStyle;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSEllipse.prototype.toGML=function(){throw new Error("GML output not supported for this shape type")};GSEllipse.prototype.toWKT=function(){throw new Error("WKT output not supported for this shape type")};GSUtil.extend(GSLine,GSVectorGraphics);function GSLine(a){GSLine.baseConstructor.apply(this,[a]);this.type="GSLine";this.resizeToLayer=true;this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"line")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":shape")}}this.from=a.from?a.from:this.map.getMapCenter();this.to=a.to?a.to:this.map.getMapCenter();this.style={fill:"none",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSLine.prototype.setFrom=function(a){this.from=a;this.render()};GSLine.prototype.setTo=function(a){this.to=a;this.render()};GSLine.prototype.render=function(){if(this.isVisible()){GSLine.superClass.render.call(this);var a=this.map.translateToMapCoordinate(this.from);var b=this.map.translateToMapCoordinate(this.to);if(_browser.svg){this.graphicsEl.setAttributeNS(null,"x1",a.x);this.graphicsEl.setAttributeNS(null,"y1",a.y);this.graphicsEl.setAttributeNS(null,"x2",b.x);this.graphicsEl.setAttributeNS(null,"y2",b.y)}else{if(_browser.isIE6up){var c="M "+Math.round(a.x)+" "+Math.round(a.y)+" L "+Math.round(b.x)+" "+Math.round(b.y);this.graphicsEl.style.display="none";this.graphicsEl.path=c;this.graphicsEl.style.display=""}}}};GSLine.prototype.getBounds=function(){var a=Math.min(this.from.x,this.to.x);var d=Math.min(this.from.y,this.to.y);var c=Math.max(this.from.x,this.to.x);var b=Math.max(this.from.y,this.to.y);return new GSBounds(a,d,c,b)};GSLine.prototype.getInfoWindowPosition=function(){var a=Math.min(this.from.x,this.to.x)+Math.abs((this.from.x-this.to.x)/2);var b=Math.min(this.from.y,this.to.y)+Math.abs((this.from.y-this.to.y)/2);return new GSPoint(a,b)};GSLine.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),from:this.from,to:this.to,visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSLine.prototype.toGML=function(){var a=[];a.push('<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:27200">');a.push("<gml:coordinates>"+this.from.x+","+this.from.y+" "+this.to.x+","+this.to.y+"</gml:coordinates>");a.push("</gml:LineString>");return a.join("")};GSLine.prototype.toWKT=function(){return"LINESTRING("+this.from.x+" "+this.from.y+","+this.to.x+" "+this.to.y+")"};GSUtil.extend(GSRect,GSVectorGraphics);function GSRect(a){GSRect.baseConstructor.apply(this,[a]);this.type="GSRect";this.radius=a.radius?a.radius:0;this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"rect")}else{if(_browser.isIE6up){if(this.radius==0){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":rect")}else{this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":roundrect")}}}this.width=a.width?a.width:0;this.height=a.height?a.height:0;this.origin=a.origin?a.origin:this.map.getMapCenter();this.style={fill:"white",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSRect.prototype.setRadius=function(a){this.radius=a;this.render()};GSRect.prototype.setWidth=function(a){this.width=a;this.render()};GSRect.prototype.setHeight=function(a){this.height=a;this.render()};GSRect.prototype.setOrigin=function(a){this.origin=a;this.render()};GSRect.prototype.render=function(){if(this.isVisible()){GSRect.superClass.render.call(this);var h=this.map.translateToMapCoordinate(new GSPoint(this.origin.x,this.origin.y+this.height));var c=this.width/this.map.mpx;var g=this.height/this.map.mpx;var f=this.radius/this.map.mpx;if(_browser.svg){this.graphicsEl.setAttributeNS(null,"x",h.x);this.graphicsEl.setAttributeNS(null,"y",h.y);this.graphicsEl.setAttributeNS(null,"width",c);this.graphicsEl.setAttributeNS(null,"height",g);this.graphicsEl.setAttributeNS(null,"rx",f);this.graphicsEl.setAttributeNS(null,"ry",f)}else{if(_browser.isIE6up){this.graphicsEl.style.left=h.x;this.graphicsEl.style.top=h.y;this.graphicsEl.style.width=c;this.graphicsEl.style.height=g;if(this.radius!=0){var e=Math.min(c,g);var d=e/2;var a=f<=d?f:d;var b=a/e;this.setArcsize(b)}}}}};GSRect.prototype.setArcsize=function(a){var c=this.graphicsEl.nextSibling;var b=this.graphicsEl.parentNode;b.removeChild(this.graphicsEl);this.graphicsEl.setAttribute("arcsize",a);if(c){b.insertBefore(this.graphicsEl,c)}else{b.appendChild(this.graphicsEl)}};GSRect.prototype.getBounds=function(){var a=this.origin.x;var d=this.origin.y;var c=this.origin.x+this.width;var b=this.origin.y+this.height;return new GSBounds(a,d,c,b)};GSRect.prototype.getInfoWindowPosition=function(){var a=this.origin.x+(this.width/2);var b=this.origin.y+(this.height/2);return new GSPoint(a,b)};GSRect.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),origin:this.origin,width:this.width,height:this.height,radius:this.radius,visible:this.visible};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSRect.prototype.toGML=function(){var a=[];a.push(this.origin.x+","+this.origin.y);a.push((this.origin.x+this.width)+","+this.origin.y);a.push(this.origin.x+","+(this.origin.y+this.height));a.push((this.origin.x+this.width)+","+(this.origin.y+this.height));sb.push('<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:27200">');sb.push("<gml:coordinates>"+a.join(" ")+"</gml:coordinates>");sb.push("</gml:LineString>");return sb.join("")};GSRect.prototype.toWKT=function(){var a=[];a.push(this.origin.x+" "+this.origin.y);a.push((this.origin.x+this.width)+" "+this.origin.y);a.push(this.origin.x+" "+(this.origin.y+this.height));a.push((this.origin.x+this.width)+" "+(this.origin.y+this.height));return"LINESTRING("+a.join(",")+")"};GSUtil.extend(GSPath,GSVectorGraphics);function GSPath(a){GSPath.baseConstructor.apply(this,[a]);this.type="GSPath";this.resizeToLayer=true;this.parser=new PathParser();this.coordinateTranslator=new CoordinateTranslator(map);this.coordinateExtractor=new CoordinateExtractor();this.graphicsEl=undefined;if(_browser.svg){this.graphicsEl=document.createElementNS(_globals.svgns,"path")}else{if(_browser.isIE6up){this.graphicsEl=document.createElement(_globals.vmlnsPrefix+":shape")}}this.data=a.data?a.data:[];this.style={fill:"none",stroke:"black","stroke-width":"1px","stroke-opacity":1};GSUtil.merge(a.style,this.style);this.setStyle(this.style)}GSPath.prototype.setData=function(a){this.data=a;this.render()};GSPath.prototype.render=function(){if(this.isVisible()){GSPath.superClass.render.call(this);if(this.data){this.coordinateTranslator.map=this.map;this.parser.setHandler(this.coordinateTranslator);this.parser.parseData(this.data);var c=this.coordinateTranslator.getTranslatedPath();if(_browser.svg){this.graphicsEl.setAttributeNS(null,"d",c)}else{if(_browser.isIE6up){var b=c;b=b.replace(/c/g,"v");b=b.replace(/z/gi,"x");if(b.search(/\./)>-1){pathitems=b.split(/[ ,]/);for(var a=0;a<pathitems.length;a++){if(isNaN(parseFloat(pathitems[a]))==false){pathitems[a]=Math.round(pathitems[a])}}b=pathitems.join(" ")}this.graphicsEl.style.display="none";this.graphicsEl.path=b;this.graphicsEl.style.display=""}}}}};GSPath.prototype.getBounds=function(){var c=this.getCoords();var a=GSUtil.getMinimum(GSUtil.getPropertyArray(c,"x"));var e=GSUtil.getMinimum(GSUtil.getPropertyArray(c,"y"));var d=GSUtil.getMaximum(GSUtil.getPropertyArray(c,"x"));var b=GSUtil.getMaximum(GSUtil.getPropertyArray(c,"y"));return new GSBounds(a,e,d,b)};GSPath.prototype.getInfoWindowPosition=function(){var a=this.getCoords();return a[Math.round(a.length/2)-1]};GSPath.prototype.getCoords=function(){if(!this.coordinateExtractor.coords){this.coordinateExtractor.map=this.map;this.parser.setHandler(this.coordinateExtractor);this.parser.parseData(this.data)}return this.coordinateExtractor.coords};GSPath.prototype.toJson=function(){var a={type:this.type,style:GSUtil.toCC(this.style),data:this.data};if(this.text){a.text=this.text;a.textPosition=this.textPosition;a.textStyle=GSUtil.toCC(this.textStyle)}return GSUtil.objToJson(a)};GSPath.prototype.toGML=function(){if(this.data.search(/[cC]/)!=-1){throw new Error("GML output not supported for paths containing arcs.")}var e=this.getCoords();var d=[];for(var c=0,b=this.c1.length;c<b;c++){var a=this.c1[c];d.push(a.x+", "+a.y)}var f=[];f.push('<gml:LineString xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:27200">');f.push("<gml:coordinates>"+d.join(" ")+"</gml:coordinates>");f.push("</gml:LineString>");return f.join("")};GSPath.prototype.toWKT=function(){if(this.data.search(/[cC]/)!=-1){throw new Error("WKT output not supported for paths containing arcs.")}var e=this.getCoords();var d=[];for(var c=0,b=this.c1.length;c<b;c++){var a=this.c1[c];d.push(a.x+" "+a.y)}return"LINESTRING("+d.join(",")+")"};function CoordinateExtractor(){this.map;this.coords}CoordinateExtractor.prototype.beginParse=function(){this.coords=[]};CoordinateExtractor.prototype.linetoAbs=function(a,b){this.coords.push(new GSPoint(a,b))};CoordinateExtractor.prototype.linetoRel=function(a,c){var b=new GSPoint((a/this.map.mpx),(c/this.map.mpx));this.coords.push(b)};CoordinateExtractor.prototype.movetoAbs=function(a,b){this.coords.push(new GSPoint(a,b))};CoordinateExtractor.prototype.movetoRel=function(a,c){var b=new GSPoint((a/this.map.mpx),(c/this.map.mpx));this.coords.push(b)};CoordinateExtractor.prototype.curvetoCubicAbs=function(c,e,b,d,a,f){this.coords.push(new GSPoint(c,e),new GSPoint(b,d),new GSPoint(a,f))};CoordinateExtractor.prototype.curvetoCubicRel=function(b,i,a,h,j,g){var e=new GSPoint((b/this.map.mpx),(i/this.map.mpx));var d=new GSPoint((a/this.map.mpx),(h/this.map.mpx));var f=new GSPoint((j/this.map.mpx),(g/this.map.mpx));this.coords.push(e,d,f)};function CoordinateTranslator(){this.map;this.tokens}CoordinateTranslator.prototype.beginParse=function(){this.tokens=[]};CoordinateTranslator.prototype.getTranslatedPath=function(){return this.tokens.join(" ")};CoordinateTranslator.prototype.linetoAbs=function(a,c){var b=this.map.translateToMapCoordinate(new GSPoint(a,c));this.tokens.push("L "+b.x+","+b.y)};CoordinateTranslator.prototype.movetoAbs=function(a,c){var b=this.map.translateToMapCoordinate(new GSPoint(a,c));this.tokens.push("M "+b.x+","+b.y)};CoordinateTranslator.prototype.curvetoCubicAbs=function(b,i,a,h,j,g){var e=this.map.translateToMapCoordinate(new GSPoint(b,i));var d=this.map.translateToMapCoordinate(new GSPoint(a,h));var f=this.map.translateToMapCoordinate(new GSPoint(j,g));this.tokens.push("C "+e.x+","+e.y+" "+d.x+","+d.y+" "+f.x+","+f.y)};CoordinateTranslator.prototype.closePath=function(){this.tokens.push("z")};GSUtil.extend(GSHandle,GSMapFeature);function GSHandle(c){GSHandle.baseConstructor.call(this);this.type="GSHandle";this.graphicsEl=GSUtil.createElement("div");this.graphicsEl.style.position="absolute";this.parent=c.parent;this.point=c.point;this.style={width:8,height:8,fill:"white",opacity:0.9,stroke:"black","stroke-width":"1px",cursor:"pointer",fontSize:"1px"};GSUtil.merge(c.style,this.style);this.setStyle(this.style);this.dragStyle={stroke:"aqua",fill:"white",opacity:0.9,cursor:"crosshair"};GSUtil.merge(c.dragStyle,this.dragStyle);this.insertStyle={stroke:"black",fill:"white",opacity:0.5,cursor:"pointer"};GSUtil.merge(c.insertStyle,this.insertStyle);this.beforeHandle=c.beforeHandle;this.afterHandle=c.afterHandle;this.isInsertHandle=c.isInsertHandle!==undefined?c.isInsertHandle:false;if(this.isInsertHandle){this._setStyle(this.insertStyle);this.createDragBoundary();this.disableContextMenu()}else{this.setTip(GSHandle.TOOL_TIP_TEXT,{showDelay:0,hideDelay:0,offset:new GSPoint(20,-10)});var b=GSContextMenuManager.getContextMenu();this.setContextMenu(b);var a=new GSMenuItem("Delete point");a.addEventHandler("click",GSUtil.bindAsEventListener(this.pointDeletedHandler,this));this.addContextMenuItemAt(a,0);if(b.getItems().length){this.addContextMenuItemAt(new GSMenuItem("",{isSeparator:true}),1)}}this.selectedStyle={fill:"aqua",opacity:0.9,stroke:"black"};GSUtil.merge(c.selectedStyle,this.selectedStyle);this.snapStyle={fill:"aqua","fill-opacity":0.9,stroke:"aqua","stroke-opacity":1};GSUtil.merge(c.snapStyle,this.snapStyle);this.visible=c.visible==undefined?false:true;this.setVisible(this.visible);this.draggable=c.draggable!==undefined?c.draggable:true;if(this.draggable){GSEventManager.bind(this.graphicsEl,"mousedown",this,this.dragStart)}this.dragging=false;this.dragStartPoint=null;this.selectable=c.selectable==undefined?true:false;if(this.selectable){GSEventManager.bind(this.graphicsEl,"click",this,this.select)}this.selected=c.selected==undefined?false:true;if(this.selected){this._setStyle(this.selectedStyle);this.broadcastMessage("handleSelected",this)}this.modifierKey=c.modifierKey;if(this.modifierKey){if(this.modifierKey!="none"){this.modifierKey+="Key"}}else{this.modifierKey="altKey"}this.subscribeToKeyEvents()}GSHandle.TOOL_TIP_TEXT="Drag to move point";GSHandle.NUDGE_INCREMENT=1;GSHandle.prototype.subscribeToKeyEvents=function(){this.eventListeners.keydown=GSEventManager.addEventListener(document,"keydown",GSUtil.bindAsEventListener(this.keyHandler,this))};GSHandle.prototype.createDragBoundary=function(){if(_browser.svg){this.dragBoundary=document.createElementNS(_globals.svgns,"polyline");this.dragBoundary.style.display="none";this.dragBoundary.setAttributeNS(null,"stroke","#adadad");this.dragBoundary.setAttributeNS(null,"stroke-width","2px");this.dragBoundary.setAttributeNS(null,"stroke-dasharray","2px,4px");this.dragBoundary.setAttributeNS(null,"fill","none");GSUtil.makeUnselectable(this.dragBoundary)}else{if(_browser.isIE6up){this.dragBoundary=document.createElement(_globals.vmlnsPrefix+":shape");this.dragBoundary.style.display="none";this.dragBoundary.setAttribute("unselectable","on");var b=document.createElement(_globals.vmlnsPrefix+":stroke");b.setAttribute("on","true");b.setAttribute("color",this.parent.style.stroke);b.setAttribute("weight","3px");b.setAttribute("dashstyle","dot");this.dragBoundary.appendChild(b);var a=document.createElement(_globals.vmlnsPrefix+":fill");a.setAttribute("on","false");this.dragBoundary.appendChild(a)}}};GSHandle.prototype.select=function(a){if(this.modifierKey=="none"||a[this.modifierKey]){if(this.selected){this._setStyle(this.style);this.tip.hide();this.selected=false;this.broadcastMessage("handleDeselected",this)}else{this._setStyle(this.selectedStyle);this.selected=true;this.broadcastMessage("handleSelected",this)}}GSUtil.cancelEvent(a)};GSHandle.prototype.dragStart=function(a){this.dragStartPoint=this.map.getMouseCoordinate(a);this._setStyle(this.dragStyle);if(this.isInsertHandle){this.dragBoundary.style.display=""}this.eventListeners.mousemove=GSEventManager.bind(document,"mousemove",this,this.onDrag);this.eventListeners.mouseup=GSEventManager.bind(document,"mouseup",this,this.stopDrag);this.dragging=true;this.broadcastMessage("handleDragStart",this);GSUtil.cancelEvent(a)};GSHandle.prototype.onDrag=function(f){this.point=this.map.getMouseCoordinate(f);this.closest=undefined;if(this.parent.snapHandles){var h=this.map.getSnappables();for(var c=0,b=h.length;c<b;c++){var d=h[c];if(d!==this.parent&&d.isVisible()){var g=this.map.translateToMapCoordinate(this.point);var a=d.closestPoint(g,15);if(a){if(!this.closest||a.delta<this.closest.delta){this.closest=a}}}}}if(this.closest){this._setStyle(this.snapStyle)}else{this._setStyle(this.dragStyle)}if(!this.isInsertHandle){this.tip.setText(this.point.x+", "+this.point.y)}this.render();this.broadcastMessage("handleDragging",this);GSUtil.cancelEvent(f)};GSHandle.prototype.stopDrag=function(a){GSEventManager.release(this.eventListeners.mousemove);delete this.eventListeners.mousemove;GSEventManager.release(this.eventListeners.mouseup);delete this.eventListeners.mouseup;if(this.isInsertHandle){this._setStyle(this.insertStyle);this.dragBoundary.style.display="none"}else{this._setStyle(this.style);this.tip.setText(GSHandle.TOOL_TIP_TEXT)}if(!this.dragStartPoint.equals(this.map.getMouseCoordinate(a))){if(this.closest){this.point=this.closest.point;this.closest=undefined;this.render()}this.broadcastMessage("handleDragEnd",this)}this.dragging=false;GSUtil.cancelEvent(a)};GSHandle.prototype.addToLayer=function(a){a.map.contentContainer.appendChild(this.graphicsEl);if(this.isInsertHandle){if(!a.vectorContainer){a.vectorContainer=a.createVectorContainer()}if(_browser.isIE6up){this.dragBoundary.style.width=a.map.pxWidth;this.dragBoundary.style.height=a.map.pxHeight;this.dragBoundary.coordsize=a.map.pxWidth+" "+a.map.pxHeight}a.vectorContainer.appendChild(this.dragBoundary)}GSHandle.superClass.addToLayer.call(this,a)};GSHandle.prototype.render=function(){if(this.isVisible()){var g=this.map.translateToMapCoordinate(this.point);var a=g.x-this.style.width/2;var f=g.y-this.style.height/2;this.graphicsEl.style.left=a+"px";this.graphicsEl.style.top=f+"px";this.graphicsEl.style.width=this.style.width+"px";this.graphicsEl.style.height=this.style.height+"px";this.graphicsEl.style.zIndex=100;if(this.isInsertHandle&&this.dragging){var d=this.map.translateToMapCoordinate(this.beforeHandle.point);var b=this.map.translateToMapCoordinate(this.afterHandle.point);if(_browser.svg){var c=[d.x,d.y,g.x,g.y,b.x,b.y];this.dragBoundary.setAttributeNS(null,"points",c)}else{if(_browser.isIE6up){var e="m "+Math.round(d.x)+","+Math.round(d.y)+" l "+Math.round(g.x)+", "+Math.round(g.y)+", "+Math.round(b.x)+", "+Math.round(b.y)+" e";this.dragBoundary.style.display="none";this.dragBoundary.path=e;this.dragBoundary.style.display=""}}}}};GSHandle.prototype.setStyle=function(a){for(var c in a){var b=a[c];switch(c){case"stroke":this.setStroke(b);break;case"stroke-width":this.setStrokeWidth(b);break;case"fill":this.setFill(b);break;case"opacity":this.setOpacity(b);break;default:this.graphicsEl.style[c]=b;break}}};GSHandle.prototype._setStyle=function(a){for(var c in a){var b=a[c];switch(c){case"stroke":this._setStroke(b);break;case"stroke-width":this._setStrokeWidth(b);break;case"fill":this._setFill(b);break;case"opacity":this._setOpacity(b);break;default:this.graphicsEl.style[c]=b;break}}};GSHandle.prototype.setStroke=function(a){this.style.stroke=a;return this._setStroke(a)};GSHandle.prototype.setStrokeWidth=function(a){this.style["stroke-width"]=a;return this._setStrokeWidth(a)};GSHandle.prototype.setFill=function(a){this.style.fill=a;return this._setFill(a)};GSHandle.prototype.setOpacity=function(a){this.style.opacity=a;return this._setOpacity(a)};GSHandle.prototype._setStroke=function(a){if(a==="none"){this.graphicsEl.style.borderStyle="none"}else{this.graphicsEl.style.borderStyle="solid";this.graphicsEl.style.borderColor=a}};GSHandle.prototype._setStrokeWidth=function(a){this.graphicsEl.style.borderWidth=a};GSHandle.prototype._setStrokeOpacity=function(a){};GSHandle.prototype._setFill=function(a){if(a==="none"){this.graphicsEl.style.backgroundColor="transparent"}else{this.graphicsEl.style.backgroundColor=a}};GSHandle.prototype._setFillOpacity=function(a){};GSHandle.prototype._setOpacity=function(a){GSUtil.setOpacity(this.graphicsEl,a*100)};GSHandle.prototype.remove=function(){this.map.contentContainer.removeChild(this.graphicsEl);if(this.isInsertHandle){this.layer.vectorContainer.removeChild(this.dragBoundary)}GSHandle.superClass.remove.call(this)};GSHandle.prototype.setVisible=function(a){this.visible=a;if(this.graphicsEl){this.graphicsEl.style.visibility=(a===true?"visible":"hidden")}if(this.onmap&&this.visible){this.render()}};GSHandle.prototype.pointDeletedHandler=function(a){this.contextMenu.hide();this.broadcastMessage("pointDeleted",this.point);GSUtil.cancelEvent(a)};GSHandle.prototype.toString=function(){return"GSHandle: x=["+this.point.x+"], y=["+this.point.y+"]"};GSHandle.prototype.keyHandler=function(b){if(this.selected){var a=GSHandle.NUDGE_INCREMENT*this.map.mpx;switch(b.keyCode){case GSKeyEvents.KEY_LEFT:this.point=new GSPoint(this.point.x-a,this.point.y);break;case GSKeyEvents.KEY_RIGHT:this.point=new GSPoint(this.point.x+a,this.point.y);break;case GSKeyEvents.KEY_UP:this.point=new GSPoint(this.point.x,this.point.y+a);break;case GSKeyEvents.KEY_DOWN:this.point=new GSPoint(this.point.x,this.point.y-a);break}this.render();this.tip.setText(this.point.x+", "+this.point.y);this.tip.show();this.broadcastMessage("handleMoved",this)}};Svg.VERSION=1;Svg.NAMESPACE="http://www.w3.org/2000/svg";function Svg(){}PathParser.PARAMCOUNT={A:7,C:6,H:1,L:2,M:2,Q:4,S:4,T:2,V:1,Z:0};PathParser.METHODNAME={A:"arcAbs",a:"arcRel",C:"curvetoCubicAbs",c:"curvetoCubicRel",H:"linetoHorizontalAbs",h:"linetoHorizontalRel",L:"linetoAbs",l:"linetoRel",M:"movetoAbs",m:"movetoRel",Q:"curvetoQuadraticAbs",q:"curvetoQuadraticRel",S:"curvetoCubicSmoothAbs",s:"curvetoCubicSmoothRel",T:"curvetoQuadraticSmoothAbs",t:"curvetoQuadraticSmoothRel",V:"linetoVerticalAbs",v:"linetoVerticalRel",Z:"closePath",z:"closePath"};function PathParser(){this._lexer=new PathLexer();this._handler=null}PathParser.prototype.parsePath=function(a){if(a==null||a.namespaceURI!=Svg.NAMESPACE||a.localName!="path"){throw new Error("PathParser.parsePath: The first parameter must be an SVG path element")}this.parseData(a.getAttributeNS(null,"d"))};PathParser.prototype.parseData=function(h){if(typeof(h)!="string"){throw new Error("PathParser.parseData: The first parameter must be a string")}if(this._handler!=null&&this._handler.beginParse!=null){this._handler.beginParse()}var c=this._lexer;c.setPathData(h);var g="BOP";var d=c.getNextToken();while(!d.typeis(PathToken.EOD)){var b;var e=new Array();switch(d.type){case PathToken.COMMAND:if(g=="BOP"&&d.text!="M"&&d.text!="m"){throw new Error("PathParser.parseData: a path must begin with a moveto command")}g=d.text;b=PathParser.PARAMCOUNT[d.text.toUpperCase()];d=c.getNextToken();break;case PathToken.NUMBER:break;default:throw new Error("PathParser.parseData: unrecognized token type: "+d.type)}for(var f=0;f<b;f++){switch(d.type){case PathToken.COMMAND:throw new Error("PathParser.parseData: parameter must be a number: "+d.text);case PathToken.NUMBER:e[f]=d.text-0;break;default:throw new Error("PathParser.parseData: unrecognized token type: "+d.type)}d=c.getNextToken()}if(this._handler!=null){var j=this._handler;var a=PathParser.METHODNAME[g];if(j[a]!=null){j[a].apply(j,e)}}if(g=="M"){g="L"}if(g=="m"){g="l"}}};PathParser.prototype.setHandler=function(a){this._handler=a};PathLexer.VERSION=1;function PathLexer(a){if(a==null){a=""}this.setPathData(a)}PathLexer.prototype.setPathData=function(a){if(typeof(a)!="string"){throw new Error("PathLexer.setPathData: The first parameter must be a string")}this._pathData=a};PathLexer.prototype.getNextToken=function(){var a=null;var b=this._pathData;while(a==null){if(b==null||b==""){a=new PathToken(PathToken.EOD,"")}else{if(b.match(/^([ \t\r\n,]+)/)){b=b.substr(RegExp.$1.length)}else{if(b.match(/^([AaCcHhLlMmQqSsTtVvZz])/)){a=new PathToken(PathToken.COMMAND,RegExp.$1);b=b.substr(RegExp.$1.length)}else{if(b.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/)){a=new PathToken(PathToken.NUMBER,parseFloat(RegExp.$1));b=b.substr(RegExp.$1.length)}else{throw new Error("PathLexer.getNextToken: unrecognized path data "+b)}}}}}this._pathData=b;return a};PathToken.UNDEFINED=0;PathToken.COMMAND=1;PathToken.NUMBER=2;PathToken.EOD=3;function PathToken(a,b){if(arguments.length>0){this.init(a,b)}}PathToken.prototype.init=function(a,b){this.type=a;this.text=b};PathToken.prototype.typeis=function(a){return this.type==a};function GSDrawingHandler(b,a){this.layer=b;this.map=b.map;this.eventListeners={};this.drawStyle={fill:"white","fill-opacity":0.4,stroke:"black","stroke-width":"1px","stroke-opacity":1};if(a.drawStyle){this.drawStyle=GSUtil.merge(a.drawStyle,this.drawStyle)}this.viewStyle={fill:"white",stroke:"black","stroke-width":"1px","stroke-opacity":1};if(a.viewStyle){this.viewStyle=GSUtil.merge(a.viewStyle,this.viewStyle)}this.drawing=false;this.onShapeCreated=function(){};if(a.onShapeCreated){this.onShapeCreated=a.onShapeCreated}this.onDrawingCancelled=function(){};if(a.onDrawingCancelled){this.onDrawingCancelled=a.onDrawingCancelled}this.snappable=(a.snappable==true);this.snapHandles=(a.snapHandles==true);this.map.addListener(this)}GSDrawingHandler.prototype.startDrawing=function(){if(!this.drawing){this.drawing=true;this.createDrawFeature();if(!this.eventListeners.keydownListenerToken){this.eventListeners.keydownListenerToken=GSEventManager.addEventListener(document,"keydown",GSUtil.bindAsEventListener(this.keyHandler,this))}}};GSDrawingHandler.prototype.stopDrawing=function(){if(this.drawing){var a=this.removeDrawFeature();this.drawing=false;this.viewFeature=this.createViewFeature(a);if(this.viewFeature!==null){this.onShapeCreated(this.viewFeature)}GSEventManager.removeEventListener(this.eventListeners.keydownListenerToken);this.eventListeners.keydownListenerToken=null}};GSDrawingHandler.prototype.createDrawFeature=function(){};GSDrawingHandler.prototype.removeDrawFeature=function(){};GSDrawingHandler.prototype.createViewFeature=function(){};GSDrawingHandler.prototype.snapPoint=function(b){var d=this.map.translateToMapCoordinate(b);var f=this.map.getSnappables();var e=null;for(var c=0;c<f.length;c++){if(f[c].isVisible()){var a=f[c].closestPoint(d,15);if(a){if(!e||a.delta<e.delta){e=a}}}}if(e){return e.point}return b};GSDrawingHandler.prototype.keyHandler=function(a){if(a.keyCode==GSKeyEvents.KEY_ESC){this.removeDrawFeature();this.drawing=false;if(this.onDrawingCancelled){this.onDrawingCancelled()}}};function GSMultiLevelPolyline(a){if(!a){a={}}this.type="GSMultiLevelPolyline";this.levelPoints=a.levelPoints?a.levelPoints:[];this.levelPolylines=[];this.style=a.style?a.style:{};this.layer=null;this.map=null;this.currentVisiblePolyline=null;this.createLevelPolylines()}GSMultiLevelPolyline.getLevelPoints=function(f,h){var e=[];var d,c,b,a;var g=4;for(d=0,a=g;d<a;d++){e[d]=[]}for(d=0,a=f.length;d<a;d++){for(c=0,b=h[d];c<=b;c++){e[c].push(f[d])}}return e};GSMultiLevelPolyline.prototype.createLevelPolylines=function(){if(this.levelPoints.length){this.removePolylines();for(var b=0,a=this.levelPoints.length;b<a;b++){this.levelPolylines[b]=new GSPolyline({points:this.levelPoints[b],style:this.style});this.levelPolylines[b].setVisible(false)}}};GSMultiLevelPolyline.prototype.addPolylinesToLayer=function(a){this.layer=a;this.map=this.layer.map;this.map.addListener(this);this.updateVisiblePolyline()};GSMultiLevelPolyline.prototype.updateVisiblePolyline=function(){if(this.map!==null){var a=Math.floor((15-this.map.getZoomLevel())/3);if(a<0){a=0}else{if(a>3){a=3}}if(a!=this.currentVisiblePolyline){if(this.currentVisiblePolyline!==null){if(this.levelPolylines[this.currentVisiblePolyline].graphicsEl){this.levelPolylines[this.currentVisiblePolyline].setVisible(false)}else{this.removePolylines();return}}this.currentVisiblePolyline=a;if(!this.levelPolylines[this.currentVisiblePolyline]){console.log("No polyline for level "+this.currentVisiblePolyline)}if(this.levelPolylines[this.currentVisiblePolyline].graphicsEl){if(!this.levelPolylines[this.currentVisiblePolyline].layer){this.layer.addFeature(this.levelPolylines[this.currentVisiblePolyline])}else{this.levelPolylines[this.currentVisiblePolyline].setVisible(true)}}else{this.removePolylines();return}}}};GSMultiLevelPolyline.prototype.mapBoundsChanged=function(c,a,b){this.updateVisiblePolyline()};GSMultiLevelPolyline.prototype.mapZoomed=function(c,b,a){this.updateVisiblePolyline()};GSMultiLevelPolyline.prototype.removePolylines=function(){if(this.levelPolylines.length){for(var b=0,a=this.levelPolylines.length;b<a;b++){if(this.levelPolylines[b].graphicsEl){this.layer.removeFeature(this.levelPolylines[b])}}}this.levelPolylines=[];if(this.map){this.map.removeListener(this);this.map=null;this.layer=null}};GSMultiLevelPolyline.prototype.projectPoint=function(a){if(this.levelPolylines[this.currentVisiblePolyline]){return this.levelPolylines[this.currentVisiblePolyline].projectPoint(a)}return null};GSMultiLevelPolyline.prototype.addEventHandler=function(c,d){for(var b=0,a=this.levelPolylines.length;b<a;b++){this.levelPolylines[b].addEventHandler(c,d)}};GSMultiLevelPolyline.prototype.clone=function(){var a=new GSMultiLevelPolyline({style:GSUtil.clone(this.style),levelPoints:this.levelPoints});return a};