-
-<script type="text/javascript">
- var marker;
- var map;
-
- function mapInit(){
- map = createMap("map");
-
- <% unless object_zoom %>
- <% if bbox %>
- var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
-
- map.zoomToExtent(proj(bbox));
-
- <% if box %>
- $(window).load(function() { addBoxToMap(bbox) });
- <% end %>
- <% else %>
- var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
- <% if params[:scale].to_f > 0 then -%>
- var zoom = <%= scale_to_zoom params[:scale] %>;
- <% else -%>
- var zoom = <%= zoom %>;
- <% end -%>
-
- setMapCenter(centre, zoom);
- <% end %>
- <% end %>
-
- <% if !layers.nil? and !layers.empty? %>
- setMapLayers("<%= layers %>");
- <% end %>
-
- <% if marker %>
- marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
- <% end %>
-
- <% if object %>
- var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
-
- <% if object_type != "node" %>
- url += "/full";
- <% end %>
-
- $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
- <% end %>
-
- map.events.register("moveend", map, updateLocation);
- map.events.register("changelayer", map, updateLocation);
-
- updateLocation();
- handleResize();
- }
-
- $(document).ready(function () {
- $("#show_data").click(function (e) {
- $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
- startBrowse(sidebarHtml);
- }});
- e.preventDefault();
- });
-
- $("body").on("click", "a.set_position", function () {
- var lat = parseFloat($(this).attr("data-lat"));
- var lon = parseFloat($(this).attr("data-lon"));
- var zoom = parseInt($(this).attr("data-zoom"));
- var min_lon = parseFloat($(this).attr("data-min-lon"));
- var min_lat = parseFloat($(this).attr("data-min-lat"));
- var max_lon = parseFloat($(this).attr("data-max-lon"));
- var max_lat = parseFloat($(this).attr("data-max-lat"));
- var centre = new OpenLayers.LonLat(lon, lat);
-
- if (min_lon && min_lat && max_lon && max_lat) {
- var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
-
- map.zoomToExtent(proj(bbox));
- } else {
- setMapCenter(centre, zoom);
- }
-
- if (marker) {
- removeMarkerFromMap(marker);
- }
-
- marker = addMarkerToMap(centre, getArrowIcon());
-
- return false;
- });
- });
-
- function updateLocation() {
- var lonlat = unproj(map.getCenter());
- var zoom = map.getZoom();
- var layers = getMapLayers();
- var extents = unproj(map.getExtent());
- var expiry = new Date();
- var objtype;
- var objid;
-
- <% if object %>
- objtype = "<%= object_type %>";
- objid = <%= object_id %>;
- <% end %>
-
- updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
-
- expiry.setYear(expiry.getFullYear() + 10);
- document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
- }
-
- function remoteEditHandler(event) {
- var extent = unproj(map.getExtent());
- var loaded = false;
-
- $("#linkloader").load(function () { loaded = true; });
- $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
-
- setTimeout(function () {
- if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
- }, 1000);
-
- return false;
- }
-
- function installEditHandler() {
- $("#remoteanchor").click(remoteEditHandler);
-
- <% if preferred_editor == "remote" %>
- $("#editanchor").click(remoteEditHandler);
-
- <% if params[:action] == "edit" %>
- remoteEditHandler();
- <% end %>
- <% end %>
- }
-
- $(document).ready(mapInit);
- $(document).ready(installEditHandler);
- $(document).ready(handleResize);
-
- $(window).resize(function() {
- var centre = map.getCenter();
- var zoom = map.getZoom();
-
- handleResize();
-
- map.setCenter(centre, zoom);
- });
-
- $(document).ready(function () {
- $("#exportanchor").click(function (e) {
- $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>", success: function (sidebarHtml) {
- startExport(sidebarHtml);
- }});
- e.preventDefault();
- });
-
- <% if params[:export] -%>
- $("#exportanchor").click();
- <% end -%>
-
- <% if params[:query] -%>
- doSearch("<%= params[:query] %>");
- <% end %>
- });
-// -->
-</script>