Unifies some logic, cleans up style.
//= require menu
//= require sidebar
//= require menu
//= require sidebar
+function zoomPrecision(zoom) {
+ var decimals = Math.pow(10, Math.floor(zoom/3));
+ return function(x) {
+ return Math.round(x * decimals) / decimals;
+ };
+}
+
/*
* Called as the user scrolls/zooms around to aniplate hrefs of the
* view tab and various other links
*/
function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,objid) {
/*
* Called as the user scrolls/zooms around to aniplate hrefs of the
* view tab and various other links
*/
function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,objtype,objid) {
- var decimals = Math.pow(10, Math.floor(zoom/3));
+ var toPrecision = zoomPrecision(zoom);
- lat = Math.round(lat * decimals) / decimals;
- lon = Math.round(lon * decimals) / decimals;
+ lat = toPrecision(lat);
+ lon = toPrecision(lon);
- minlon = Math.round(minlon * decimals) / decimals;
- minlat = Math.round(minlat * decimals) / decimals;
- maxlon = Math.round(maxlon * decimals) / decimals;
- maxlat = Math.round(maxlat * decimals) / decimals;
+ minlon = toPrecision(minlon);
+ minlat = toPrecision(minlat);
+ maxlon = toPrecision(maxlon);
+ maxlat = toPrecision(maxlat);
}
$(".geolink").each(function (index, link) {
}
$(".geolink").each(function (index, link) {
function startExport(sidebarHtml) {
function startExport(sidebarHtml) {
- var vectors;
- var box;
- var transform;
- var markerLayer;
- var markerControl;
+ var vectors,
+ box,
+ transform,
+ markerLayer,
+ markerControl,
+ epsg4326 = new OpenLayers.Projection("EPSG:4326"),
+ epsg900913 = new OpenLayers.Projection("EPSG:900913");
vectors = new OpenLayers.Layer.Vector("Vector Layer", {
displayInLayerSwitcher: false
vectors = new OpenLayers.Layer.Vector("Vector Layer", {
displayInLayerSwitcher: false
$("#sidebar_title").html(I18n.t('export.start_rjs.export'));
$("#sidebar_content").html(sidebarHtml);
$("#sidebar_title").html(I18n.t('export.start_rjs.export'));
$("#sidebar_content").html(sidebarHtml);
- $("#maxlat").change(boundsChanged);
- $("#minlon").change(boundsChanged);
- $("#maxlon").change(boundsChanged);
- $("#minlat").change(boundsChanged);
+ $("#maxlat,#minlon,#maxlon,#minlat").change(boundsChanged);
$("#drag_box").click(startDrag);
$("#add_marker").click(startMarker);
$("#drag_box").click(startDrag);
$("#add_marker").click(startMarker);
- $("#format_osm").click(formatChanged);
- $("#format_mapnik").click(formatChanged);
- $("#format_html").click(formatChanged);
+ $("#format_osm,#format_mapnik,#format_html").click(formatChanged);
$("#mapnik_scale").change(mapnikSizeChanged);
$("#mapnik_scale").change(mapnikSizeChanged);
map.removeLayer(vectors);
}
map.removeLayer(vectors);
}
- function boundsChanged() {
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ function getMercatorBounds() {
var bounds = new OpenLayers.Bounds($("#minlon").val(), $("#minlat").val(),
$("#maxlon").val(), $("#maxlat").val());
var bounds = new OpenLayers.Bounds($("#minlon").val(), $("#minlat").val(),
$("#maxlon").val(), $("#maxlat").val());
- bounds.transform(epsg4326, map.getProjectionObject());
+ return bounds.transform(epsg4326, epsg900913);
+ }
+
+ function boundsChanged() {
+ var bounds = getMercatorBounds();
map.events.unregister("moveend", map, mapMoved);
map.zoomToExtent(bounds);
map.events.unregister("moveend", map, mapMoved);
map.zoomToExtent(bounds);
$("#add_marker").html(I18n.t('export.start_rjs.change_marker'));
$("#marker_inputs").show();
$("#add_marker").html(I18n.t('export.start_rjs.change_marker'));
$("#marker_inputs").show();
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
- var epsg900913 = new OpenLayers.Projection("EPSG:900913");
var geom = event.feature.geometry.clone().transform(epsg900913, epsg4326);
$("#marker_lon").val(geom.x.toFixed(5));
var geom = event.feature.geometry.clone().transform(epsg900913, epsg4326);
$("#marker_lon").val(geom.x.toFixed(5));
}
function clearMarker() {
}
function clearMarker() {
- $("#marker_lon").val("");
- $("#marker_lat").val("");
+ $("#marker_lon,#marker_lat").val("");
$("#marker_inputs").hide();
$("#add_marker").html(I18n.t('export.start_rjs.add_marker'));
$("#marker_inputs").hide();
$("#add_marker").html(I18n.t('export.start_rjs.add_marker'));
}
function setBounds(bounds) {
}
function setBounds(bounds) {
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
- var decimals = Math.pow(10, Math.floor(map.getZoom() / 3));
+ var toPrecision = zoomPrecision(map.getZoom());
bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
bounds = bounds.clone().transform(map.getProjectionObject(), epsg4326);
- $("#minlon").val(Math.round(bounds.left * decimals) / decimals);
- $("#minlat").val(Math.round(bounds.bottom * decimals) / decimals);
- $("#maxlon").val(Math.round(bounds.right * decimals) / decimals);
- $("#maxlat").val(Math.round(bounds.top * decimals) / decimals);
+ $("#minlon").val(toPrecision(bounds.left));
+ $("#minlat").val(toPrecision(bounds.bottom));
+ $("#maxlon").val(toPrecision(bounds.right));
+ $("#maxlat").val(toPrecision(bounds.top));
mapnikSizeChanged();
htmlUrlChanged();
mapnikSizeChanged();
htmlUrlChanged();
// Create "larger map" link
var center = bounds.getCenterLonLat();
// Create "larger map" link
var center = bounds.getCenterLonLat();
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
- var epsg900913 = new OpenLayers.Projection("EPSG:900913");
bounds.transform(epsg4326, epsg900913);
var zoom = map.getZoomForExtent(bounds);
bounds.transform(epsg4326, epsg900913);
var zoom = map.getZoomForExtent(bounds);
}
function maxMapnikScale() {
}
function maxMapnikScale() {
- var bounds = new OpenLayers.Bounds($("#minlon").val(), $("#minlat").val(), $("#maxlon").val(), $("#maxlat").val());
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
- var epsg900913 = new OpenLayers.Projection("EPSG:900913");
-
- bounds.transform(epsg4326, epsg900913);
+ var bounds = getMercatorBounds();
return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
}
function mapnikImageSize(scale) {
return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
}
function mapnikImageSize(scale) {
- var bounds = new OpenLayers.Bounds($("#minlon").val(), $("#minlat").val(), $("#maxlon").val(), $("#maxlat").val());
- var epsg4326 = new OpenLayers.Projection("EPSG:4326");
- var epsg900913 = new OpenLayers.Projection("EPSG:900913");
-
- bounds.transform(epsg4326, epsg900913);
+ var bounds = getMercatorBounds();
return new OpenLayers.Size(Math.round(bounds.getWidth() / scale / 0.00028),
Math.round(bounds.getHeight() / scale / 0.00028));
return new OpenLayers.Size(Math.round(bounds.getWidth() / scale / 0.00028),
Math.round(bounds.getHeight() / scale / 0.00028));