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 if (!browseBounds || !browseBounds.contains(bounds)) {
50 function displayFeatureWarning(count, limit, callback) {
51 $('#browse_status').html(
52 $("<p class='warning'></p>")
53 .text(I18n.t("browse.start_rjs.loaded_an_area_with_num_features", { num_features: count, max_features: limit }))
55 $("<input type='submit'>")
56 .val(I18n.t('browse.start_rjs.load_data'))
63 var bounds = map.getBounds();
64 var size = bounds.getSize();
66 if (size > OSM.MAX_REQUEST_AREA) {
67 $('#browse_status').html(
68 $("<p class='warning'></p>")
69 .text(I18n.t("browse.start_rjs.unable_to_load_size", { max_bbox_size: OSM.MAX_REQUEST_AREA, bbox_size: size.toFixed(2) })));
73 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
76 * Modern browsers are quite happy showing far more than 100 features in
77 * the data browser, so increase the limit to 2000 by default, but keep
78 * it restricted to 500 for IE8 and 100 for older IEs.
80 var maxFeatures = 2000;
83 if (navigator.appVersion < 8) {
85 } else if (navigator.appVersion < 9) {
90 if (dataLoader) dataLoader.abort();
94 success: function (xml) {
95 dataLayer.clearLayers();
98 var features = dataLayer.buildFeatures(xml);
100 function addFeatures() {
101 $('#browse_status').empty();
102 dataLayer.addData(features);
105 if (features.length < maxFeatures) {
108 displayFeatureWarning(features.length, maxFeatures, addFeatures);
112 browseBounds = bounds;
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.router.route('/' + layer.feature.type + '/' + layer.feature.id);
129 // Stash the currently drawn feature
130 selectedLayer = layer;