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(
55 .text(I18n.t("browse.start_rjs.load_data"))
56 .prepend($("<span class='icon close'></span>").click(cancel)))
60 $("<p class='alert alert-warning clearfix'></p>")
61 .text(I18n.t("browse.start_rjs.feature_warning", { num_features: count, max_features: limit })))
63 $("<input type='submit' class='btn btn-primary'>")
64 .val(I18n.t("browse.start_rjs.load_data"))
71 var bounds = map.getBounds();
72 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
75 * Modern browsers are quite happy showing far more than 100 features in
76 * the data browser, so increase the limit to 2000 by default, but keep
77 * it restricted to 500 for IE8 and 100 for older IEs.
79 var maxFeatures = 2000;
82 if (navigator.appVersion < 8) {
84 } else if (navigator.appVersion < 9) {
89 if (dataLoader) dataLoader.abort();
93 success: function (xml) {
94 dataLayer.clearLayers();
97 var features = dataLayer.buildFeatures(xml);
99 function addFeatures() {
100 $("#browse_status").empty();
101 dataLayer.addData(features);
102 browseBounds = bounds;
105 function cancelAddFeatures() {
106 $("#browse_status").empty();
109 if (features.length < maxFeatures) {
112 displayFeatureWarning(features.length, maxFeatures, addFeatures, cancelAddFeatures);
120 function onSelect(layer) {
121 // Unselect previously selected feature
123 selectedLayer.setStyle(selectedLayer.originalStyle);
126 // Redraw in selected style
127 layer.originalStyle = layer.options;
128 layer.setStyle({ color: "#0000ff", weight: 8 });
130 OSM.router.route("/" + layer.feature.type + "/" + layer.feature.id);
132 // Stash the currently drawn feature
133 selectedLayer = layer;