1 $(document).ready(function () {
3 var params = OSM.mapParams();
4 var map = createMap("map");
6 if (!params.object_zoom) {
8 var bbox = new OpenLayers.Bounds(params.minlon, params.minlat, params.maxlon, params.maxlat);
10 map.zoomToExtent(proj(bbox));
13 $(window).load(function() { addBoxToMap(bbox) });
16 setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom);
21 setMapLayers(params.layers);
25 marker = addMarkerToMap(new OpenLayers.LonLat(params.mlon, params.mlat));
29 var url = "/api/" + OSM.API_VERSION + "/" + params.object_type + "/" + params.object_id;
31 if (params.object_type != "node") {
35 $(window).load(function() { addObjectToMap(url, params.object_zoom) });
38 map.events.register("moveend", map, updateLocation);
39 map.events.register("changelayer", map, updateLocation);
44 $("#show_data").click(function (e) {
45 $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
46 startBrowse(sidebarHtml);
51 $("body").on("click", "a.set_position", function () {
52 var data = $(this).data();
53 var centre = new OpenLayers.LonLat(data.lon, data.lat);
55 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
56 var bbox = new OpenLayers.Bounds(data.minLon, data.minLat, data.maxLon, data.maxLat);
58 map.zoomToExtent(proj(bbox));
60 setMapCenter(centre, data.zoom);
64 removeMarkerFromMap(marker);
67 marker = addMarkerToMap(centre, getArrowIcon());
72 function updateLocation() {
73 var lonlat = unproj(map.getCenter());
74 var zoom = map.getZoom();
75 var layers = getMapLayers();
76 var extents = unproj(map.getExtent());
77 var expiry = new Date();
79 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object_type, params.object_id);
81 expiry.setYear(expiry.getFullYear() + 10);
82 $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry});
85 function remoteEditHandler(event) {
86 var extent = unproj(map.getExtent());
89 $("#linkloader").load(function () { loaded = true; });
90 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
92 setTimeout(function () {
93 if (!loaded) alert(I18n.t('site.index.remote_failed'));
99 $("a[data-editor=remote]").click(remoteEditHandler);
101 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
105 $(window).resize(function() {
106 var centre = map.getCenter();
107 var zoom = map.getZoom();
111 map.setCenter(centre, zoom);
114 $("#exportanchor").click(function (e) {
115 $.ajax({ url: $(this).data('url'), success: function (sidebarHtml) {
116 startExport(sidebarHtml);
121 if (window.location.pathname == "/export") {
122 $("#exportanchor").click();
126 if (query = getArgs(window.location.toString()).query) {