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 for (var i = 0; i < layers.length; i++) {
23 layers[i].layer = new (layers[i].klass)(layers[i]);
26 layers[0].layer.addTo(map);
28 $("#map").on("resized", function () {
32 L.control.zoom({position: 'topright'})
35 OSM.mapUI().addTo(map);
38 getUrl: function(map) {
39 return setArgs('http://osm.org/', {
40 lon: map.getCenter().lng,
41 lat: map.getCenter().lat
54 L.control.scale().addTo(map);
56 map.on("moveend layeradd layerremove", updateLocation);
58 if (!params.object_zoom) {
60 var bbox = L.latLngBounds([params.minlat, params.minlon],
61 [params.maxlat, params.maxlon]);
73 map.setView([params.lat, params.lon], params.zoom);
78 setMapLayers(params.layers);
82 marker = L.marker([params.mlat, params.mlon], {icon: getUserIcon()}).addTo(map);
86 addObjectToMap(params.object, map, { zoom: params.object_zoom });
91 $("body").on("click", "a.set_position", function (e) {
94 var data = $(this).data();
95 var centre = L.latLng(data.lat, data.lon);
97 if (data.minLon && data.minLat && data.maxLon && data.maxLat) {
98 map.fitBounds([[data.minLat, data.minLon],
99 [data.maxLat, data.maxLon]]);
101 map.setView(centre, data.zoom);
104 if (data.type && data.id) {
105 addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
109 map.removeLayer(marker);
112 marker = L.marker(centre, {icon: getUserIcon()}).addTo(map);
115 function updateLocation() {
116 var center = map.getCenter().wrap();
117 var zoom = map.getZoom();
118 var layers = getMapLayers();
119 var extents = map.getBounds().wrap();
121 updatelinks(center.lng,
131 var expiry = new Date();
132 expiry.setYear(expiry.getFullYear() + 10);
133 $.cookie("_osm_location", [center.lng, center.lat, zoom, layers].join("|"), {expires: expiry});
136 function remoteEditHandler() {
137 var extent = map.getBounds();
140 $("#linkloader").load(function () { loaded = true; });
141 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
142 + "&bottom=" + extent.getSouth()
143 + "&right=" + extent.getEast()
144 + "&top=" + extent.getNorth());
146 setTimeout(function () {
147 if (!loaded) alert(I18n.t('site.index.remote_failed'));
153 $("a[data-editor=remote]").click(remoteEditHandler);
155 if (OSM.preferred_editor == "remote" && $('body').hasClass("site-edit")) {
159 $(window).resize(handleResize);
161 $("#search_form").submit(function () {
162 var bounds = map.getBounds();
164 $("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
165 $("#sidebar_content").load($(this).attr("action"), {
166 query: $("#query").val(),
167 minlon: bounds.getWest(),
168 minlat: bounds.getSouth(),
169 maxlon: bounds.getEast(),
170 maxlat: bounds.getNorth()
176 if ($("#query").val()) {
177 $("#search_form").submit();
180 // Focus the search field for browsers that don't support
181 // the HTML5 'autofocus' attribute
182 if (!("autofocus" in document.createElement("input"))) {
187 function getMapBaseLayer() {
188 for (var i = 0; i < layers.length; i++) {
189 if (map.hasLayer(layers[i].layer)) {
195 function getMapLayers() {
196 var layerConfig = "";
197 for (var i = 0; i < layers.length; i++) {
198 if (map.hasLayer(layers[i].layer)) {
199 layerConfig += layers[i].layerCode;
205 function setMapLayers(layerConfig) {
206 var foundLayer = false;
207 for (var i = 0; i < layers.length; i++) {
208 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
209 map.addLayer(layers[i].layer);
212 map.removeLayer(layers[i].layer);
216 map.addLayer(layers[0].layer);