From 339c7ec21ee6bcd4c3ea8e7d947f035daa3b7e63 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Mon, 13 May 2013 01:10:18 +0100 Subject: [PATCH] add utility functions to clamp latitude to +-90.0, and longitude to +-180.0 --- code/utils_misc.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/code/utils_misc.js b/code/utils_misc.js index 95329149..8cd14518 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -407,3 +407,30 @@ window.addLayerGroup = function(name, layerGroup, defaultDisplay) { if(isLayerGroupDisplayed(name, defaultDisplay)) map.addLayer(layerGroup); layerChooser.addOverlay(layerGroup, name); } + + + +window.clampLat = function(lat) { + if (lat > 90.0) + lat = 90.0; + else if (lat < -90.0) + lat = -90.0; + return lat; +} + +window.clampLng = function(lng) { + if (lng > 180.0) + lng = 180.0 + else if (lng < -180.0) + lng = -180.0; + return lng; +} + + +window.clampLatLng = function(latlng) { + return new L.LatLng ( clampLat(latlng.lat), clampLng(latlng.lng) ); +} + +window.clampLatLngBounds = function(bounds) { + return new L.LatLngBounds ( clampLatLng(bounds.getSouthWest()), clampLatLng(bounds.getNorthEast()) ); +}