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);
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) {
56 $('#browse_status').append(
57 $("<p class='warning'></p>")
58 .text(I18n.t("browse.start_rjs.loaded_an_area_with_num_features", { num_features: count, max_features: limit }))
60 $("<input type='submit'>")
61 .val(I18n.t('browse.start_rjs.load_data'))
68 var bounds = map.getBounds();
69 var size = bounds.getSize();
71 if (size > OSM.MAX_REQUEST_AREA) {
72 setStatus(I18n.t("browse.start_rjs.unable_to_load_size", { max_bbox_size: OSM.MAX_REQUEST_AREA, bbox_size: size }));
76 setStatus(I18n.t('browse.start_rjs.loading'));
78 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
81 * Modern browsers are quite happy showing far more than 100 features in
82 * the data browser, so increase the limit to 2000 by default, but keep
83 * it restricted to 500 for IE8 and 100 for older IEs.
85 var maxFeatures = 2000;
88 if (navigator.appVersion < 8) {
90 } else if (navigator.appVersion < 9) {
95 if (dataLoader) dataLoader.abort();
99 success: function (xml) {
100 dataLayer.clearLayers();
101 selectedLayer = null;
103 var features = dataLayer.buildFeatures(xml);
105 function addFeatures() {
107 dataLayer.addData(features);
110 if (features.length < maxFeatures) {
113 displayFeatureWarning(features.length, maxFeatures, addFeatures);
121 function onSelect(layer) {
122 // Unselect previously selected feature
124 selectedLayer.setStyle(selectedLayer.originalStyle);
127 // Redraw in selected style
128 layer.originalStyle = layer.options;
129 layer.setStyle({color: '#0000ff', weight: 8});
131 OSM.route('/browse/' + layer.feature.type + '/' + layer.feature.id);
133 // Stash the currently drawn feature
134 selectedLayer = layer;
137 function setStatus(status) {
138 $('#browse_status').append($('<p></p>').text(status));
141 function clearStatus() {
142 $('#browse_status').empty();