~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/examples/osm-layer.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html xmlns="http://www.w3.org/1999/xhtml">
 
2
  <head>
 
3
    <title>OpenLayers: OSM Layer</title>
 
4
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
 
5
    <link rel="stylesheet" href="style.css" type="text/css" />
 
6
    <style>
 
7
        #map {
 
8
            height: 350px;
 
9
        }
 
10
    </style>
 
11
    <script src="../lib/OpenLayers.js"></script>
 
12
    <script type="text/javascript">
 
13
        var lon = 5;
 
14
        var lat = 40;
 
15
        var zoom = 5;
 
16
        var map, layer, gml;
 
17
        function export_vectors() {
 
18
            var x = new OpenLayers.Format.XML();
 
19
            var content = x.write(gml.renderer.rendererRoot);
 
20
            $("vectors").value = content;
 
21
            $("vectors").style.display = "block";
 
22
            $("vectorlink").href = "data:image/svg+xml," + escape(content);
 
23
            $("vectorlink").style.display="block";
 
24
        }
 
25
        function on_feature_hover(feature) {
 
26
            var text ="<ul>";
 
27
            var type ="way";
 
28
            if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
 
29
                type = "node";
 
30
            }    
 
31
            text += "<li>" + feature.osm_id + ": <a href='http://crschmidt.net/osm/attributes.html?type="+type+"&id="+feature.osm_id+"'>Edit</a>, <a href='http://www.openstreetmap.org/api/0.5/"+type + "/" + feature.osm_id + "'>API</a></li>";
 
32
            for (var key in feature.attributes) {
 
33
                text += "<li>" + key + ": " + feature.attributes[key] + "</li>";
 
34
            }
 
35
            text += "</ul>";
 
36
            $("status").innerHTML = text;
 
37
        }   
 
38
        function clear_data() {
 
39
            gml.destroyFeatures();
 
40
        }
 
41
        function new_data() {
 
42
            if (!check_zoom()) { return; }
 
43
            clear_data();
 
44
            gml.loaded = false;
 
45
            gml.url = "http://www.openstreetmap.org/api/0.5/map?bbox=" + map.getExtent().toBBOX();
 
46
            $("status").innerHTML = "Loading more data...";
 
47
            gml.loadGML();
 
48
        }
 
49
        function style_osm_feature(feature) {
 
50
            feature.style = OpenLayers.Util.extend({'fill':'black'}, OpenLayers.Feature.Vector.style['default']);
 
51
            if (feature.attributes.highway == "motorway") {
 
52
                feature.style.strokeColor = "blue";
 
53
                feature.style.strokeWidth = 5;
 
54
            } else if (feature.attributes.highway == "primary") {
 
55
                feature.style.strokeColor = "red";
 
56
            } else if (feature.attributes.highway == "secondary") {
 
57
                feature.style.strokeColor = "orange";
 
58
            } else if (feature.attributes.highway) {
 
59
                feature.style.strokeColor = "black";
 
60
            }   
 
61
        }
 
62
        function check_zoom() { 
 
63
            var zoom = map.getZoom();
 
64
            if (zoom >= 11) { return true; }
 
65
            if (zoom >= 9) { return confirm("Loading this amount of data may slow your browser. Are you sure you want to do this?"); }
 
66
            $("status").innerHTML = "Area too large. Zoom in to load data. (Current zoom level: "+ zoom + ". Must be at zoom 9+.)";
 
67
            return false;
 
68
        }    
 
69
        function init(){
 
70
            OpenLayers.ProxyHost = "proxy.cgi?url=";
 
71
            OpenLayers.Feature.Vector.style['default'].strokeWidth = 4;
 
72
            OpenLayers.Feature.Vector.style['default'].cursor = 'pointer';
 
73
            map = new OpenLayers.Map('map', {'maxResolution': 360/512/16, 'numZoomLevels':15, controls: [ new OpenLayers.Control.Navigation(), new OpenLayers.Control.PanZoomBar() ]});
 
74
            map.addControl(new OpenLayers.Control.LayerSwitcher());
 
75
            map.addControl(new OpenLayers.Control.Permalink());
 
76
            layer = new OpenLayers.Layer.WMS( "OSM", 
 
77
               [
 
78
                 "http://t1.hypercube.telascience.org/tiles?",
 
79
                 "http://t2.hypercube.telascience.org/tiles?",
 
80
                 "http://t3.hypercube.telascience.org/tiles?",
 
81
                 "http://t4.hypercube.telascience.org/tiles?"
 
82
                 ], 
 
83
                {layers: 'osm-4326', format: 'image/png' } );
 
84
            map.addLayer(layer);
 
85
            if (!map.getCenter()) { 
 
86
                gml = new OpenLayers.Layer.GML("OSM", "osm/sutton_coldfield.osm", {format: OpenLayers.Format.OSM});
 
87
                map.zoomToExtent(new OpenLayers.Bounds(-1.819072,52.549034,-1.814341,52.551582));
 
88
            } else {
 
89
                if (map.getZoom() >= 11) {
 
90
                    gml = new OpenLayers.Layer.GML("OSM", "http://www.openstreetmap.org/api/0.5/map?bbox=" + map.getExtent().toBBOX(), {format: OpenLayers.Format.OSM});
 
91
                } else {
 
92
                    gml = new OpenLayers.Layer.GML("OSM", "xml/cambridgeport.osm", {format: OpenLayers.Format.OSM});
 
93
                }    
 
94
            }    
 
95
            gml.events.register("loadstart", null, function() { $("status").innerHTML = "Loading..."; })
 
96
            gml.events.register("loadend", null, function() { $("status").innerHTML = ""; })
 
97
            map.addLayer(gml);
 
98
            gml.preFeatureInsert = style_osm_feature; 
 
99
            var sf = new OpenLayers.Control.SelectFeature(gml, {'onSelect': on_feature_hover});
 
100
            map.addControl(sf);
 
101
            sf.activate();
 
102
        }
 
103
    </script>
 
104
  </head>
 
105
  <body onload="init()">
 
106
    <h1 id="title">Advanced OSM Layer</h1>
 
107
    <div id="map" class="smallmap"></div>
 
108
    <div id="download">
 
109
      <ul>
 
110
       <li><a href="javascript:new_data();">Download current view</a></li>
 
111
       <li><a href="javascript:clear_data();">Clear current data</a></li>
 
112
       <li><a href="javascript:export_vectors();">Export Vector Data</a></li>
 
113
      </ul>
 
114
    <div id="status">Loading...</div>
 
115
    </div>
 
116
    <a id="vectorlink" href="" style="display:none">Display via data: URL (FF Only)</a>
 
117
    <textarea id="vectors" style="display:none;width:100%" rows="10"></textarea>
 
118
  </body>
 
119
</html>