1 //= require index/browse
2 //= require index/export
4 //= require index/notes
6 $(document).ready(function () {
8 var params = OSM.mapParams();
9 var map = createMap("map");
11 map.events.register("moveend", map, updateLocation);
12 map.events.register("changelayer", map, updateLocation);
14 if (!params.object_zoom) {
16 var bbox = new OpenLayers.Bounds(params.minlon, params.minlat, params.maxlon, params.maxlat);
18 map.zoomToExtent(proj(bbox));
24 setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom);
29 setMapLayers(params.layers);
33 marker = addMarkerToMap(new OpenLayers.LonLat(params.mlon, params.mlat));
37 addObjectToMap(params.object, params.object_zoom);
42 $("body").on("click", "a.set_position", function () {
43 var data = $(this).data();
44 var centre = new OpenLayers.LonLat(data.lon, data.lat);
46 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
47 var bbox = new OpenLayers.Bounds(data.minLon, data.minLat, data.maxLon, data.maxLat);
49 map.zoomToExtent(proj(bbox));
51 setMapCenter(centre, data.zoom);
55 removeMarkerFromMap(marker);
58 marker = addMarkerToMap(centre, getArrowIcon());
63 function updateLocation() {
64 var lonlat = unproj(map.getCenter());
65 var zoom = map.getZoom();
66 var layers = getMapLayers();
67 var extents = unproj(map.getExtent());
68 var expiry = new Date();
70 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object);
72 expiry.setYear(expiry.getFullYear() + 10);
73 $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry});
76 function remoteEditHandler(event) {
77 var extent = unproj(map.getExtent());
80 $("#linkloader").load(function () { loaded = true; });
81 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
83 setTimeout(function () {
84 if (!loaded) alert(I18n.t('site.index.remote_failed'));
90 $("a[data-editor=remote]").click(remoteEditHandler);
92 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
96 $(window).resize(function() {
97 var centre = map.getCenter();
98 var zoom = map.getZoom();
102 map.setCenter(centre, zoom);
105 $("#search_form").submit(function () {
106 var extent = unproj(map.getExtent());
108 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
109 $("#sidebar_content").load($(this).attr("action"), {
110 query: $("#query").val(),
112 minlat: extent.bottom,
113 maxlon: extent.right,
120 if ($("#query").val()) {
121 $("#search_form").submit();