Line | |
---|
1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
---|
5 | <title>OpenLayers: WRS Feature Example</title> |
---|
6 | |
---|
7 | <script src="http://openlayers.org/api/OpenLayers.js" type="text/javascript"></script> |
---|
8 | <script type="text/javascript"> |
---|
9 | var map; |
---|
10 | var geojson = |
---|
11 | |
---|
12 | { "type": "FeatureCollection", |
---|
13 | "features": [ |
---|
14 | $parameters:{ p | |
---|
15 | \{ "type": "Feature", |
---|
16 | "geometry": \{ |
---|
17 | "type": "Polygon", |
---|
18 | "coordinates": [ |
---|
19 | [$p.polygon$] |
---|
20 | ] |
---|
21 | \}, |
---|
22 | "crs": \{ |
---|
23 | "type": "EPSG", |
---|
24 | "properties": \{"code": "srid"\} |
---|
25 | \}, |
---|
26 | "properties": \{ |
---|
27 | "id": "$p.id$" |
---|
28 | \} |
---|
29 | \} |
---|
30 | };separator=","$ |
---|
31 | ], |
---|
32 | "status": { |
---|
33 | "code": 200, |
---|
34 | "request": "catch" |
---|
35 | }, |
---|
36 | "user": { |
---|
37 | "request_id": "$request_id$" |
---|
38 | } |
---|
39 | }; |
---|
40 | |
---|
41 | function init() { |
---|
42 | map = new OpenLayers.Map('map'); |
---|
43 | |
---|
44 | map.addLayer(new OpenLayers.Layer.WMS( |
---|
45 | "OpenLayers WMS", |
---|
46 | "http://labs.metacarta.com/wms/vmap0", |
---|
47 | {layers: 'basic'} |
---|
48 | ) |
---|
49 | ); |
---|
50 | |
---|
51 | var vectors = new OpenLayers.Layer.Vector("WRS Feature"); |
---|
52 | map.addLayer(vectors); |
---|
53 | |
---|
54 | var features = new OpenLayers.Format.GeoJSON().read(geojson); |
---|
55 | var bounds; |
---|
56 | |
---|
57 | if(features) { |
---|
58 | if(features.constructor != Array) { |
---|
59 | features = [features]; |
---|
60 | } |
---|
61 | for(var i=0; i<features.length; ++i) { |
---|
62 | if(!bounds) { |
---|
63 | bounds = features[i].geometry.getBounds(); |
---|
64 | } else { |
---|
65 | bounds.extend(features[i].geometry.getBounds()); |
---|
66 | } |
---|
67 | |
---|
68 | } |
---|
69 | vectors.addFeatures(features); |
---|
70 | map.zoomToExtent(bounds); |
---|
71 | } else { |
---|
72 | map.setCenter(new OpenLayers.LonLat(0, 0), 5); |
---|
73 | } |
---|
74 | } |
---|
75 | </script> |
---|
76 | |
---|
77 | <style type="text/css"> |
---|
78 | body { |
---|
79 | margin: 5px; |
---|
80 | } |
---|
81 | #map { |
---|
82 | width: 600px; |
---|
83 | height: 400px; |
---|
84 | border: 1px solid #ccc; |
---|
85 | } |
---|
86 | </style> |
---|
87 | </head> |
---|
88 | |
---|
89 | <body onload="init()"> |
---|
90 | <h1 id="title">WRS Feature Example</h1> |
---|
91 | <p>This map draws the result of a WRS request.</p> |
---|
92 | <div id="map"></div> |
---|
93 | </body> |
---|
94 | </html> |
---|
95 | |
---|