1 //= require index/browse
2 //= require index/export
5 $(document).ready(function () {
7 var params = OSM.mapParams();
8 var map = createMap("map");
10 if (!params.object_zoom) {
12 var bbox = new OpenLayers.Bounds(params.minlon, params.minlat, params.maxlon, params.maxlat);
14 map.zoomToExtent(proj(bbox));
17 $(window).load(function() { addBoxToMap(bbox) });
20 setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom);
25 setMapLayers(params.layers);
29 marker = addMarkerToMap(new OpenLayers.LonLat(params.mlon, params.mlat));
33 var url = "/api/" + OSM.API_VERSION + "/" + params.object_type + "/" + params.object_id;
35 if (params.object_type != "node") {
39 $(window).load(function() { addObjectToMap(url, params.object_zoom) });
42 map.events.register("moveend", map, updateLocation);
43 map.events.register("changelayer", map, updateLocation);
48 $("#show_data").click(function (e) {
49 $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
50 startBrowse(sidebarHtml);
55 $("body").on("click", "a.set_position", function () {
56 var data = $(this).data();
57 var centre = new OpenLayers.LonLat(data.lon, data.lat);
59 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
60 var bbox = new OpenLayers.Bounds(data.minLon, data.minLat, data.maxLon, data.maxLat);
62 map.zoomToExtent(proj(bbox));
64 setMapCenter(centre, data.zoom);
68 removeMarkerFromMap(marker);
71 marker = addMarkerToMap(centre, getArrowIcon());
76 function updateLocation() {
77 var lonlat = unproj(map.getCenter());
78 var zoom = map.getZoom();
79 var layers = getMapLayers();
80 var extents = unproj(map.getExtent());
81 var expiry = new Date();
83 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object_type, params.object_id);
85 expiry.setYear(expiry.getFullYear() + 10);
86 $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry});
89 function remoteEditHandler(event) {
90 var extent = unproj(map.getExtent());
93 $("#linkloader").load(function () { loaded = true; });
94 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
96 setTimeout(function () {
97 if (!loaded) alert(I18n.t('site.index.remote_failed'));
103 $("a[data-editor=remote]").click(remoteEditHandler);
105 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
109 $(window).resize(function() {
110 var centre = map.getCenter();
111 var zoom = map.getZoom();
115 map.setCenter(centre, zoom);
118 $("#exportanchor").click(function (e) {
119 $.ajax({ url: $(this).data('url'), success: function (sidebarHtml) {
120 startExport(sidebarHtml);
125 if (window.location.pathname == "/export") {
126 $("#exportanchor").click();
129 $("#search_form").submit(function () {
130 var extent = unproj(map.getExtent());
132 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
133 $("#sidebar_content").load($(this).attr("action"), {
134 query: $("#query").val(),
136 minlat: extent.bottom,
137 maxlon: extent.right,
144 if ($("#query").val()) {
145 $("#search_form").submit();