]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/export.js
Add about page
[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     update();
13
14     locationFilter.on("change", update);
15
16     map.on("moveend", update);
17
18     $("#maxlat,#minlon,#maxlon,#minlat").change(boundsChanged);
19
20     $("#drag_box").click(enableFilter);
21
22     setBounds(map.getBounds());
23
24     $("#sidebar").one("closed", function () {
25       map.removeLayer(locationFilter);
26       map.off("moveend", update);
27       locationFilter.off("change", update);
28     });
29
30     function getBounds() {
31       return L.latLngBounds(L.latLng($("#minlat").val(), $("#minlon").val()),
32                             L.latLng($("#maxlat").val(), $("#maxlon").val()));
33     }
34
35     function boundsChanged() {
36       var bounds = getBounds();
37
38       map.fitBounds(bounds);
39       locationFilter.setBounds(bounds);
40
41       enableFilter();
42       validateControls();
43     }
44
45     function enableFilter() {
46       if (!locationFilter.getBounds().isValid()) {
47         locationFilter.setBounds(map.getBounds().pad(-0.2));
48       }
49
50       $("#drag_box").hide();
51       locationFilter.enable();
52     }
53
54     function update() {
55       setBounds(locationFilter.isEnabled() ? locationFilter.getBounds() : map.getBounds());
56       validateControls();
57     }
58
59     function setBounds(bounds) {
60       var precision = zoomPrecision(map.getZoom());
61       $("#minlon").val(bounds.getWest().toFixed(precision));
62       $("#minlat").val(bounds.getSouth().toFixed(precision));
63       $("#maxlon").val(bounds.getEast().toFixed(precision));
64       $("#maxlat").val(bounds.getNorth().toFixed(precision));
65     }
66
67     function validateControls() {
68       $("#export_osm_too_large").toggle(getBounds().getSize() > OSM.MAX_REQUEST_AREA);
69     }
70   }
71 }