1 page.replace_html :sidebar_title, 'Browse'
2 page.replace_html :sidebar_content, :partial => 'start'
4 var gml, sf, obj_list, currentFeature;
5 OpenLayers.Feature.Vector.style['default'].strokeWidth = 3;
6 OpenLayers.Feature.Vector.style['default'].cursor = "pointer";
8 openSidebar({ onclose: stopBrowse });
9 vectors = new OpenLayers.Layer.Vector("Vector Layer", {
10 displayInLayerSwitcher: false
13 box = new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.RegularPolygon, {
19 callbacks: { done: endDrag }
24 function stopBrowse() {
34 currentFeature.destroy();
35 currentFeature = null;
38 function startDrag() {
39 $("drag_box").innerHTML='Drag a box on the map to select an area';
44 $("drag_box").onclick = startDrag;
47 var bounds = map.getExtent();
51 $("use_map").onclick = useMap;
52 function dataLoaded() {
53 $("status").innerHTML = "Loaded " + this.features.length + " features. (<a href='"+ this.url+"'>API</a>)";
55 obj_list = document.createElement("ul");
56 for (var i = 0; i < this.features.length; i++) {
57 var feature = this.features[i];
59 if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
62 var nice_name = type.substr(0,1).toUpperCase() + type.substr(1,type.length);
63 var li = document.createElement("li");
64 li.appendChild(document.createTextNode(nice_name + " "));
65 var link = document.createElement("a");
66 link.href = "/browse/"+type+"/"+feature.osm_id;
67 var name = feature.attributes.name || feature.osm_id;
68 link.appendChild(document.createTextNode(name));
70 li.appendChild(document.createTextNode(" "));
71 var link = document.createElement("a");
73 link.appendChild(document.createTextNode("+"));
74 link.feature = feature;
75 link.onclick = OpenLayers.Function.bind(function() {
76 var layer = this.feature.layer;
77 for (var i = 0; i < layer.selectedFeatures.length; i++) {
78 var f = layer.selectedFeatures[i];
79 layer.drawFeature(f, layer.styleMap.createSymbolizer(f, "default"));
81 on_feature_hover(this.feature);
82 map.setCenter(this.feature.geometry.getBounds().getCenterLonLat());
85 obj_list.appendChild(li);
87 $("object").innerHTML = "";
88 $("object").appendChild(obj_list);
90 function getData(bounds) {
91 $("status").innerHTML = "Loading...";
92 bounds.transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
93 var url = "/api/0.5/map?bbox="+bounds.toBBOX();
95 var def = OpenLayers.Feature.Vector.style['default'];
96 var style = new OpenLayers.Style();
97 style.addRules([new OpenLayers.Rule(
99 {"Polygon": {'fillColor': '#ff0000', 'strokeColor': '#ff0000'},
100 "Line": {'fillColor': '#ffff00', 'strokeColor': '#000000', strokeOpacity: '0.4'},
101 "Point": {'fillColor': '#00ff00', 'strokeColor': '#00ff00'}}
104 gml = new OpenLayers.Layer.GML("Data",url,
105 {format: OpenLayers.Format.OSM, formatOptions: {checkTags: true},
106 styleMap: new OpenLayers.StyleMap({'default': style, 'select': {'strokeColor': '#0000ff'}})
109 gml.events.register("loadend", gml, dataLoaded );
111 sf = new OpenLayers.Control.SelectFeature(gml, {'onSelect': on_feature_hover});
119 function endDrag(bbox) {
120 var bounds = bbox.getBounds();
124 $("drag_box").innerHTML = "Select an area to see features";
127 function loadObjList() {
128 $("object").innerHTML="";
129 $("object").appendChild(obj_list);
132 function on_feature_hover(feature) {
133 if (currentFeature) {
134 currentFeature.layer.drawFeature(
135 currentFeature, currentFeature.layer.styleMap.createSymbolizer(currentFeature, "default")
138 feature.layer.drawFeature(
139 feature, feature.layer.styleMap.createSymbolizer(feature, "select")
141 if ($("object").firstChild == $("object").obj_list) {
142 $("object").removeChild(obj_list);
144 $("object").innerHTML = "";
146 var div = document.createElement("div");
147 var link = document.createElement("a");
149 link.onclick = loadObjList;
150 link.appendChild(document.createTextNode("Back to Object List"));
151 div.appendChild(link)
152 $("object").appendChild(div);
153 var ul = document.createElement("ul");
155 if (feature.geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
158 var li = document.createElement("li");
159 var link = document.createElement("a");
160 link.href = "/browse/"+type+"/"+feature.osm_id;
161 link.appendChild(document.createTextNode(feature.osm_id));
162 li.appendChild(link);
164 for (var key in feature.attributes) {
165 var li = document.createElement("li");
166 li.appendChild(document.createTextNode(key + ": " + feature.attributes[key]));
169 $("object").appendChild(ul);
170 currentFeature = feature;
172 function setBounds(bounds) {
173 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
174 var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
176 bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
178 $("minlon").innerHTML = Math.round(bounds.left * decimals) / decimals;
179 $("minlat").innerHTML = Math.round(bounds.bottom * decimals) / decimals;
180 $("maxlon").innerHTML = Math.round(bounds.right * decimals) / decimals;
181 $("maxlat").innerHTML = Math.round(bounds.top * decimals) / decimals;