Database Reference
In-Depth Information
Consuming
WMS
services
with
OpenLayers
Inthisrecipe,youwillusetheMapServerandGeoserverWMSyoucreatedinthefirst
two recipes of this chapter using the OpenLayers open-source JavaScript API.
This excellent library help developer to quickly assemble web pages using mapping
viewersandfeatures.Inthisrecipe,youwillcreateanHTMLpage,addanOpenLay-
ersmapinitandabunchofcontrolsinthatmapfornavigation,switchthelayers,and
identifyfeaturesofthelayers.WewillthenaddtotheOpenLayersmapthetwoWMS
layerspointingtothePostGIStables,implementedwithMapServerandGeoServerat
the beginning of this chapter.
Getting ready
MapServer uses PROJ.4 ( https://trac.osgeo.org/proj/ ) for projection management.
This library does not exist by default with the Spherical Mercator projection
( EPSG:900913 )defined.SuchaprojectioniscommonlyusedbycommercialmapAPI
providers,suchasGoogleMaps,Yahoo!Maps,andMicrosoftBing,thatcanprovide
excellent base layers for your maps.
1. As you will use a couple of Google Maps base layers in the map you are
going to create in this recipe, you need to add the EPSG:900913 support to
PROJ.4.Therefore,addanEPSG:900913definitionlineinthePROJ.4data-
file (in Linux, generally, this is in /usr/share/proj/epsg , and in my Win-
dows OS, it is in C:\ms4w\proj\nad ). Open the PROJ.4 datafile, add the
following line, and then save it:
<900913> +proj=merc +a=6378137 +b=6378137
+lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0
+k=1.0 +units=m +nadgrids=@null +no_defs
2. DuetosecurityrestrictionsinJavaScript,itisnotpossibletoretrieveinform-
ationfromremotedomainsusing XMLHttpRequest .Youwillencounterthis
issue in the recipe when you send a WMS GetFeatureInfo request to
GeoServer that is typically running on Tomcat at port 8080, which is differ-
ent from the HTML page running on Apache or ISS, port 80. Therefore, un-
Search WWH ::




Custom Search