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 var bounds = map.getBounds();
45 getData(!browseBounds || !browseBounds.contains(bounds));
46 browseBounds = bounds;
49 function displayFeatureWarning(count, limit, callback) {
50 $('#browse_status').html(
51 $("<p class='warning'></p>")
52 .text(I18n.t("browse.start_rjs.loaded_an_area_with_num_features", { num_features: count, max_features: limit }))
54 $("<input type='submit'>")
55 .val(I18n.t('browse.start_rjs.load_data'))
61 function getData(inPrevious) {
62 var bounds = map.getBounds();
63 var size = bounds.getSize();
65 if (size > OSM.MAX_REQUEST_AREA) {
66 $('#browse_status').html(
67 $("<p class='warning'></p>")
68 .text(I18n.t("browse.start_rjs.unable_to_load_size", { max_bbox_size: OSM.MAX_REQUEST_AREA, bbox_size: size.toFixed(2) })));
72 if (inPrevious) return;
74 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
77 * Modern browsers are quite happy showing far more than 100 features in
78 * the data browser, so increase the limit to 2000 by default, but keep
79 * it restricted to 500 for IE8 and 100 for older IEs.
81 var maxFeatures = 2000;
84 if (navigator.appVersion < 8) {
86 } else if (navigator.appVersion < 9) {
91 if (dataLoader) dataLoader.abort();
95 success: function (xml) {
96 dataLayer.clearLayers();
99 var features = dataLayer.buildFeatures(xml);
101 function addFeatures() {
102 $('#browse_status').empty();
103 dataLayer.addData(features);
106 if (features.length < maxFeatures) {
109 displayFeatureWarning(features.length, maxFeatures, addFeatures);
117 function onSelect(layer) {
118 // Unselect previously selected feature
120 selectedLayer.setStyle(selectedLayer.originalStyle);
123 // Redraw in selected style
124 layer.originalStyle = layer.options;
125 layer.setStyle({color: '#0000ff', weight: 8});
127 OSM.route('/browse/' + layer.feature.type + '/' + layer.feature.id);
129 // Stash the currently drawn feature
130 selectedLayer = layer;