dojo.require("esri.map");dojo.require("esri.toolbars.draw");dojo.require("esri.layers.FeatureLayer");dojo.require("esri.tasks.geometry");TmapyExtension=function(){};TmapyExtension.prototype={map:null,draw:null,baseLayers:[],dynamicLayer:null,geometryService:null,selectionBorder:null,selectionShape:null,symbols:{drawing:{point:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE,10,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([255,0,0]),1),new dojo.Color([0,255,0,0.25])),polyline:new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH,new dojo.Color([255,0,0]),3),polygon:new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH,new dojo.Color([255,0,0,0.5]),2),new dojo.Color([255,255,0,0.3])),multipoint:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,20,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH,new dojo.Color([0,0,0]),1),new dojo.Color([255,255,0,0.5]))},selection:{point:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE,10,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([255,0,0]),1),new dojo.Color([0,255,0,0.25])),polyline:new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([255,0,0]),3),polygon:new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([255,0,0,0.5]),2),new dojo.Color([255,255,0,0.3])),multipoint:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,20,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,0]),1),new dojo.Color([255,255,0,0.5]))},blink:{point:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE,20,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,255]),1),new dojo.Color([0,0,255,0.25])),polyline:new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,255]),3),polygon:new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,255]),2),new dojo.Color([0,0,255,0.3])),multipoint:new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND,20,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,new dojo.Color([0,0,0]),1),new dojo.Color([0,0,255,0.5]))}},blinkParams:{shape:null,interval:null,delay:200,amount:5,counter:0,stayVisible:false,isBlinking:false},baseLayer:function(_1){for(var i=0;i<this.baseLayers.length;i++){var _2=this.baseLayers[i];if(_2.tmapyId==_1){if(!_2.visible){_2.show();}}else{if(_2.visible){_2.hide();}}}},drawingOn:function(_3){if(!this.map){return false;}if(!_3){_3="POLYGON";}this.map.hideZoomSlider();this.clearDrawing();var _4,_5;switch(_3){case "POINT":_4=this.symbols.drawing.point;_5=esri.toolbars.Draw.POINT;break;case "LINE":_4=this.symbols.drawing.polyline;_5=esri.toolbars.Draw.LINE;break;case "POLYLINE":_4=this.symbols.drawing.polyline;_5=esri.toolbars.Draw.POLYLINE;break;case "POLYGON":_4=this.symbols.drawing.polygon;_5=esri.toolbars.Draw.POLYGON;break;case "EXTENT":case "RECT":_4=this.symbols.drawing.polygon;_5=esri.toolbars.Draw.EXTENT;break;case "FREEHAND_POLYGON":_4=this.symbols.drawing.polygon;_5=esri.toolbars.Draw.FREEHAND_POLYGON;break;case "FREEHAND_POLYLINE":_4=this.symbols.drawing.polyline;_5=esri.toolbars.Draw.FREEHAND_POLYLINE;break;default:_4=this.symbols.drawing.polygon;_5=esri.toolbars.Draw.POLYGON;break;}this.draw.setFillSymbol(_4);this.draw.activate(_5);this.draw.active=true;},drawingOff:function(){if(this.draw){this.draw.deactivate();this.draw.active=false;this.map.showZoomSlider();}},clearDrawing:function(){this.map.graphics.clear();if(this.blinkParams.isBlinking){this.blinkParams.shape=null;}},drawWkt:function(_6,_7){var _8=this.wktToGeometry(_6);if(_8){if(_7){if(_8.type=="point"){var _9=new esri.geometry.Extent();var _a=100;_9.xmin=_8.x-_a;_9.ymin=_8.y-_a;_9.xmax=_8.x+_a;_9.ymax=_8.y+_a;this.map.setExtent(_9);}else{if(_8.getExtent){this.map.setExtent(_8.getExtent().expand(1.25));}}}this.clearDrawing();this.addShapeToMap(_8,this.symbols.selection);}},getDrawingWkt:function(){var _b=this.getDrawnGeometry();var _c="";if(_b){switch(_b.type){case "extent":_c=this.extentGeometryToWkt(_b);break;case "polygon":_c=this.polygonGeometryToWkt(_b);break;default:break;}}return _c;},getDrawingArea:function(){var _d=this.getDrawnGeometry();var _e=0;if(_d){switch(_d.type){case "extent":_e=this.getExtentGeometryArea(_d);break;case "polygon":_e=this.getPolygonGeometryArea(_d);break;default:break;}}_e=Math.round(_e*100)/100;return _e;},fullExtent:function(){for(var i=0;i<this.baseLayers.length;i++){var _f=this.baseLayers[i];if(_f.visible){this.map.setExtent(_f.initialExtent);break;}}},getExtent:function(){var _10=[];if(this.map.extent){_10.push(this.map.extent.xmin);_10.push(this.map.extent.ymin);_10.push(this.map.extent.xmax);_10.push(this.map.extent.ymax);}return _10;},setExtent:function(_11){if(_11&&_11.length==4){this.map.setExtent(new esri.geometry.Extent(_11[0],_11[1],_11[2],_11[3]));}},blink:function(wkt,_12,_13,_14){if(this.blinkParams.isBlinking){return false;}var _15=this.wktToGeometry(wkt);if(_15){if(_13){if(_15.type=="point"){var _16=new esri.geometry.Extent();var _17=100;_16.xmin=_15.x-_17;_16.ymin=_15.y-_17;_16.xmax=_15.x+_17;_16.ymax=_15.y+_17;this.map.setExtent(_16);}else{if(_15.getExtent){this.map.setExtent(_15.getExtent().expand(1.25));}}}if(this.blinkParams.shape){this.map.graphics.remove(this.blinkParams.shape);}this.blinkParams.shape=this.addShapeToMap(_15,this.symbols.blink);if(this.blinkParams.shape){if(_12){this.blinkParams.amount=Math.floor(_12/this.blinkParams.delay);}this.blinkParams.counter=0;this.blinkParams.stayVisible=_14;this.blinkParams.isBlinking=true;this.blinkParams.interval=window.setInterval(dojo.hitch(this,function(){this.justBlinkShape();}),this.blinkParams.delay);}}},addToSelection:function(_18,_19,_1a){var _1b=false;var _1c=this.dynamicLayer;if(_1c){if(_1c.layerInfos&&_1c.layerInfos[_18]){var _1d=_1c.layerDefinitions?_1c.layerDefinitions:[];var _1e=[_19];if(_1d[_18]){var _1f=_1d[_18].split(" OR ");for(var i=0;i<_1f.length;i++){if(_1f[i]!=_19){_1e.push(_1f[i]);}}}_1d[_18]=_1e.join(" OR ");if(_1a){var _20=new esri.tasks.QueryTask(this.dynamicLayer.url+"/"+_18);var _21=new esri.tasks.Query();_21.returnGeometry=true;_21.outFields=[];_21.where=_1d[_18];dojo.connect(_20,"onComplete",this,"moveToFeatureset");_20.execute(_21);}if(_1c.setLayerDefinitions){_1c.setLayerDefinitions(_1d);this.setLayerVisibility(_1c,_18,true);if(!_1c.visible){_1c.show();}_1b=true;}}}return _1b;},removeFromSelection:function(_22,_23,_24){var _25=false;var _26=this.dynamicLayer;if(_26){if(_26.layerInfos&&_26.layerInfos[_22]){var _27=_26.layerDefinitions?_26.layerDefinitions:[];if(_27[_22]){var _28=_27[_22].split(" OR ");var _29=[];for(var i=0;i<_28.length;i++){if(_28[i]!=_23){_29.push(_28[i]);}}_27[_22]=_29.join(" OR ");if(_29.length==0){this.setLayerVisibility(_26,_22,false);_25=true;}else{if(_24){var _2a=new esri.tasks.QueryTask(this.dynamicLayer.url+"/"+_22);var _2b=new esri.tasks.Query();_2b.returnGeometry=true;_2b.outFields=[];_2b.where=_27[_22];dojo.connect(_2a,"onComplete",this,"moveToFeatureset");_2a.execute(_2b);}if(_26.setLayerDefinitions){_26.setLayerDefinitions(_27);this.setLayerVisibility(_26,_22,true);if(!_26.visible){_26.show();}_25=true;}}}}}return _25;},clearSelection:function(){this.clearDrawing();var _2c=false;var _2d=this.dynamicLayer;if(_2d){_2d.setVisibleLayers([]);_2d.setLayerDefinitions([]);_2d.hide();}return _2c;},checkSelectionBorder:function(){if(this.selectionShape.geometry){var _2e=new esri.tasks.Query();_2e.geometry=this.selectionShape.geometry;_2e.spatialRelationship=esri.tasks.Query.SPATIAL_REL_WITHIN;this.selectionBorder.selectFeatures(_2e,esri.layers.FeatureLayer.SELECTION_NEW);}},setMap:function(_2f){this.map=_2f;this.draw=new esri.toolbars.Draw(this.map);dojo.connect(this.draw,"onDrawEnd",this,"addSelectionShapeToMap");dojo.connect(this.selectionBorder,"onSelectionComplete",this,"onSelectionBorderComplete");dojo.connect(this.geometryService,"onIntersectComplete",this,"onSelectionIntersectComplete");},setBaseLayers:function(_30){for(var i=0;i<_30.length;i++){_30[i].visible=false;this.map.addLayer(_30[i]);}this.baseLayers=_30;},setDynamicLayer:function(_31){_31.setVisibleLayers([]);this.dynamicLayer=_31;this.map.addLayer(_31);},addShapeToMap:function(_32,_33){if(typeof _33=="undefined"){var _33=this.symbols.selection;}var _34;switch(_32.type){case "point":_34=_33.point;break;case "polyline":_34=_33.polyline;break;case "polygon":_34=_33.polygon;break;case "extent":_34=_33.polygon;break;}var _35=new esri.Graphic(_32,_34);this.map.graphics.add(_35);this.drawingOff();return _35;},addSelectionShapeToMap:function(_36,_37){if(typeof _37=="undefined"){var _37=this.symbols.selection;}var _38;switch(_36.type){case "point":_38=_37.point;break;case "polyline":_38=_37.polyline;break;case "polygon":_38=_37.polygon;break;case "extent":_38=_37.polygon;break;}this.selectionShape=new esri.Graphic(_36,_38);this.map.graphics.add(this.selectionShape);this.drawingOff();},onSelectionBorderComplete:function(_39){if(this.selectionShape.geometry){if(_39.length>0){this.onSelectionBorderIn();}else{var _3a=new esri.tasks.Query();_3a.geometry=this.selectionShape.geometry;_3a.spatialRelationship=esri.tasks.Query.SPATIAL_REL_INTERSECT;_3a.returnGeometry=true;var _3b=new esri.tasks.QueryTask("http://wgp.urm.cz/ArcGIS/rest/services/APP_Vyhledavani/vyhledavani/MapServer/6");var ext=this;_3b.execute(_3a,function(_3c){if(_3c.features.length>0){ext.onSelectionIntersectStart();ext.geometryService.intersect([_3c.features[0].geometry],ext.selectionShape.geometry);}else{ext.onSelectionBorderOut();}});}}},onSelectionIntersectStart:function(){},onSelectionIntersectComplete:function(_3d){if(_3d.length>0){this.map.graphics.clear();this.selectionShape.setGeometry(_3d[0]);this.map.graphics.add(this.selectionShape);}},onSelectionBorderIn:function(){},onSelectionBorderOut:function(){},getDrawnGeometry:function(){var _3e=false;var _3f=this.map.graphics.graphics[0];if(_3f){if(_3f.geometry&&(_3f.geometry.type=="polygon"||_3f.geometry.type=="extent")){_3e=this.map.graphics.graphics[0].geometry;}}return _3e;},wktToGeometry:function(wkt){var _40=wkt.indexOf("(");var _41=wkt.substring(0,_40).replace(/\s*$/,"");var _42=false;switch(_41){case "EXTENT":_42=this.wktToExtentGeometry(wkt);break;case "POLYGON":_42=this.wktToPolygonGeometry(wkt);break;case "POLYLINE":_42=this.wktToPolylineGeometry(wkt);break;case "POINT":_42=this.wktToPointGeometry(wkt);break;default:break;}return _42;},polygonGeometryToWkt:function(_43){var _44=[];if(_43.rings[0]){for(var i=0;i<_43.rings[0].length;i++){var x=Math.round(_43.rings[0][i][0]*100)/100;var y=Math.round(_43.rings[0][i][1]*100)/100;_44.push(x+" "+y);}}var wkt="POLYGON(("+_44.join(",")+"))";return wkt;},extentGeometryToWkt:function(_45){var _46=[];var x,y;for(var i=0;i<5;i++){if(i==1||i==2){x=_45.xmax;}else{x=_45.xmin;}if(i==2||i==3){y=_45.ymax;}else{y=_45.ymin;}_46.push((Math.round(x*100)/100)+" "+(Math.round(y*100)/100));}var wkt="POLYGON(("+_46.join(",")+"))";return wkt;},wktToPolygonGeometry:function(wkt){var _47=wkt.indexOf("((");var _48=wkt.substring(_47+2).replace(/\s*$/,"").replace(/^\s*/,"").replace(/\)*$/,"").replace(/\(*$/,"").split(",");var _49=[];for(var i=0;i<_48.length;i++){var _4a=_48[i].replace(/\s*$/,"").replace(/^\s*/,"").split(" ");_49.push([Math.round(_4a[0]*100)/100,Math.round(_4a[1]*100)/100]);}var _4b=new esri.geometry.Polygon();_4b.addRing(_49);return _4b;},wktToExtentGeometry:function(wkt){var _4c=new esri.geometry.Extent();var _4d=wkt.indexOf("((");var _4e=wkt.substring(_4d+2).replace(/\s*$/,"").replace(/^\s*/,"").replace(/\)*$/,"").replace(/\(*$/,"").split(",");if(_4e.length==5){var x,y,_4f,_50,_51,_52;for(var i=0;i<5;i++){var _53=_4e[i].replace(/\s*$/,"").split(" ");var x=Math.round(_53[0]*100)/100;var y=Math.round(_53[1]*100)/100;if(i==0){_4f=x;_50=y;_51=x;_52=y;}else{if(x<_4f){_4f=x;}else{if(x>_51){_51=x;}}if(y<_50){_50=y;}else{if(y>_52){_52=y;}}}}_4c.xmin=_4f;_4c.ymin=_50;_4c.xmax=_51;_4c.ymax=_52;}return _4c;},wktToPolylineGeometry:function(wkt){var _54=wkt.indexOf("((");var _55=wkt.substring(_54+2).replace(/\s*$/,"").replace(/^\s*/,"").replace(/\)*$/,"").replace(/\(*$/,"").split(",");var _56=[];for(var i=0;i<_55.length;i++){var _57=_55[i].replace(/\s*$/,"").split(" ");_56.push([Math.round(_57[0]*100)/100,Math.round(_57[1]*100)/100]);}var _58=new esri.geometry.Polyline();_58.addPath(_56);return _58;},wktToPointGeometry:function(wkt){var _59=wkt.indexOf("(");var _5a=wkt.substring(_59+1).replace(/\s*$/,"").replace(/^\s*/,"").replace(/\)*$/,"").replace(/\(*$/,"").split(" ");var _5b=new esri.geometry.Point(Math.round(_5a[0]*100)/100,Math.round(_5a[1]*100)/100);return _5b;},getExtentGeometryArea:function(_5c){var _5d=(_5c.xmax-_5c.xmin)*(_5c.ymax-_5c.ymin);return _5d;},getPolygonGeometryArea:function(_5e){var _5f=0;var _60=_5e.rings[0];if(_60){var _61=0;for(var i=0;i<_60.length-1;i++){var x=_60[i][0];var y=_60[i][1];var _62=_60[i+1][0];var _63=_60[i+1][1];_61+=(x*_63-y*_62);}_5f=Math.abs(-_61/2);}return _5f;},justBlinkShape:function(){this.blinkParams.counter++;if(this.blinkParams.shape){if(this.blinkParams.interval&&this.blinkParams.counter>=(this.blinkParams.amount)){window.clearInterval(this.blinkParams.interval);if(this.blinkParams.stayVisible){this.blinkParams.shape.show();}else{this.map.graphics.remove(this.blinkParams.shape);}this.blinkParams.isBlinking=false;}else{if(this.blinkParams.counter%2){this.blinkParams.shape.hide();}else{this.blinkParams.shape.show();}}}else{if(this.blinkParams.interval){window.clearInterval(this.blinkParams.interval);}this.blinkParams.isBlinking=false;}},filterLayerByAttr:function(_64,_65,_66){var _67=false;if(_64.layerInfos&&_64.layerInfos[_65]){var _68=[];_68[_65]=_66;if(_64.setLayerDefinitions){_64.setLayerDefinitions(_68);_67=true;}}return _67;},moveToFeatureset:function(_69){if(_69.features){var _6a=false;for(var i=0;i<_69.features.length;i++){var _6b=_69.features[i].geometry;var _6c={};if(_6b.type=="point"){var _6d=_6b.x-50;var _6e=_6b.y-50;var _6f=_6b.x+50;var _70=_6b.x+50;_6c=new esri.geometry.Extent(_6d,_6e,_6f,_70);}else{if(_6b.getExtent){_6c=_6b.getExtent();}}if(!_6a){_6a=_6c;}else{if(_6c.xmin<_6a.xmin){_6a.xmin=_6c.xmin;}if(_6c.ymin<_6a.ymin){_6a.ymin=_6c.ymin;}if(_6c.xmax>_6a.xmax){_6a.xmax=_6c.xmax;}if(_6c.ymax>_6a.ymax){_6a.ymax=_6c.ymax;}}}if(_6a){this.map.setExtent(_6a.expand(1.25));}}},setLayerVisibility:function(_71,_72,_73){var _74=false;if(typeof _71!="undefined"&&typeof _72!="undefined"&&typeof _73!="undefined"&&_71.layerInfos&&_71.layerInfos[_72]){var _75=[];if(_73){_75=[_72];for(var i=0;i<_71.visibleLayers.length;i++){if(_71.visibleLayers[i]!=_72){_75.push(_71.visibleLayers[i]);}}}else{for(var i=0;i<_71.visibleLayers.length;i++){if(_72!=_71.visibleLayers[i]){_75.push(_71.visibleLayers[i]);}}}_71.setVisibleLayers(_75);_74=true;}return _74;}};
