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 $("#show_data").click(function (e) {
42 $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
43 startBrowse(sidebarHtml);
48 $("body").on("click", "a.set_position", function () {
49 var data = $(this).data();
50 var centre = new OpenLayers.LonLat(data.lon, data.lat);
52 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
53 var bbox = new OpenLayers.Bounds(data.minLon, data.minLat, data.maxLon, data.maxLat);
55 map.zoomToExtent(proj(bbox));
57 setMapCenter(centre, data.zoom);
61 removeMarkerFromMap(marker);
64 marker = addMarkerToMap(centre, getArrowIcon());
69 function updateLocation() {
70 var lonlat = unproj(map.getCenter());
71 var zoom = map.getZoom();
72 var layers = getMapLayers();
73 var extents = unproj(map.getExtent());
74 var expiry = new Date();
76 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, params.object);
78 expiry.setYear(expiry.getFullYear() + 10);
79 $.cookie("_osm_location", [lonlat.lon, lonlat.lat, zoom, layers].join("|"), {expires: expiry});
82 function remoteEditHandler(event) {
83 var extent = unproj(map.getExtent());
86 $("#linkloader").load(function () { loaded = true; });
87 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
89 setTimeout(function () {
90 if (!loaded) alert(I18n.t('site.index.remote_failed'));
96 $("a[data-editor=remote]").click(remoteEditHandler);
98 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
102 $(window).resize(function() {
103 var centre = map.getCenter();
104 var zoom = map.getZoom();
108 map.setCenter(centre, zoom);
111 $("#search_form").submit(function () {
112 var extent = unproj(map.getExtent());
114 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
115 $("#sidebar_content").load($(this).attr("action"), {
116 query: $("#query").val(),
118 minlat: extent.bottom,
119 maxlon: extent.right,
126 if ($("#query").val()) {
127 $("#search_form").submit();