1 OSM.initializeBrowse = function (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);
39 $("#browse_status").empty();
43 function updateData() {
44 var bounds = map.getBounds();
45 if (!browseBounds || !browseBounds.contains(bounds)) {
50 function displayFeatureWarning(count, limit, add, cancel) {
51 $("#browse_status").html(
52 $("<p class='warning'></p>")
53 .text(I18n.t("browse.start_rjs.feature_warning", { num_features: count, max_features: limit }))
55 $("<span class='icon close'></span>")
58 $("<input type='submit'>")
59 .val(I18n.t("browse.start_rjs.load_data"))
66 var bounds = map.getBounds();
67 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
70 * Modern browsers are quite happy showing far more than 100 features in
71 * the data browser, so increase the limit to 2000 by default, but keep
72 * it restricted to 500 for IE8 and 100 for older IEs.
74 var maxFeatures = 2000;
77 if (navigator.appVersion < 8) {
79 } else if (navigator.appVersion < 9) {
84 if (dataLoader) dataLoader.abort();
88 success: function (xml) {
89 dataLayer.clearLayers();
92 var features = dataLayer.buildFeatures(xml);
94 function addFeatures() {
95 $("#browse_status").empty();
96 dataLayer.addData(features);
97 browseBounds = bounds;
100 function cancelAddFeatures() {
101 $("#browse_status").empty();
104 if (features.length < maxFeatures) {
107 displayFeatureWarning(features.length, maxFeatures, addFeatures, cancelAddFeatures);
115 function onSelect(layer) {
116 // Unselect previously selected feature
118 selectedLayer.setStyle(selectedLayer.originalStyle);
121 // Redraw in selected style
122 layer.originalStyle = layer.options;
123 layer.setStyle({ color: "#0000ff", weight: 8 });
125 OSM.router.route("/" + layer.feature.type + "/" + layer.feature.id);
127 // Stash the currently drawn feature
128 selectedLayer = layer;