Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 129 lines (113 sloc) 4.648 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
<!DOCTYPE html>
<html>
<!--
This probably needs to be renamed index.html for deployment.
Specifically, it needs to be the default page for whatever
directory it is in.
-->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">

    <!-- this gmaps key generated for http://openlayers.org/dev/ -->
    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAA9XNhd8q0UdwNC7YSO4YZghSPUCi5aRYVveCcVYxzezM4iaj_gxQ9t-UajFL70jfcpquH5l1IJ-Zyyw'></script>
    <!-- Localhost key -->
     <!--<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTS6gjckBmeABOGXIUiOiZObZESPg'></script>-->
<script src="http://openlayers.org/dev/lib/OpenLayers.js"></script>

<script>

function runMVS() {
    OpenLayers.ProxyHost = '/proxy/?url=';
    if (document.location.protocol != "file:") {
        theArgs = OpenLayers.Util.getParameters();
    } else {
        theArgs = {};
        theArgs.center = "0,0";
        theArgs.zoom = "0";
        theArgs.data = "textfile.txt";
        theArgs.controls = 'panzoom,mouse';
        theArgs.layers = 'openlayers';
    }


    // ----
    // TODO: Handle all this parsing better.
    var safeArgs = {};

    var DEFAULT_LAT = 0;
    var DEFAULT_LON = 0;
    var DEFAULT_ZOOM_LEVEL = 0;
    var DEFAULT_CONTROLS = ['panzoom','mouse'];
    var DEFAULT_LAYERS = ['openlayers'];
    
    var IDX_LAT = 0;
    var IDX_LON = 1;

    safeArgs.centerLat = theArgs.center ?
        parseFloat(theArgs.center.split(",")[IDX_LAT]) : DEFAULT_LAT;
    
    safeArgs.centerLon = theArgs.center ?
        parseFloat(theArgs.center.split(",")[IDX_LON]) : DEFAULT_LON;

    safeArgs.zoom = theArgs.zoom ? parseInt(theArgs.zoom) : DEFAULT_ZOOM_LEVEL;
    
    safeArgs.controls = theArgs.controls ?
        theArgs.controls.split(",") : DEFAULT_CONTROLS;
    
    safeArgs.layers = theArgs.layers ?
        theArgs.layers.split(",") : DEFAULT_LAYERS;
    
    safeArgs.data = theArgs.data; // TODO: Make this "safe".
    safeArgs.marker = theArgs.marker; // TODO: Make this "safe".
    
    // -----
    var theMVS = new OpenLayers.Map('map', {controls: [], maxResolution: 'auto'});
    for(var i = 0; i < safeArgs.controls.length; i++) {
        switch(safeArgs.controls[i]) {
            case 'panzoombar':
                theMVS.addControl(new OpenLayers.Control.PanZoomBar());
                break;
            case 'panzoom':
                theMVS.addControl(new OpenLayers.Control.PanZoom());
                break;
            case 'layerswitcher':
                theMVS.addControl(new OpenLayers.Control.LayerSwitcher());
                break;
            case 'mouse':
                theMVS.addControl(new OpenLayers.Control.MouseDefaults());
                break;
        }
    }
    for(var i = 0; i < safeArgs.layers.length; i++) {
        switch(safeArgs.layers[i]) {
            case 'openlayers':
                theMVS.addLayer(
                  new OpenLayers.Layer.WMS( "OpenLayers WMS",
                        "http://vmap0.tiles.osgeo.org/wms/vmap0",
                        {layers: 'basic'} )
                  );
                break;
            case 'nasa':
                theMVS.addLayer(
                    new OpenLayers.Layer.WMS("NASA Mosaic",
                       "http://t1.hypercube.telascience.org/cgi-bin/landsat7",
                       {"EXCEPTIONS" : "application/vnd.ogc.se_inimage",
                        "format" : "image/jpeg",
                        layers:"landsat7"}
                       ));
                break;
            case 'gmaps':
                theMVS.addLayer(
                    new OpenLayers.Layer.Google( "Google" , {type: G_HYBRID_MAP })
                );
                break;
        }
    }
    theMVS.setCenter(new OpenLayers.LonLat(safeArgs.centerLon, safeArgs.centerLat), safeArgs.zoom);

    if (safeArgs.marker) {
        var m = new OpenLayers.Layer.Markers("Marker");
        m.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(safeArgs.centerLon, safeArgs.centerLat)));
        theMVS.addLayer(m);
    }
    if (safeArgs.data) {
        theMVS.addLayer(new OpenLayers.Layer.Text("Data", {location: safeArgs.data}));
    }

}
</script>
</head>
<body style="margin:0px;"
      onload="runMVS();">
<div id="map"
     style="width: 100%; height: 100%;
background: lightyellow;
"></div>
</body>
</html>
Something went wrong with that request. Please try again.