1 <html xmlns="http://www.w3.org/1999/xhtml">
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" />
11 <script src="../lib/OpenLayers.js"></script>
12 <script type="text/javascript">
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";
25 function on_feature_hover(feature) {
28 if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
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>";
36 $("status").innerHTML = text;
38 function clear_data() {
39 gml.destroyFeatures();
42 if (!check_zoom()) { return; }
45 gml.url = "http://www.openstreetmap.org/api/0.5/map?bbox=" + map.getExtent().toBBOX();
46 $("status").innerHTML = "Loading more data...";
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";
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+.)";
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",
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?"
83 {layers: 'osm-4326', format: 'image/png' } );
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));
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});
92 gml = new OpenLayers.Layer.GML("OSM", "xml/cambridgeport.osm", {format: OpenLayers.Format.OSM});
95 gml.events.register("loadstart", null, function() { $("status").innerHTML = "Loading..."; })
96 gml.events.register("loadend", null, function() { $("status").innerHTML = ""; })
98 gml.preFeatureInsert = style_osm_feature;
99 var sf = new OpenLayers.Control.SelectFeature(gml, {'onSelect': on_feature_hover});
105 <body onload="init()">
106 <h1 id="title">Advanced OSM Layer</h1>
107 <div id="map" class="smallmap"></div>
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>
114 <div id="status">Loading...</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>