function GmlReports(map){this.map=map;this.layer=null;this.selector=null;this.pointStyle=new Object();this.pointStyle.externalGraphic='/images/marker_red.png';this.pointStyle.pointRadius=30;this.selectedPointStyle=new Object();this.selectedPointStyle.externalGraphic='/images/marker_red.png';this.selectedPointStyle.pointRadius=36;this.selectedPointStyle.fillOpacity=0.6;this.enabled=false;this.setMode=function(enabled){this.enabled=enabled;if(this.selector){if(enabled)this.selector.activate();else this.selector.deactivate();}}
var objRef=this;this.createSuccess=function(responseText){var jsonReply=eval("("+responseText+")");if(!jsonReply.reply.error){$('#create_status').text('הכביש נוצר בהצלחה!');config.objects.mainMap.callListeners("refreshWmsLayers");}else{$('#create_status').text('שגיאה: '+jsonReply.reply.message);}}
this.createError=function(){$('#create_status').text('שגיאה: לא ניתן לשלוח בקשה לשרת.');}
this.createSegment=function(objRef,id){var params="report_id="+objRef.report_id+"&segment_id="+id;$('#create_status').text('אנא המתן...');$.ajax({type:'POST',url:'/map_edit/reports_create_seg.php',data:params,success:objRef.createSuccess.bind(objRef),error:objRef.createError.bind(objRef)});}
this.onClick=function(evt){var feature=this;var isSegment=false;if(feature.geometry.CLASS_NAME.indexOf('LineString')>-1)
isSegment=true;var lonlat=feature.layer.map.getLonLatFromPixel(evt.xy);var info="<p><b>";if(feature.attributes['name'])
info+="רחוב: "+feature.attributes['name'];if(feature.attributes['start_time'])
info+="<br>שעת התחלה: "+feature.attributes['start_time'];if(feature.attributes['end_time'])
info+="<br>שעת סיום: "+feature.attributes['end_time'];if(feature.attributes['length'])
info+="<br>אורך: "+feature.attributes['length']+" מ'";if(feature.attributes['speed'])
info+="<br>מהירות: "+feature.attributes['speed']+" קמ\"ש";if(feature.attributes['info'])
info+="<br>סוג: "+feature.attributes['info'];if(feature.attributes['description'])
info+="<br>מידע: "+feature.attributes['description'];if(isSegment)
info+="<br><span id=\"create_status\"><a id=\"reportCreateSeg\" href=\"#\">צור כביש חדש בקטע זה</a></span>";info+="</b></p>";var popup=new OpenLayers.Popup(null,lonlat,new OpenLayers.Size(200,200),info,true);popup.setOpacity(0.9);feature.layer.map.addPopup(popup,true);OpenLayers.Event.stop(evt);if(isSegment){$("#reportCreateSeg").click(function(){objRef.createSegment(objRef,feature.attributes['id']);return false;});}}
this.onSelect=function(objRef,feature){if(feature.geometry.CLASS_NAME.indexOf('Point')>-1){}
feature.layer.events.registerPriority('mousedown',feature,objRef.onClick);}
this.onUnselect=function(objRef,feature){feature.layer.events.unregister('mousedown',feature,objRef.onClick);}
this.showReport=function(id,name,bbox){var report_url;this.report_id=id;if(id==0)report_url="/test_gml.xml";else report_url="/map_edit/show_file.php?id="+id+"&amp;type=gml";if(this.layer){config.objects.mainMap.setParam('deleteLayer','user_report');this.layer=null;}
if(bbox){var points=bbox.split(',');var min=points[0].split(' ');var max=points[1].split(' ');var bounds=new OpenLayers.Bounds(min[0],min[1],max[0],max[1]);this.map.zoomToExtent(bounds);}
if(!name)name='דו&quot;ח נסיעה';var doc=(new DOMParser()).parseFromString('<?xml version="1.0" encoding="utf-8" standalone="no" ?><wmc:ViewContext version="1.0.0" id="owsview_generated_context" xmlns="http://www.opengis.net/context" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengeospatial.net/context/1.0.0/context.xsd" xmlns:sld="http://www.opengis.net/sld" xmlns:wmc="http://www.opengis.net/context">  <wmc:LayerList><wmc:Layer queryable="0" hidden="0"><wmc:Server service="FMReport" version="2.1.2" title="OGC:GML"><wmc:OnlineResource xlink:type="simple" xlink:href="'+report_url+'"/></wmc:Server><wmc:Name>user_report</wmc:Name><wmc:Title>'+name+'</wmc:Title><wmc:SRS>EPSG:4326</wmc:SRS><wmc:StyleList><wmc:Style current="1"><SLD><sld:Graphic><sld:Mark><sld:Fill><sld:CssParameter name="fill">#ee9900</sld:CssParameter><sld:CssParameter name="fill-opacity">0.4</sld:CssParameter></sld:Fill><sld:Stroke><sld:CssParameter name="stroke">#0000FF</sld:CssParameter><sld:CssParameter name="stroke-opacity">1</sld:CssParameter><sld:CssParameter name="stroke-width">3</sld:CssParameter></sld:Stroke></sld:Mark><sld:Size>3</sld:Size></sld:Graphic></SLD></wmc:Style></wmc:StyleList></wmc:Layer></wmc:LayerList></wmc:ViewContext>',"text/xml");var layers=doc.selectSingleNode("/wmc:ViewContext/wmc:LayerList");config.objects.mainMap.setParam('addLayer',layers.childNodes[0]);}
this.initLayer=function(layer){this.layer=layer;var objRef=this;this.layer.preFeatureInsert=function(feature){if(feature.geometry.CLASS_NAME.indexOf('Point')>-1){feature.style.strokeColor="red";feature.style.pointRadius=6;return;}
var status=feature.attributes['status'];if(status=='ERROR'){feature.style.strokeColor="red";}else if(status=='WARNING'){feature.style.strokeColor="yellow";}}
this.selector=new OpenLayers.Control.SelectFeature(this.layer,{hover:true,onSelect:function(feature){objRef.onSelect(objRef,feature);},onUnselect:function(feature){objRef.onUnselect(objRef,feature);},selectStyle:{fillColor:"blue",fillOpacity:0.4,hoverFillColor:"white",hoverFillOpacity:0.8,strokeColor:"red",strokeOpacity:1,strokeWidth:5,hoverStrokeColor:"red",hoverStrokeOpacity:1,hoverStrokeWidth:0.2,pointRadius:8,pointerEvents:"visiblePainted",cursor:"pointer"}});this.map.addControl(this.selector);if(this.enabled)this.selector.activate();}}