Advertisement
Guest User

OpenLayers.Control.ArcGisRestIdentify (giohappy)

a guest
Dec 10th, 2010
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. OpenLayers.Control.ArcGisRestIdentify = OpenLayers.Class(OpenLayers.Control, {
  2.     layerid:null,
  3.     eventListeners:null,
  4.     url:null,
  5.     EVENT_TYPES: ["resultarrived"],
  6.    
  7.     defaultHandlerOptions: {
  8.         'single': true,
  9.         'double': false,
  10.         'pixelTolerance': 0,
  11.         'stopSingle': false,
  12.         'stopDouble': false,
  13.         'sr' : 4326
  14.     },
  15.  
  16.     initialize: function(options) {
  17.         this.EVENT_TYPES =
  18.         OpenLayers.Control.ArcGisRestIdentify .prototype.EVENT_TYPES.concat(
  19.             OpenLayers.Control.prototype.EVENT_TYPES
  20.         );
  21.         this.handlerOptions = OpenLayers.Util.extend(
  22.             {}, this.defaultHandlerOptions
  23.         );
  24.         OpenLayers.Control.prototype.initialize.apply(
  25.             this, arguments
  26.         );
  27.         var callbacks = {};
  28.         callbacks['click'] = this.doQuery;
  29.         this.handler = new OpenLayers.Handler.Click(
  30.             this, callbacks, this.handlerOptions
  31.         );
  32.     },
  33.    
  34.     activate: function () {
  35.         if (!this.active) {
  36.             this.handler.activate();
  37.         }
  38.         return OpenLayers.Control.prototype.activate.apply(
  39.             this, arguments
  40.         );
  41.     },
  42.  
  43.     deactivate: function () {
  44.         return OpenLayers.Control.prototype.deactivate.apply(
  45.             this, arguments
  46.         );
  47.     },
  48.  
  49.     /*trigger: function(e) {
  50.         var lonlat = map.getLonLatFromViewPortPx(e.xy);
  51.         alert("You clicked near " + lonlat.lat + " N, " +
  52.                                   + lonlat.lon + " E");*/
  53.    
  54.     buildOptions: function(clickPosition,url){
  55.         evtlonlat = this.map.getLonLatFromPixel(clickPosition);
  56.         var queryoptions = {
  57.         geometry:evtlonlat.lon+","+evtlonlat.lat,
  58.         geometryType:"esriGeometryPoint",
  59.         sr:this.sr,
  60.         tolerance:3,
  61.         imageDisplay:this.map.getSize().w+","+this.map.getSize().h+",96",
  62.         mapExtent:this.map.getExtent().toBBOX(null,false),
  63.         layers:"visible:"+this.layerid,
  64.         spatialRel:"esriSpatialRelIntersects",
  65.         f:"json",
  66.         returnGeometry:"false"};
  67.        
  68.         var query = {
  69.             url:url,
  70.             params:queryoptions,
  71.             callback: function(request){
  72.                 this.handleresult(request,clickPosition);
  73.             },
  74.             scope: this
  75.         };
  76.         return query
  77.     },
  78.    
  79.     handleresult: function(result,xy){
  80.         this.events.triggerEvent("resultarrived",{
  81.             text:result.responseText,
  82.             xy:xy
  83.         });
  84.     },
  85.    
  86.     request: function(clickPosition){
  87.         queryOptions = this.buildOptions(clickPosition,this.url);
  88.         var request = OpenLayers.Request.GET(queryOptions);
  89.     },
  90.    
  91.     doQuery: function(e){
  92.         this.request(e.xy);
  93.     }
  94. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement