OpenLayers OpenLayers

root/sandbox/follower/b-singlefile/mvs.html

Revision 210, 3.2 kB (checked in by crschmidt, 3 years ago)

MapViewerService ported to new code. By the way, for those of you who were participating in the Mythical Man Month discussion: 9 minutes. Although I'm not sure the text file support is completely working.

Line 
1 <html>
2 <!--
3      OpenLayers Map Viewer Service
4
5      Copyright 2005-2006 MetaCarta, Inc., released under the BSD License.
6 -->
7 <!--
8      This probably needs to be renamed index.html for deployment.
9      Specifically, it needs to be the default page for whatever
10      directory it is in.
11 -->
12 <head>
13
14 <script src="lib/OpenLayers.js"></script>
15
16 <script>
17
18 // From:
19 // <http://www.oreilly.com/catalog/jscript3/chapter/ch13.html#JSCRIPT-CH-WINDOWS-EX-LOC>
20 /*
21  * This function parses comma-separated name=value argument pairs from
22  * the query string of the URL. It stores the name=value pairs in
23  * properties of an object and returns that object.
24  */
25 // +pjl changed to split on ampersand, not comma.
26
27 function getArgs() {
28     var args = new Object();
29     var query = location.search.substring(1);  // Get query string.
30     var pairs = query.split("&");              // Break at ampersand. //+pjl
31
32     for(var i = 0; i < pairs.length; i++) {
33     var pos = pairs[i].indexOf('=');       // Look for "name=value".
34     if (pos == -1) continue;               // If not found, skip.
35     var argname = pairs[i].substring(0,pos);  // Extract the name.
36     var value = pairs[i].substring(pos+1); // Extract the value.
37     args[argname] = unescape(value);          // Store as a property.
38     }
39     return args;                               // Return the object.
40 }
41
42
43 function runMVS() {
44     if (document.location.protocol != "file:") {
45         theArgs = getArgs();
46     } else {
47         theArgs = {};
48         theArgs.center = "0,0";
49         theArgs.zoom = "0";           
50         theArgs.data = "textfile.txt";
51     }
52
53
54     // ----
55     // TODO: Handle all this parsing better.
56     var safeArgs = {}
57
58     var DEFAULT_LAT = 0;
59     var DEFAULT_LON = 0;
60     var DEFAULT_ZOOM_LEVEL = 0;
61
62     var IDX_LAT = 0;
63     var IDX_LON = 1;
64
65     safeArgs.centerLat = theArgs.center ?
66         parseFloat(theArgs.center.split(",")[IDX_LAT]) : DEFAULT_LAT;
67    
68     safeArgs.centerLon = theArgs.center ?
69         parseFloat(theArgs.center.split(",")[IDX_LON]) : DEFAULT_LON;
70
71     safeArgs.zoom = theArgs.zoom ? parseInt(theArgs.zoom) : DEFAULT_ZOOM_LEVEL;
72
73     safeArgs.data = theArgs.data; // TODO: Make this "safe".
74
75     // -----
76     var theMVS = new OpenLayers.Map($('map'));
77         theMVS.addLayer(
78              new OpenLayers.Layer.WMS("OpenLayers WMS",
79                           "http://octo.metacarta.com/cgi-bin/mapserv",
80                           {"map" : "/mapdata/vmap_wms.map",
81                            layers: 'basic'}
82                           ));
83
84         theMVS.addLayer(
85             new OpenLayers.Layer.WMS("NASA Mosaic",
86                          "http://wms.jpl.nasa.gov/wms.cgi",
87                          {"EXCEPTIONS" : "application/vnd.ogc.se_inimage",
88                           "format" : "image/jpeg",
89                           layers:"modis,global_mosaic"}
90                          ));
91     theMVS.setCenter(new OpenLayers.LonLat(safeArgs.centerLon, safeArgs.centerLat), safeArgs.zoom);
92
93     if (safeArgs.data) {
94         theMVS.addLayer(new OpenLayers.Layer.Text("Data", safeArgs.data));
95     }
96
97 }
98 </script>
99 </head>
100 <body style="margin:0px;"
101       onload="runMVS();">
102 <div id="map"
103      style="width: 100%; height: 100%;
104             background: lightyellow;
105            "></div>
106 </body>
107 </html>
Note: See TracBrowser for help on using the browser.