1 //= require index/browse
2 //= require index/export
5 $(document).ready(function () {
7 var params = OSM.mapParams();
8 var map = createMap("map");
10 map.events.register("moveend", map, updateLocation);
11 map.events.register("changelayer", map, updateLocation);
13 if (!params.object_zoom) {
15 var bbox = new OpenLayers.Bounds(params.minlon, params.minlat, params.maxlon, params.maxlat);
17 map.zoomToExtent(proj(bbox));
23 setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom);
28 setMapLayers(params.layers);
32 marker = addMarkerToMap(new OpenLayers.LonLat(params.mlon, params.mlat));
36 addObjectToMap(params.object, params.object_zoom);
41 $("body").on("click", "a.set_position", function () {
42 var data = $(this).data();
43 var centre = new OpenLayers.LonLat(data.lon, data.lat);
45 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
46 var bbox = new OpenLayers.Bounds(data.minLon, data.minLat, data.maxLon, data.maxLat);
48 map.zoomToExtent(proj(bbox));
50 setMapCenter(centre, data.zoom);
54 removeMarkerFromMap(marker);
57 marker = addMarkerToMap(centre, getArrowIcon());
62 function updateLocation() {
63 var lonlat = unproj(map.getCenter());
64 var zoom = map.getZoom();
65 var layers = getMapLayers();
66 var extents = unproj(map.getExtent());
67 var expiry = new Date();
69 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object);
71 expiry.setYear(expiry.getFullYear() + 10);
72 $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry});
75 function remoteEditHandler(event) {
76 var extent = unproj(map.getExtent());
79 $("#linkloader").load(function () { loaded = true; });
80 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
82 setTimeout(function () {
83 if (!loaded) alert(I18n.t('site.index.remote_failed'));
89 $("a[data-editor=remote]").click(remoteEditHandler);
91 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
95 $(window).resize(function() {
96 var centre = map.getCenter();
97 var zoom = map.getZoom();
101 map.setCenter(centre, zoom);
104 $("#search_form").submit(function () {
105 var extent = unproj(map.getExtent());
107 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
108 $("#sidebar_content").load($(this).attr("action"), {
109 query: $("#query").val(),
111 minlat: extent.bottom,
112 maxlon: extent.right,
119 if ($("#query").val()) {
120 $("#search_form").submit();