]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/export.js
Reorganize share/export UI
[rails.git] / app / assets / javascripts / index / export.js
1 function initializeExport(map) {
2   if (window.location.pathname == "/export") {
3     startExport();
4   }
5
6   function startExport() {
7     var locationFilter = new L.LocationFilter({
8       enableButton: false,
9       adjustButton: false
10     }).addTo(map);
11
12     locationFilter.on("change", update);
13
14     map.on("moveend", update);
15
16     $("#sidebar_title").html(I18n.t('export.start_rjs.export'));
17
18     $("#maxlat,#minlon,#maxlon,#minlat").change(boundsChanged);
19
20     $("#drag_box").click(enableFilter);
21
22     openSidebar();
23
24     setBounds(map.getBounds());
25
26     $("#sidebar").one("closed", function () {
27       map.removeLayer(locationFilter);
28       map.off("moveend", update);
29       locationFilter.off("change", update);
30     });
31
32     function getBounds() {
33       return L.latLngBounds(L.latLng($("#minlat").val(), $("#minlon").val()),
34                             L.latLng($("#maxlat").val(), $("#maxlon").val()));
35     }
36
37     function boundsChanged() {
38       var bounds = getBounds();
39
40       map.fitBounds(bounds);
41       locationFilter.setBounds(bounds);
42
43       enableFilter();
44       validateControls();
45     }
46
47     function enableFilter() {
48       if (!locationFilter.getBounds().isValid()) {
49         locationFilter.setBounds(map.getBounds().pad(-0.2));
50       }
51
52       $("#drag_box").hide();
53       locationFilter.enable();
54     }
55
56     function update() {
57       setBounds(locationFilter.isEnabled() ? locationFilter.getBounds() : map.getBounds());
58       validateControls();
59     }
60
61     function setBounds(bounds) {
62       var precision = zoomPrecision(map.getZoom());
63       $("#minlon").val(bounds.getWest().toFixed(precision));
64       $("#minlat").val(bounds.getSouth().toFixed(precision));
65       $("#maxlon").val(bounds.getEast().toFixed(precision));
66       $("#maxlat").val(bounds.getNorth().toFixed(precision));
67     }
68
69     function validateControls() {
70       $("#export_osm_too_large").toggle(getBounds().getSize() > OSM.MAX_REQUEST_AREA);
71     }
72   }
73 }