Skip to content

Commit

Permalink
removed some use of magic numbers in code
Browse files Browse the repository at this point in the history
  • Loading branch information
DanieSimonlLowe committed Jan 21, 2021
1 parent 7bf5c60 commit 2a93b16
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var CLI_Cookie={
set: function (name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
date.setTime(date.getTime() + TimeUnit.DAYS.toMillis(days));
var expires = "; expires=" + date.toGMTString();
} else
var expires = "";
Expand Down Expand Up @@ -388,7 +388,7 @@ var CLI=
},
add_clear_cache_url_query:function()
{
var cli_rand=new Date().getTime()/1000;
var cli_rand=new TimeUnit.Millis.toSECONDS(Date().getTime());
var cli_url=window.location.href;
var cli_hash_arr=cli_url.split('#');
var cli_urlparts= cli_hash_arr[0].split('?');
Expand Down Expand Up @@ -480,10 +480,11 @@ var CLI=
barAsWidget:function(a)
{
var cli_elm=this.bar_elm;
var cli_win=jQuery(window);
var cli_winh=cli_win.height()-40;
var cli_win=jQuery(window);
var cli_winh=cli_win.height()-40;
var cli_winw=cli_win.width();
var cli_defw=cli_winw>400 ? 300 : cli_winw-30;
var cli_defw=cli_winw>400 ? 300 : cli_winw-30;

cli_elm.css({
'width':cli_defw,'height':'auto','max-height':cli_winh,'padding':'25px 15px','overflow':'auto','position':'fixed','box-sizing':'border-box'
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
/**
* Method: endBox
*/


endBox: function(end) {
var minDisplacement = 5;

var result;
if (Math.abs(this.dragHandler.start.x - end.x) > 5 ||
Math.abs(this.dragHandler.start.y - end.y) > 5) {
if (Math.abs(this.dragHandler.start.x - end.x) > minDisplacement ||
Math.abs(this.dragHandler.start.y - end.y) > minDisplacement) {
var start = this.dragHandler.start;
var top = Math.min(start.y, end.y);
var bottom = Math.max(start.y, end.y);
Expand Down
27 changes: 17 additions & 10 deletions geonode/static/geonode/js/ol-2.13/lib/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
* @requires OpenLayers/Popup/Anchored.js
* @requires Rico/Corner.js
*/

XMLisOpen = 1;
XMLhasReceivedHeaders = 2
XMLisLoaded = 4;
/**
* About: Deprecated
* The deprecated.js script includes all methods, properties, and constructors
Expand Down Expand Up @@ -301,6 +303,7 @@ OpenLayers.Ajax = {
activeRequestCount: 0
};


/**
* Namespace: OpenLayers.Ajax.Responders
* {Object}
Expand Down Expand Up @@ -511,7 +514,7 @@ OpenLayers.Ajax.Request = OpenLayers.Class(OpenLayers.Ajax.Base, {
*/
onStateChange: function() {
var readyState = this.transport.readyState;
if (readyState > 1 && !((readyState == 4) && this._complete)) {
if (readyState > XMLisOpen && !((readyState == XMLisLoaded) && this._complete)) {
this.respondToReadyState(this.transport.readyState);
}
},
Expand Down Expand Up @@ -726,16 +729,16 @@ OpenLayers.Ajax.Response = OpenLayers.Class({
var transport = this.transport = request.transport,
readyState = this.readyState = transport.readyState;

if ((readyState > 2 &&
if ((readyState > XMLhasReceivedHeaders &&
!(!!(window.attachEvent && !window.opera))) ||
readyState == 4) {
readyState == XMLisLoaded) {
this.status = this.getStatus();
this.statusText = this.getStatusText();
this.responseText = transport.responseText == null ?
'' : String(transport.responseText);
}

if(readyState == 4) {
if(readyState == XMLisLoaded) {
var xml = transport.responseXML;
this.responseXML = xml === undefined ? null : xml;
}
Expand Down Expand Up @@ -1035,6 +1038,8 @@ OpenLayers.Util.extend(OpenLayers.Tile.prototype, {
* bounds - {<OpenLayers.Bounds>}
*/
getBoundsFromBaseLayer: function(position) {
var fullRot = 360;

var msg = OpenLayers.i18n('reprojectDeprecated',
{'layerName':this.layer.name});
OpenLayers.Console.warn(msg);
Expand All @@ -1048,9 +1053,9 @@ OpenLayers.Util.extend(OpenLayers.Tile.prototype, {
// that fashion.
if (topLeft.lon > bottomRight.lon) {
if (topLeft.lon < 0) {
topLeft.lon = -180 - (topLeft.lon+180);
topLeft.lon = -topLeft.lon - fullRot;
} else {
bottomRight.lon = 180+bottomRight.lon+180;
bottomRight.lon = bottomRight.lon + fullRot;
}
}
var bounds = new OpenLayers.Bounds(topLeft.lon,
Expand Down Expand Up @@ -1326,9 +1331,10 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
* Zoombox function.
*/
zoomBoxEnd: function(evt) {
mouseSensitivity = 5
if (this.mouseDragStart != null) {
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > 5 ||
Math.abs(this.mouseDragStart.y - evt.xy.y) > 5) {
if (Math.abs(this.mouseDragStart.x - evt.xy.x) > mouseSensitivity ||
Math.abs(this.mouseDragStart.y - evt.xy.y) > mouseSensitivity) {
var start = this.map.getLonLatFromViewPortPx( this.mouseDragStart );
var end = this.map.getLonLatFromViewPortPx( evt.xy );
var top = Math.max(start.lat, end.lat);
Expand Down Expand Up @@ -1373,6 +1379,7 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
onWheelEvent: function(e){

// first determine whether or not the wheeling was inside the map
var scrollSensitivity = 120;
var inMap = false;
var elem = OpenLayers.Event.element(e);
while(elem != null) {
Expand All @@ -1390,7 +1397,7 @@ OpenLayers.Control.MouseDefaults = OpenLayers.Class(OpenLayers.Control, {
e = window.event;
}
if (e.wheelDelta) {
delta = e.wheelDelta/120;
delta = e.wheelDelta/scrollSensitivity;
if (window.opera && window.opera.version() < 9.2) {
delta = -delta;
}
Expand Down
21 changes: 12 additions & 9 deletions geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
SplitResult
)

maxExtent = 20037508.34;
DEFAULT_TITLE = ""
DEFAULT_ABSTRACT = ""

Expand Down Expand Up @@ -112,6 +113,7 @@

logger = logging.getLogger("geonode.utils")

fullRot = 360;

def unzip_file(upload_file, extension='.shp', tempdir=None):
"""
Expand Down Expand Up @@ -333,7 +335,7 @@ def bbox_to_wkt(x0, x1, y0, y1, srid="4326", include_srid=True):

def _v(coord, x, source_srid=4326, target_srid=3857):
if source_srid == 4326 and x and abs(coord) != 180.0:
coord = coord - (round(coord / 360.0) * 360.0)
coord = coord - (round(coord / fullRot) * fullRot)
if source_srid == 4326 and target_srid != 4326:
if x and float(coord) >= 179.999:
return 179.999
Expand Down Expand Up @@ -416,7 +418,7 @@ def zoom(mapPx, worldPx, fraction):
sw = [float(bounds[0]), float(bounds[1])]
latFraction = (latRad(ne[1]) - latRad(sw[1])) / pi
lngDiff = ne[0] - sw[0]
lngFraction = ((lngDiff + 360.0) if (lngDiff < 0) else lngDiff) / 360.0
lngFraction = ((lngDiff + fullRot) if (lngDiff < 0) else lngDiff) / fullRot
latZoom = zoom(float(height), WORLD_DIM['height'], latFraction)
lngZoom = zoom(float(width), WORLD_DIM['width'], lngFraction)
# ratio = float(max(width, height)) / float(min(width, height))
Expand Down Expand Up @@ -445,27 +447,27 @@ def forward_mercator(lonlat):
If the lat value is out of range, -inf will be returned as the y value
"""
x = lonlat[0] * 20037508.34 / 180
x = lonlat[0] * maxExtent / 180
try:
# With data sets that only have one point the value of this
# expression becomes negative infinity. In order to continue,
# we wrap this in a try catch block.
n = tan((90 + lonlat[1]) * pi / 360)
n = tan((90 + lonlat[1]) * pi / fullRot)
except ValueError:
n = 0
if n <= 0:
y = float("-inf")
else:
y = log(n) / pi * 20037508.34
y = log(n) / pi * maxExtent
return (x, y)


def inverse_mercator(xy):
"""
Given coordinates in spherical mercator, return a lon,lat tuple.
"""
lon = (xy[0] / 20037508.34) * 180
lat = (xy[1] / 20037508.34) * 180
lon = (xy[0] / maxExtent) * 180
lat = (xy[1] / maxExtent) * 180
lat = 180 / pi * \
(2 * atan(exp(lat * pi / 180)) - pi / 2)
return (lon, lat)
Expand Down Expand Up @@ -850,16 +852,17 @@ def _baselayer(lyr, order):
return DEFAULT_MAP_CONFIG, DEFAULT_BASE_LAYERS



_viewer_projection_lookup = {
"EPSG:900913": {
"maxResolution": 156543.03390625,
"units": "m",
"maxExtent": [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
"maxExtent": [-maxExtent, -maxExtent, maxExtent, maxExtent],
},
"EPSG:3857": {
"maxResolution": 156543.03390625,
"units": "m",
"maxExtent": [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
"maxExtent": [-maxExtent, -maxExtent, maxExtent, maxExtent],
},
"EPSG:4326": {
"max_resolution": (180 - (-180)) / 256,
Expand Down

0 comments on commit 2a93b16

Please sign in to comment.