1 OSM.initializeDataLayer = function (map) {
3 var dataLayer = map.dataLayer;
20 dataLayer.isWayArea = function () {
24 dataLayer.on("click", function (e) {
28 map.on("layeradd", function (e) {
29 if (e.layer === dataLayer) {
30 map.on("moveend", updateData);
35 map.on("layerremove", function (e) {
36 if (e.layer === dataLayer) {
37 map.off("moveend", updateData);
38 $("#browse_status").empty();
42 function updateData() {
43 var bounds = map.getBounds();
44 if (!loadedBounds || !loadedBounds.contains(bounds)) {
49 function displayFeatureWarning(count, limit, add, cancel) {
50 $("#browse_status").html(
51 $("<div class='p-3'>").append(
52 $("<div class='d-flex'>").append(
53 $("<h2 class='flex-grow-1 text-break'>")
54 .text(I18n.t("browse.start_rjs.load_data")),
56 $("<button type='button' class='btn-close'>")
57 .attr("aria-label", I18n.t("javascripts.close"))
59 $("<p class='alert alert-warning'>")
60 .text(I18n.t("browse.start_rjs.feature_warning", { num_features: count, max_features: limit })),
61 $("<input type='submit' class='btn btn-primary d-block mx-auto'>")
62 .val(I18n.t("browse.start_rjs.load_data"))
69 var bounds = map.getBounds();
70 var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
73 * Modern browsers are quite happy showing far more than 100 features in
74 * the data browser, so increase the limit to 2000 by default, but keep
75 * it restricted to 500 for IE8 and 100 for older IEs.
77 var maxFeatures = 2000;
80 if (navigator.appVersion < 8) {
82 } else if (navigator.appVersion < 9) {
87 if (dataLoader) dataLoader.abort();
91 success: function (xml) {
92 dataLayer.clearLayers();
94 var features = dataLayer.buildFeatures(xml);
96 function addFeatures() {
97 $("#browse_status").empty();
98 dataLayer.addData(features);
99 loadedBounds = bounds;
102 function cancelAddFeatures() {
103 $("#browse_status").empty();
106 if (features.length < maxFeatures) {
109 displayFeatureWarning(features.length, maxFeatures, addFeatures, cancelAddFeatures);
112 if (map._objectLayer) {
113 map._objectLayer.bringToFront();
121 function onSelect(layer) {
122 OSM.router.route("/" + layer.feature.type + "/" + layer.feature.id);