MapLog.namespace("MapLog.Control"); MapLog.Control.TracQuery = OpenLayers.Class(OpenLayers.Control,{ /** * default handler configuration options */ defaultHandlerOptions: { 'single': true, 'double': false, 'pixelTolerance': 0, 'stopSingle': false, 'stopDouble': false }, /** * click handler */ handler: undefined, /** * size */ size: new OpenLayers.Size(300,200), /** * query layer */ qlayer: undefined, /** * ext container instead of popup */ extContainer: undefined, /** * print results to popup */ usePopup: true, /** * popup class */ popupClass: OpenLayers.Popup.FramedCloud, /** * Contructor: OpenLayers.Control.UnitSwitcher * Switcher for MapLog units * * Parameters: * layer - {OpenLayers.Layer.UnitLayer} * qlayer - {String} query layer name * options - {Object} configuration options */ initialize: function(layer,qlayer,options) { OpenLayers.Control.prototype.initialize.apply(this, [options]); this.handlerOptions = OpenLayers.Util.extend( {}, this.defaultHandlerOptions ); this.handler = new OpenLayers.Handler.Click( this, { 'click': this.trigger }, this.handlerOptions); this.qlayer = qlayer; this.layer = layer; }, /** * Triger click action */ trigger: function(e) { var feature = this.unitsLayer.getFeatureFromEvent(e); var lonlat = this.map.getLonLatFromPixel(e.xy); var bounds = this.map.getExtent(); var size = this.map.getSize(); if (this.popup) { this.map.removePopup(this.popup); this.popup.destroy(); } if (!feature) { if (!this.layer.params.IDS) { return; } // var url = this.layer.getFullRequestString({mode:"query", // qlayer:(this.qlayer ? this.qlayer : this.layer.params.layers), // "map_projection": this.map.projection.getCode(), // "imgxy": e.xy.x+" "+e.xy.y, // "mapsize": size.w+" "+size.h, // "imgext":bounds.left+" "+bounds.bottom+" "+bounds.right+" "+bounds.top // }); var params = { IDS: this.layer.params.IDS, fromTime: this.layer.params.fromTime, toTime: this.layer.params.toTime, EPSG: this.map.projection.getCode().split(":")[1], xclick: lonlat.lon, yclick: lonlat.lat, imgext: bounds.left+" "+bounds.bottom+" "+bounds.right+" "+bounds.top }; var url = OpenLayers.Util.urlAppend(MapLog.Control.TracQuery.PositionDetailURL, OpenLayers.Util.getParameterString(params)); this.popup = new this.popupClass(undefined, lonlat, this.size, "", null, true); this.map.addPopup(this.popup); OpenLayers.Request.GET({ url: url, scope: this, success: this.displayResult }); } else { var temp_cze = '
'+ ''+ '
Firma:
{holderName}  
'+ '
Telefon:
{phone}  
'+ '
'+ ' '+ '
SPZ:
{spz}  
'+ '
Typ:
{typ}  
'+ '
Model:
{model}  
'+ '
'+ ''+ '
Rychlost:
{speed} km/h  
'+ '
Poslední pozice:
{time_stamp} {xwgs84},{ywgs84}  
'+ '
Klíček:
{ignition_on}  
'+ '
'+ ''+ '
RFID:
{rfid_desc}  
'+ '
'+ '
'+ '

Řidiči:

'+ ''; var temp_eng = '
'+ ''+ '
Company:
{holderName}  
'+ '
Voice phone:
{phone}  
'+ '
'+ ' '+ '
Reg No.:
{spz}  
'+ '
Type:
{typ}  
'+ '
Model:
{model}  
'+ '
'+ ''+ '
Speed:
{speed} km/h  
'+ '
Last position:
{time_stamp} {xwgs84},{ywgs84}  
'+ '
Ignition:
{ignition_on}  
'+ '
'+ ''+ '
RFID:
{rfid_desc}  
'+ '
'+ '
'+ '

Drivers:

'+ ''; var template = temp_eng; if (HS.getLang() == "cze"){ template = temp_cze; } if (this.usePopup) { this.popup = new this.popupClass(undefined, lonlat, this.size, MapLog.UnitFeature.processDetailTemplate(feature.attributes,template), null, true); this.map.addPopup(this.popup); this.popup.setSize(this.size); } else if (this.extContainer) { this.extContainer.body.update(MapLog.UnitFeature.processDetailTemplate(feature.attributes,template)); } } // /if feature OpenLayers.Event.stop(e,true); }, /** * Display Popup */ displayResult: function(httprequest){ //var jsonFormat = new OpenLayers.Format.JSON(); //var resp = jsonFormat.read(httprequest.responseText); var resp = eval("("+httprequest.responseText+")"); var template; if (resp[0].status == "success") { template = 'Údaje o bodu na trase
'+ '
Název:
{unit_description}  
'+ '
Čas:
{time_stamp}  
'+ '
Pozice:
{lat} {lon} 
'+ '
Rychlost:
{speed} km/h  
'+ '
Klíček:
{ignition_status}  
'+ '
'; resp[0].obj.ignition_status = (resp[0].obj.ignition_status === 0 ? "Vypnuto" : "Zapnuto"); } else { template = "Nothing found"; } if (this.popup) { this.popup.setContentHTML(MapLog.UnitFeature.processDetailTemplate(resp[0].obj,template)); this.popup.setSize(new OpenLayers.Size(300,120)); var px = this.map.getLayerPxFromLonLat(new OpenLayers.LonLat(resp[0].obj.x, resp[0].obj.y)); this.popup.moveTo(px); } else if (this.extContainer) { this.extContainer.body.update(MapLog.UnitFeature.processDetailTemplate(resp[0].obj,template)); this.extContainer.doLayout(); } }, CLASS_NAME: "MapLog.Control.TracQuery" }); MapLog.Control.TracQuery.PositionDetailURL = "/maplog/tools/position_detail.php";