2 //= require index/browse
3 //= require index/export
5 //= require index/notes
6 //= require index/map_ui
8 var map, layers; // TODO: remove globals
10 $(document).ready(function () {
12 var params = OSM.mapParams();
15 attributionControl: false,
22 layers[0].layer.addTo(map);
24 $("#map").on("resized", function () {
28 L.control.zoom({position: 'topright'})
31 OSM.mapUI().addTo(map);
34 getUrl: function(map) {
35 return setArgs('http://osm.org/', {
36 lon: map.getCenter().lng,
37 lat: map.getCenter().lat
50 L.control.scale().addTo(map);
52 map.on("moveend layeradd layerremove", updateLocation);
54 if (!params.object_zoom) {
56 var bbox = L.latLngBounds([params.minlat, params.minlon],
57 [params.maxlat, params.maxlon]);
69 map.setView([params.lat, params.lon], params.zoom);
74 setMapLayers(params.layers);
78 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
82 addObjectToMap(params.object, map, { zoom: params.object_zoom });
87 $("body").on("click", "a.set_position", function (e) {
90 var data = $(this).data();
91 var centre = L.latLng(data.lat, data.lon);
93 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
94 map.fitBounds([[data.minLat, data.minLon],
95 [data.maxLat, data.maxLon]]);
97 map.setView(centre, data.zoom);
100 if (data.type && data.id) {
101 addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
105 map.removeLayer(marker);
108 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
111 function updateLocation() {
112 var center = map.getCenter().wrap();
113 var zoom = map.getZoom();
114 var layers = getMapLayers();
115 var extents = map.getBounds().wrap();
117 updatelinks(center.lng,
127 var expiry = new Date();
128 expiry.setYear(expiry.getFullYear() + 10);
129 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
132 function remoteEditHandler() {
133 var extent = map.getBounds();
136 $("#linkloader").load(function () { loaded = true; });
137 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
138 + "&bottom=" + extent.getSouth()
139 + "&right=" + extent.getEast()
140 + "&top=" + extent.getNorth());
142 setTimeout(function () {
143 if (!loaded) alert(I18n.t('site.index.remote_failed'));
149 $("a[data-editor=remote]").click(remoteEditHandler);
151 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
155 $(window).resize(handleResize);
157 $("#search_form").submit(function () {
158 var bounds = map.getBounds();
160 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
161 $("#sidebar_content").load($(this).attr("action"), {
162 query: $("#query").val(),
163 minlon: bounds.getWest(),
164 minlat: bounds.getSouth(),
165 maxlon: bounds.getEast(),
166 maxlat: bounds.getNorth()
172 if ($("#query").val()) {
173 $("#search_form").submit();
176 // Focus the search field for browsers that don't support
177 // the HTML5 'autofocus' attribute
178 if (!("autofocus" in document.createElement("input"))) {
183 function getMapBaseLayer() {
184 for (var i = 0; i < layers.length; i++) {
185 if (map.hasLayer(layers[i].layer)) {
191 function getMapLayers() {
192 var layerConfig = "";
193 for (var i = 0; i < layers.length; i++) {
194 if (map.hasLayer(layers[i].layer)) {
195 layerConfig += layers[i].layerCode;
201 function setMapLayers(layerConfig) {
202 var foundLayer = false;
203 for (var i = 0; i < layers.length; i++) {
204 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
205 map.addLayer(layers[i].layer);
208 map.removeLayer(layers[i].layer);
212 map.addLayer(layers[0].layer);