Home > Web GIS > Make GetFeatureInfo work for WMS map

Make GetFeatureInfo work for WMS map

What I wanted to do:

  • Create a webpage with map using OpenLayers. The map consumes a WMS from my GeoServer
  • Get attributes of the data when I click on a feature on the map. The attributes will be displayed under the map in a table

What I have:

Issue:

  • I followed examples of GetFeatureInfo to create WMS overlay on Google map using OpenLayers. It worked well. But nothing showed up when I click feature on the map: GetFeatureInfo didn’t work

Solution:

The problem is due to JavaScript’s security restriction on cross site XMLHttpRequest (See ProxyHost section in http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions). To solve this problem, I need a proxy to bypass this restriction. To follow “How do I setup ProxyHost?” in the FAQ and some other Q&As on the internet, I did the following:

  • Install Apache HTTP server on my PC
  • Get proxy.cgi from http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi
  • Change python path on the top line of proxy.cgi to my python executable (#!C:/Python26/ArcGIS10.0/python.exe -u;)
  • Add ‘localhost:8080’ in allowedHosts in proxy.cgi. This allows the proxy to work for GeoServer
  • Copy proxy.cgi to /cgi-bin under Apache folder on my PC
  • Start up Apache
  • To test the proxy.cgi, I ran http://localhost/cgi-bin/proxy.cgi, which redirected me to the homepage of OpenLayers.org
  • Copy my webpage Test.html to /htdocs under Apache folder (where I pretend I am going to serve out my webpage)
  • Add OpenLayers.ProxyHost = “/cgi-bin/proxy.cgi?url=”; on the webpage
  • Start up GeoServer
  • run the webpage from localhost/Test.html
It worked!
Advertisements
Categories: Web GIS Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: