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);
39 $('#browse_status').empty();
43 function updateData() {
44 if (map.getZoom() >= 15) {
45 var bounds = map.getBounds();
46 if (!browseBounds || !browseBounds.contains(bounds)) {
47 browseBounds = bounds;
53 function displayFeatureWarning(count, limit, callback) {
54 $('#browse_status').html(
55 $("<p class='warning'></p>")
56 .text(I18n.t("browse.start_rjs.loaded_an_area_with_num_features", { num_features: count, max_features: limit }))
58 $("<input type='submit'>")
59 .val(I18n.t('browse.start_rjs.load_data'))
66 var bounds = map.getBounds();
67 var size = bounds.getSize();
69 if (size > OSM.MAX_REQUEST_AREA) {
70 $('#browse_status').html(
71 $("<p class='warning'></p>")
72 .text(I18n.t("browse.start_rjs.unable_to_load_size", { max_bbox_size: OSM.MAX_REQUEST_AREA, bbox_size: size })));
76 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
79 * Modern browsers are quite happy showing far more than 100 features in
80 * the data browser, so increase the limit to 2000 by default, but keep
81 * it restricted to 500 for IE8 and 100 for older IEs.
83 var maxFeatures = 2000;
86 if (navigator.appVersion < 8) {
88 } else if (navigator.appVersion < 9) {
93 if (dataLoader) dataLoader.abort();
97 success: function (xml) {
98 dataLayer.clearLayers();
101 var features = dataLayer.buildFeatures(xml);
103 function addFeatures() {
104 $('#browse_status').empty();
105 dataLayer.addData(features);
108 if (features.length < maxFeatures) {
111 displayFeatureWarning(features.length, maxFeatures, addFeatures);
119 function onSelect(layer) {
120 // Unselect previously selected feature
122 selectedLayer.setStyle(selectedLayer.originalStyle);
125 // Redraw in selected style
126 layer.originalStyle = layer.options;
127 layer.setStyle({color: '#0000ff', weight: 8});
129 OSM.route('/browse/' + layer.feature.type + '/' + layer.feature.id);
131 // Stash the currently drawn feature
132 selectedLayer = layer;