root/tools/routingservice/branches/wrs-2.0/data/templates/route/route_openlayers.st

Revision 304, 2.2 KB (checked in by daniel, 19 months ago)

geojson variable

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 = { "type": "FeatureCollection",
11                                                "features": [
12$parameters:{ p |
13                                                        \{ "type": "Feature",
14                                                                "geometry": \{
15                                                                        "type": "LineString",
16                                                                        "coordinates": [
17                                                                                $p.line$
18                                                                        ]
19                                                                \},
20                                                                "crs": \{
21                                                                        "type": "EPSG",
22                                                                        "properties": \{"code": "srid"\}
23                                                                \},
24                                                                "properties": \{
25                                                                        "id": "$p.id$"
26                                                                \}
27                                                        \}
28};separator=","$
29                                                ],
30                                                "status": {
31                                                        "code": 200,
32                                                        "request": "route"
33                                                },
34                                                "user": {
35                                                        "request_id": "$request_id$"
36                                                }
37                                        };
38
39        function init() {
40            map = new OpenLayers.Map('map');
41                       
42            map.addLayer(new OpenLayers.Layer.WMS(
43                                                                "OpenLayers WMS",
44                                            "http://labs.metacarta.com/wms/vmap0",
45                                                                {layers: 'basic'}
46                                                        )
47                                                );
48                                               
49                        var vectors = new OpenLayers.Layer.Vector("WRS Feature");
50                        map.addLayer(vectors);
51                       
52                        var features = new OpenLayers.Format.GeoJSON().read(geojson);
53                        var bounds;
54                       
55                        if(features) {
56                            if(features.constructor != Array) {
57                                features = [features];
58                            }
59                            for(var i=0; i<features.length; ++i) {
60                                if(!bounds) {
61                                    bounds = features[i].geometry.getBounds();
62                                } else {
63                                    bounds.extend(features[i].geometry.getBounds());
64                                }
65                       
66                            }
67                            vectors.addFeatures(features);
68                            map.zoomToExtent(bounds);
69                        } else {
70                            map.setCenter(new OpenLayers.LonLat(0, 0), 5);
71                        }
72        }
73    </script>
74       
75    <style type="text/css">
76        body {
77            margin: 5px;
78        }
79        #map {
80            width: 600px;
81            height: 400px;
82                        border: 1px solid #ccc;
83        }
84    </style>
85</head>
86       
87<body onload="init()">
88        <h1 id="title">WRS Feature Example</h1>
89        <p>This map draws the result of a WRS request.</p>
90        <div id="map"></div>
91</body>
92</html>
93
Note: See TracBrowser for help on using the browser.