Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>OpenLayers GetFeature Example</title>
- <script src="../lib/OpenLayers.js"></script>
- <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
- <link rel="stylesheet" href="style.css" type="text/css" />
- <style type="text/css">
- ul, li { padding-left: 0px; margin-left: 0px; }
- </style>
- </head>
- <body>
- <h1 id="title">GetFeature Example</h1>
- <div id="tags"></div>
- <p id="shortdesc">
- Demonstrates sending a GetFeature query to an OWS. Returns information about a map feature in the side DIV.
- </p>
- <a id="permalink" href="">Permalink</a><br />
- <div style="float:right;width:28%">
- <h1 style="font-size:1.3em;">USA States</h1>
- <p style="font-size:.8em;">Click a country to see statistics about the country below.</p>
- <div id="nodeList">
- </div>
- </div>
- <div id="map" class="smallmap"></div>
- <script defer="defer" type="text/javascript">
- OpenLayers.ProxyHost = "proxy.cgi?url=";
- var map = new OpenLayers.Map('map', {'maxResolution':'auto'});
- var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
- "http://localhost:18080/geoserver/ows", {'layers': 'topp:states'} );
- map.addLayer(wms);
- map.addControl(new OpenLayers.Control.Permalink('permalink'));
- map.zoomToMaxExtent();
- map.events.register('click', map, function (e) {
- OpenLayers.Util.getElement('nodeList').innerHTML = "Loading... please wait...";
- var lonlat = map.getLonLatFromViewPortPx(e.xy);
- var lonlatString = lonlat.toShortString().replace(/ /g, ''); // remove any spaces
- var filter = '<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><Intersects><PropertyName>the_geom</PropertyName><gml:Point srsName="EPSG:4326"><gml:coordinates>' + lonlatString + '</gml:coordinates></gml:Point></Intersects></Filter>';
- var params = {
- service: 'WFS',
- request: 'GetFeature',
- version: '1.1.0',
- typeName: wms.params.LAYERS,
- outputFormat: 'json',
- // remove the propertyName line below to get all attributes
- propertyName: 'STATE_ABBR,STATE_NAME,STATE_FIPS',
- filter: filter
- };
- var u = OpenLayers.Util.removeTail(wms.url);
- u += '?' + OpenLayers.Util.getParameterString(params);
- OpenLayers.loadURL(u, '', this, setHTML);
- OpenLayers.Event.stop(e);
- });
- function setHTML(response) {
- var jsonReader = new OpenLayers.Format.GeoJSON();
- var features = jsonReader.read(response.responseText);
- var html = '<hr />';
- for (var i=0; i< features.length; i++) {
- var feature = features[i];
- html += '<strong>' + feature.id + '</strong>' + '<br />';;
- for (var a in feature.attributes) {
- html += '<strong>' + a + '</strong>: ' + escape(feature.attributes[a]) + '<br />';
- }
- }
- OpenLayers.Util.getElement('nodeList').innerHTML = html;
- }
- </script>
- <div id="docs">
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement