1 function initializeBrowse(map) {
4 var dataLayer = map.dataLayer;
21 dataLayer.isWayArea = function () {
25 dataLayer.on("click", function (e) {
29 map.on('layeradd', function (e) {
30 if (e.layer === dataLayer) {
31 map.on("moveend", updateData);
36 map.on('layerremove', function (e) {
37 if (e.layer === dataLayer) {
38 map.off("moveend", updateData);
42 function updateData() {
43 if (map.getZoom() >= 15) {
44 var bounds = map.getBounds();
45 if (!browseBounds || !browseBounds.contains(bounds)) {
46 browseBounds = bounds;
50 setStatus(I18n.t('browse.start_rjs.zoom_or_select'));
54 function displayFeatureWarning(count, limit, callback) {
57 var div = document.createElement("div");
59 var p = document.createElement("p");
60 p.appendChild(document.createTextNode(I18n.t("browse.start_rjs.loaded_an_area_with_num_features", { num_features: count, max_features: limit })));
63 var input = document.createElement("input");
64 input.type = "submit";
65 input.value = I18n.t('browse.start_rjs.load_data');
66 input.onclick = callback;
67 div.appendChild(input);
69 $("#browse_content").html("");
70 $("#browse_content").append(div);
76 var bounds = map.getBounds();
77 var size = bounds.getSize();
79 if (size > OSM.MAX_REQUEST_AREA) {
80 setStatus(I18n.t("browse.start_rjs.unable_to_load_size", { max_bbox_size: OSM.MAX_REQUEST_AREA, bbox_size: size }));
84 setStatus(I18n.t('browse.start_rjs.loading'));
86 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
89 * Modern browsers are quite happy showing far more than 100 features in
90 * the data browser, so increase the limit to 2000 by default, but keep
91 * it restricted to 500 for IE8 and 100 for older IEs.
93 var maxFeatures = 2000;
96 if (navigator.appVersion < 8) {
98 } else if (navigator.appVersion < 9) {
103 if (dataLoader) dataLoader.abort();
105 dataLoader = $.ajax({
107 success: function (xml) {
110 dataLayer.clearLayers();
111 selectedLayer = null;
113 var features = dataLayer.buildFeatures(xml);
115 function addFeatures() {
116 dataLayer.addData(features);
119 if (features.length < maxFeatures) {
122 displayFeatureWarning(features.length, maxFeatures, addFeatures);
130 function onSelect(layer) {
131 // Unselect previously selected feature
133 selectedLayer.setStyle(selectedLayer.originalStyle);
136 // Redraw in selected style
137 layer.originalStyle = layer.options;
138 layer.setStyle({color: '#0000ff', weight: 8});
140 OSM.route('/browse/' + layer.feature.type + '/' + layer.feature.id);
142 // Stash the currently drawn feature
143 selectedLayer = layer;
146 function setStatus(status) {
149 function clearStatus() {