2 //= require index/browse
3 //= require index/export
5 //= require index/notes
6 //= require index/map_ui
8 $(document).ready(function () {
9 var permalinks = $("#permalink").detach().html();
11 var params = OSM.mapParams();
12 var map = createMap("map", {
19 L.control.zoom({position: 'topright'})
22 OSM.mapUI().addTo(map);
25 getUrl: function(map) {
26 return setArgs('http://osm.org/', {
27 lon: map.getCenter().lng,
28 lat: map.getCenter().lat
37 L.control.scale().addTo(map);
39 map.attributionControl.setPrefix(permalinks);
41 map.on("moveend layeradd layerremove", updateLocation);
43 if (!params.object_zoom) {
45 var bbox = L.latLngBounds([params.minlat, params.minlon],
46 [params.maxlat, params.maxlon]);
58 map.setView([params.lat, params.lon], params.zoom);
63 setMapLayers(params.layers);
67 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
71 addObjectToMap(params.object, { zoom: params.object_zoom });
76 $("body").on("click", "a.set_position", function (e) {
79 var data = $(this).data();
80 var centre = L.latLng(data.lat, data.lon);
82 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
83 map.fitBounds([[data.minLat, data.minLon],
84 [data.maxLat, data.maxLon]]);
86 map.setView(centre, data.zoom);
89 if (data.type && data.id) {
90 addObjectToMap(data, { zoom: true, style: { opacity: 0.2, fill: false } });
94 map.removeLayer(marker);
97 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
100 function updateLocation() {
101 var center = map.getCenter().wrap();
102 var zoom = map.getZoom();
103 var layers = getMapLayers();
104 var extents = map.getBounds().wrap();
106 updatelinks(center.lng,
116 var expiry = new Date();
117 expiry.setYear(expiry.getFullYear() + 10);
118 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
121 function remoteEditHandler() {
122 var extent = map.getBounds();
125 $("#linkloader").load(function () { loaded = true; });
126 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
127 + "&bottom=" + extent.getSouth()
128 + "&right=" + extent.getEast()
129 + "&top=" + extent.getNorth());
131 setTimeout(function () {
132 if (!loaded) alert(I18n.t('site.index.remote_failed'));
138 $("a[data-editor=remote]").click(remoteEditHandler);
140 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
144 $(window).resize(handleResize);
146 $("#search_form").submit(function () {
147 var bounds = map.getBounds();
149 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
150 $("#sidebar_content").load($(this).attr("action"), {
151 query: $("#query").val(),
152 minlon: bounds.getWest(),
153 minlat: bounds.getSouth(),
154 maxlon: bounds.getEast(),
155 maxlat: bounds.getNorth()
161 if ($("#query").val()) {
162 $("#search_form").submit();
165 // Focus the search field for browsers that don't support
166 // the HTML5 'autofocus' attribute
167 if (!("autofocus" in document.createElement("input"))) {