Even more map ui js refactor

This commit is contained in:
Tom MacWright 2013-06-10 14:38:08 -07:00 committed by John Firebaugh
parent 7c06f2b47e
commit 7bcea3839d
5 changed files with 37 additions and 37 deletions

View file

@ -27,22 +27,30 @@ function zoomPrecision(zoom) {
};
}
function normalBounds(bounds) {
if (bounds instanceof L.LatLngBounds) return bounds;
return new L.LatLngBounds(
new L.LatLng(bounds[0][0], bounds[0][1]),
new L.LatLng(bounds[1][0], bounds[1][1]));
}
/*
* Called as the user scrolls/zooms around to aniplate hrefs of the
* Called as the user scrolls/zooms around to maniplate hrefs of the
* view tab and various other links
*/
function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object) {
function updatelinks(loc, zoom, layers, bounds, object) {
var toPrecision = zoomPrecision(zoom);
bounds = normalBounds(bounds);
var node;
var lat = toPrecision(loc.lat),
lon = toPrecision(loc.lon || loc.lng);
if (minlon) {
minlon = toPrecision(minlon);
minlat = toPrecision(minlat);
maxlon = toPrecision(maxlon);
maxlat = toPrecision(maxlat);
if (bounds) {
var minlon = toPrecision(bounds.getWest()),
minlat = toPrecision(bounds.getSouth()),
maxlon = toPrecision(bounds.getEast()),
maxlat = toPrecision(bounds.getNorth());
}
$(".geolink").each(setGeolink);
@ -52,11 +60,15 @@ function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object)
var args = getArgs(link.href);
if ($(link).hasClass("llz")) {
args.lat = lat;
args.lon = lon;
args.zoom = zoom;
$.extend(args, {
lat: lat,
lon: lon,
zoom: zoom
});
} else if (minlon && $(link).hasClass("bbox")) {
args.bbox = minlon + "," + minlat + "," + maxlon + "," + maxlat;
$.extend(args, {
bbox: minlon + "," + minlat + "," + maxlon + "," + maxlat
});
}
if (layers && $(link).hasClass("layers")) {
@ -86,9 +98,6 @@ function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object)
link.href = setArgs(link.href, args);
}
function minZoomAlert() {
alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
}
function setShortlink() {
var args = getArgs(this.href);
@ -103,8 +112,7 @@ function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object)
// This is a hack to omit the default mapnik layer from the shortlink.
if (layers && layers != "M") {
args.layers = layers;
}
else {
} else {
delete args.layers;
}
@ -120,6 +128,10 @@ function updatelinks(loc, zoom, layers, minlon, minlat, maxlon, maxlat, object)
}
}
function minZoomAlert() {
alert(I18n.t("javascripts.site." + name + "_zoom_alert")); return false;
}
/*
* Get the URL prefix to use for a short link
*/

View file

@ -54,7 +54,8 @@ $(document).ready(function () {
return remoteEditHandler(bbox);
});
updatelinks(map.getCenter(), 16, null, params.minlon, params.minlat, params.maxlon, params.maxlat);
updatelinks(map.getCenter(), 16, null, [[params.minlat, params.minlon],
[params.maxlat, params.maxlon]]);
} else if (params.type == "note") {
object = {type: params.type, id: params.id};
@ -102,13 +103,7 @@ $(document).ready(function () {
$("#object_larger_map").show();
$("#object_edit").show();
updatelinks(map.getCenter(),
16, null,
extent.getWest(),
extent.getSouth(),
extent.getEast(),
extent.getNorth(),
object);
updatelinks(map.getCenter(), 16, null, extent, object);
} else {
$("#small_map").hide();
}

View file

@ -114,14 +114,7 @@ $(document).ready(function () {
var layers = getMapLayers();
var extents = map.getBounds().wrap();
updatelinks(center,
zoom,
layers,
extents.getWest(),
extents.getSouth(),
extents.getEast(),
extents.getNorth(),
params.object);
updatelinks(center, zoom, layers, extents, params.object);
var expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);

View file

@ -86,6 +86,6 @@
});
function mapMoved(lon, lat, zoom, minlon, minlat, maxlon, maxlat) {
updatelinks({ lon: lon, lat: lat }, zoom, null, minlon, minlat, maxlon, maxlat);
updatelinks({ lon: lon, lat: lat }, zoom, null, [[minlat, minlon], [maxlat, maxlon]]);
}
</script>

View file

@ -42,10 +42,10 @@
},
zoom,
null,
extent[0][0],
extent[0][1],
extent[1][0],
extent[1][1]);
[[extent[0][1],
extent[0][0]],
[extent[1][1],
extent[1][0]]]);
});
parent.$("body").on("click", "a.set_position", function (e) {