[OpenLayers-Users] Re: OL w/ JQuery Mobile - WMSGetFeatureInfo

Richard Greenwood richard.greenwood at gmail.com
Thu Jun 16 19:16:27 EDT 2011


On Thu, Jun 16, 2011 at 5:04 PM, maw269 <maw269 at gmail.com> wrote:
> Nope Ravi, I have not found a solution.
>
> Sorry,
>
> Matt

I don't know if the code below will help. I am putting the results
into a jQuery 'page' rather than a pop-up, and I am querying the
attribute data via a custom php page that returns JSON, but maybe it
will be useful to you none the less.

Best regards,
Rich

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
  defaultHandlerOptions: {
	  'single': true,
	  'double': false,
	  'pixelTolerance': 0,
	  'stopSingle': false,
	  'stopDouble': false
  },

  initialize: function(options) {
	  this.handlerOptions = OpenLayers.Util.extend(
		  {}, this.defaultHandlerOptions
	  );
	  OpenLayers.Control.prototype.initialize.apply(
		  this, arguments
	  );
	  this.handler = new OpenLayers.Handler.Click(
		  this, {
			  'click': this.trigger
		  }, this.handlerOptions
	  );
  },

  trigger: function(e) {
    var url;

    // var qlayers = rwg.mapservLayerList.getActiveInfoLayers();
    var qlayers = 'ownership';

    if (qlayers) {
      /* Populate Info Tool via jQuery JSON */
      url = rwg.info_url + '?layers=' + qlayers;
      url += '&r='+Math.round(map.getResolution()); // resolution in
feet per pixel

      var p0 = this.map.getLonLatFromViewPortPx(e.xy);
      url += "&p="+Math.round(p0.lon)+','+Math.round(p0.lat);

      $('#infotool').empty();
      $('#infotool').append(rwg.renderInfo(url));

      $.mobile.changePage('infopage');
    }
  }
});

rwg.renderInfo = function(url){
  var content = $('<div>');
  // content.hide();
  // in jQuery 1.4 $.getJSON() will fail silently on invalid JSON data
  $.getJSON(url, function(data) {
    // content.append('<b>' + data.numRows + ' Record(s) Found</b>');
    var infoLength = data.info.length;

    // loop thru the unique info layers
    // a single layer can return multiple records
    for (var i=0; i<infoLength; i++) {
      // content.append('<hr>');
      // Check to see if we have a function registered to display
records of this info type.
      if (typeof(rwg.infoLayers[data.info[i].handler]) === 'function') {
        content.append(rwg.infoLayers[data.info[i].handler](data.info[i].records));
      }
    }
  });
  return content;
}



-- 
Richard Greenwood
richard.greenwood at gmail.com
www.greenwoodmap.com


More information about the Users mailing list