Replace various Leaflet extensions with new builtin methods
This commit is contained in:
parent
39c0df691e
commit
168a9fc327
6 changed files with 35 additions and 71 deletions
|
@ -1,9 +1,9 @@
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
function remoteEditHandler(bbox, select) {
|
function remoteEditHandler(bbox, select) {
|
||||||
var left = bbox.getWestLng() - 0.0001;
|
var left = bbox.getWest() - 0.0001;
|
||||||
var top = bbox.getNorthLat() + 0.0001;
|
var top = bbox.getNorth() + 0.0001;
|
||||||
var right = bbox.getEastLng() + 0.0001;
|
var right = bbox.getEast() + 0.0001;
|
||||||
var bottom = bbox.getSouthLat() - 0.0001;
|
var bottom = bbox.getSouth() - 0.0001;
|
||||||
var loaded = false;
|
var loaded = false;
|
||||||
|
|
||||||
$("#linkloader").load(function () { loaded = true; });
|
$("#linkloader").load(function () { loaded = true; });
|
||||||
|
@ -61,8 +61,8 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
updatelinks(params.lon, params.lat, 16, null,
|
updatelinks(params.lon, params.lat, 16, null,
|
||||||
bbox.getWestLng(), bbox.getSouthLat(),
|
bbox.getWest(), bbox.getSouth(),
|
||||||
bbox.getEastLng(), bbox.getNorthLat(),
|
bbox.getEast(), bbox.getNorth(),
|
||||||
object);
|
object);
|
||||||
} else {
|
} else {
|
||||||
$("#object_larger_map").hide();
|
$("#object_larger_map").hide();
|
||||||
|
@ -94,10 +94,10 @@ $(document).ready(function () {
|
||||||
updatelinks(centre.lng,
|
updatelinks(centre.lng,
|
||||||
centre.lat,
|
centre.lat,
|
||||||
16, null,
|
16, null,
|
||||||
extent.getWestLng(),
|
extent.getWest(),
|
||||||
extent.getSouthLat(),
|
extent.getSouth(),
|
||||||
extent.getEastLng(),
|
extent.getEast(),
|
||||||
extent.getNorthLat(),
|
extent.getNorth(),
|
||||||
object);
|
object);
|
||||||
} else {
|
} else {
|
||||||
$("#small_map").hide();
|
$("#small_map").hide();
|
||||||
|
|
|
@ -79,10 +79,10 @@ $(document).ready(function () {
|
||||||
center.lat,
|
center.lat,
|
||||||
zoom,
|
zoom,
|
||||||
layers,
|
layers,
|
||||||
extents.getWestLng(),
|
extents.getWest(),
|
||||||
extents.getSouthLat(),
|
extents.getSouth(),
|
||||||
extents.getEastLng(),
|
extents.getEast(),
|
||||||
extents.getNorthLat(),
|
extents.getNorth(),
|
||||||
params.object);
|
params.object);
|
||||||
|
|
||||||
var expiry = new Date();
|
var expiry = new Date();
|
||||||
|
@ -95,10 +95,10 @@ $(document).ready(function () {
|
||||||
var loaded = false;
|
var loaded = false;
|
||||||
|
|
||||||
$("#linkloader").load(function () { loaded = true; });
|
$("#linkloader").load(function () { loaded = true; });
|
||||||
$("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWestLng()
|
$("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.getWest()
|
||||||
+ "&bottom=" + extent.getSouthLat()
|
+ "&bottom=" + extent.getSouth()
|
||||||
+ "&right=" + extent.getEastLng()
|
+ "&right=" + extent.getEast()
|
||||||
+ "&top=" + extent.getNorthLat());
|
+ "&top=" + extent.getNorth());
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
if (!loaded) alert(I18n.t('site.index.remote_failed'));
|
if (!loaded) alert(I18n.t('site.index.remote_failed'));
|
||||||
|
@ -121,10 +121,10 @@ $(document).ready(function () {
|
||||||
$("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
|
$("#sidebar_title").html(I18n.t('site.sidebar.search_results'));
|
||||||
$("#sidebar_content").load($(this).attr("action"), {
|
$("#sidebar_content").load($(this).attr("action"), {
|
||||||
query: $("#query").val(),
|
query: $("#query").val(),
|
||||||
minlon: bounds.getWestLng(),
|
minlon: bounds.getWest(),
|
||||||
minlat: bounds.getSouthLat(),
|
minlat: bounds.getSouth(),
|
||||||
maxlon: bounds.getEastLng(),
|
maxlon: bounds.getEast(),
|
||||||
maxlat: bounds.getNorthLat()
|
maxlat: bounds.getNorth()
|
||||||
}, openSidebar);
|
}, openSidebar);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -151,7 +151,7 @@ $(document).ready(function () {
|
||||||
|
|
||||||
setStatus(I18n.t('browse.start_rjs.loading'));
|
setStatus(I18n.t('browse.start_rjs.loading'));
|
||||||
|
|
||||||
var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBOX();
|
var url = "/api/" + OSM.API_VERSION + "/map?bbox=" + bounds.toBBoxString();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Modern browsers are quite happy showing far more than 100 features in
|
* Modern browsers are quite happy showing far more than 100 features in
|
||||||
|
|
|
@ -67,7 +67,7 @@ $(document).ready(function () {
|
||||||
var bounds = map.getBounds(),
|
var bounds = map.getBounds(),
|
||||||
centerLat = bounds.getCenter().lat,
|
centerLat = bounds.getCenter().lat,
|
||||||
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
|
halfWorldMeters = 6378137 * Math.PI * Math.cos(centerLat * Math.PI / 180),
|
||||||
meters = halfWorldMeters * (bounds.getNorthEast().lng - bounds.getSouthWest().lng) / 180,
|
meters = halfWorldMeters * (bounds.getEast() - bounds.getWest()) / 180,
|
||||||
pixelsPerMeter = map.getSize().x / meters,
|
pixelsPerMeter = map.getSize().x / meters,
|
||||||
metersPerPixel = 1 / (92 * 39.3701);
|
metersPerPixel = 1 / (92 * 39.3701);
|
||||||
return Math.round(1 / (pixelsPerMeter * metersPerPixel));
|
return Math.round(1 / (pixelsPerMeter * metersPerPixel));
|
||||||
|
@ -152,10 +152,10 @@ $(document).ready(function () {
|
||||||
function setBounds(bounds) {
|
function setBounds(bounds) {
|
||||||
var toPrecision = zoomPrecision(map.getZoom());
|
var toPrecision = zoomPrecision(map.getZoom());
|
||||||
|
|
||||||
$("#minlon").val(toPrecision(bounds.getWestLng()));
|
$("#minlon").val(toPrecision(bounds.getWest()));
|
||||||
$("#minlat").val(toPrecision(bounds.getSouthLat()));
|
$("#minlat").val(toPrecision(bounds.getSouth()));
|
||||||
$("#maxlon").val(toPrecision(bounds.getEastLng()));
|
$("#maxlon").val(toPrecision(bounds.getEast()));
|
||||||
$("#maxlat").val(toPrecision(bounds.getNorthLat()));
|
$("#maxlat").val(toPrecision(bounds.getNorth()));
|
||||||
|
|
||||||
mapnikSizeChanged();
|
mapnikSizeChanged();
|
||||||
htmlUrlChanged();
|
htmlUrlChanged();
|
||||||
|
@ -188,7 +188,7 @@ $(document).ready(function () {
|
||||||
var bounds = getBounds();
|
var bounds = getBounds();
|
||||||
var layerName = getMapBaseLayer().keyid;
|
var layerName = getMapBaseLayer().keyid;
|
||||||
|
|
||||||
var url = "http://" + OSM.SERVER_URL + "/export/embed.html?bbox=" + bounds.toBBOX() + "&layer=" + layerName;
|
var url = "http://" + OSM.SERVER_URL + "/export/embed.html?bbox=" + bounds.toBBoxString() + "&layer=" + layerName;
|
||||||
var markerUrl = "";
|
var markerUrl = "";
|
||||||
|
|
||||||
if ($("#marker_lat").val() && $("#marker_lon").val()) {
|
if ($("#marker_lat").val() && $("#marker_lon").val()) {
|
||||||
|
@ -254,16 +254,16 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function maxMapnikScale() {
|
function maxMapnikScale() {
|
||||||
var bounds = getMercatorBounds();
|
var size = getMercatorBounds().getSize();
|
||||||
|
|
||||||
return Math.floor(Math.sqrt(bounds.getWidth() * bounds.getHeight() / 0.3136));
|
return Math.floor(Math.sqrt(size.x * size.y / 0.3136));
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapnikImageSize(scale) {
|
function mapnikImageSize(scale) {
|
||||||
var bounds = getMercatorBounds();
|
var size = getMercatorBounds().getSize();
|
||||||
|
|
||||||
return {w: Math.round(bounds.getWidth() / scale / 0.00028),
|
return {w: Math.round(size.x / scale / 0.00028),
|
||||||
h: Math.round(bounds.getHeight() / scale / 0.00028)};
|
h: Math.round(size.y / scale / 0.00028)};
|
||||||
}
|
}
|
||||||
|
|
||||||
function roundScale(scale) {
|
function roundScale(scale) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ $(document).ready(function () {
|
||||||
var size = bounds.getSize();
|
var size = bounds.getSize();
|
||||||
|
|
||||||
if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
|
if (size <= OSM.MAX_NOTE_REQUEST_AREA) {
|
||||||
var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBOX();
|
var url = "/api/" + OSM.API_VERSION + "/notes.json?bbox=" + bounds.toBBoxString();
|
||||||
|
|
||||||
if (noteLoader) noteLoader.abort();
|
if (noteLoader) noteLoader.abort();
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,5 @@
|
||||||
// Leaflet extensions
|
// Leaflet extensions
|
||||||
L.extend(L.LatLngBounds.prototype, {
|
L.extend(L.LatLngBounds.prototype, {
|
||||||
getSouthLat: function () {
|
|
||||||
return this._southWest.lat;
|
|
||||||
},
|
|
||||||
|
|
||||||
getWestLng: function () {
|
|
||||||
return this._southWest.lng;
|
|
||||||
},
|
|
||||||
|
|
||||||
getNorthLat: function () {
|
|
||||||
return this._northEast.lat;
|
|
||||||
},
|
|
||||||
|
|
||||||
getEastLng: function () {
|
|
||||||
return this._northEast.lng;
|
|
||||||
},
|
|
||||||
|
|
||||||
toBBOX: function () {
|
|
||||||
var decimal = 6;
|
|
||||||
var mult = Math.pow(10, decimal);
|
|
||||||
var xmin = Math.round(this.getWestLng() * mult) / mult;
|
|
||||||
var ymin = Math.round(this.getSouthLat() * mult) / mult;
|
|
||||||
var xmax = Math.round(this.getEastLng() * mult) / mult;
|
|
||||||
var ymax = Math.round(this.getNorthLat() * mult) / mult;
|
|
||||||
return xmin + "," + ymin + "," + xmax + "," + ymax;
|
|
||||||
},
|
|
||||||
|
|
||||||
getSize: function () {
|
getSize: function () {
|
||||||
return (this._northEast.lat - this._southWest.lat) *
|
return (this._northEast.lat - this._southWest.lat) *
|
||||||
(this._northEast.lng - this._southWest.lng);
|
(this._northEast.lng - this._southWest.lng);
|
||||||
|
@ -36,16 +10,6 @@ L.extend(L.LatLngBounds.prototype, {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
L.extend(L.Bounds.prototype, {
|
|
||||||
getWidth: function () {
|
|
||||||
return this.max.x - this.min.x;
|
|
||||||
},
|
|
||||||
|
|
||||||
getHeight: function () {
|
|
||||||
return this.max.y - this.min.y;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
|
L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
|
||||||
|
|
||||||
var map;
|
var map;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue