Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Changed map permalink back to commas

Mike McGanne19d82c9a573
diff --git a/js/Worldview/Permalink.js b/js/Worldview/Permalink.js
index 687e3757b..7a67e1be0 100644
--- a/js/Worldview/Permalink.js
+++ b/js/Worldview/Permalink.js
@@ -22,6 +22,17 @@ $(function() {
var permOverlay = null;
+ /**
+ * Constant: ENCODING_EXCEPTIONS
+ * Characters that should not be encoded with encodeURI component. An
+ * array of objects where each object contains "replace" which is the
+ * regular expression to match after encoding, and "with" which is the
+ * string to replace the match after encoding.
+ */
+ ns.ENCODING_EXCEPTIONS = [
+ { replace: new RegExp("%2C", "g"), with: "," }
+ ];
+
/**
* Function: fromObject
* Returns a query string using the properties and values of an object.
@@ -47,8 +58,7 @@ $(function() {
if ( qs.length > 0 ) {
qs += "&";
}
- qs += encodeURIComponent(key) + "=" +
- encodeURIComponent(values[key]);
+ qs += encode(key) + "=" + encode(values[key]);
}
return "?" + qs;
};
@@ -159,5 +169,17 @@ $(function() {
document.getElementById('permalink_content').focus();
document.getElementById('permalink_content').select();
};
+
+ /*
+ * Encode the URI component but convert exceptions back to their original
+ * values.
+ */
+ var encode = function(value) {
+ var encoded = encodeURIComponent(value);
+ $.each(ns.ENCODING_EXCEPTIONS, function(index, exception) {
+ encoded = encoded.replace(exception.replace, exception.with);
+ });
+ return encoded;
+ }
});
diff --git a/js/Worldview/Widget/Map.js b/js/Worldview/Widget/Map.js
index 146bc59e6..cf75e8377 100644
--- a/js/Worldview/Widget/Map.js
+++ b/js/Worldview/Widget/Map.js
@@ -66,7 +66,7 @@ Worldview.Widget.Map = function(containerId, spec) {
*/
self.setValue = function(value) {
log.debug("setValue: " + extent);
- var extent = Worldview.Widget.Map.extentFromValue(value);
+ var extent = OpenLayers.Bounds.fromString(value);
self.productMap.map.zoomToExtent(extent, true);
};
@@ -81,8 +81,7 @@ Worldview.Widget.Map = function(containerId, spec) {
*/
self.getValue = function() {
var queryString = containerId + "=" +
- Worldview.Widget.Map.valueFromExtent(
- self.productMap.map.getExtent());
+ self.productMap.map.getExtent().toBBOX();
log.debug("getValue: " + queryString);
return queryString;
};
@@ -202,48 +201,6 @@ Worldview.Widget.Map = function(containerId, spec) {
return self;
};
-/**
- * Namespace: Worldview.Widget.Map
- * Utility functions.
- */
-(function(ns) {
-
- /**
- * Function: extentFromValue
- * Converts an extent value in a query string to an OpenLayers.Bounds
- * object.
- *
- * Parameters:
- * value - String in the form of L_B_R_U where L is the left X value,
- * B is the bottom Y value, R is the right X value, and U is the upper
- * Y value. Commas instead of underscores are also accepted.
- *
- * Returns:
- * The OpenLayers.Bound object that represents the given extent.
- */
- ns.extentFromValue = function(value) {
- return OpenLayers.Bounds.fromString(value.replace(/_/g, ","));
- };
-
- /**
- * Function: valueFromExtent
- * Converts an OpenLayers.Bounds object to a value that can be used
- * in a query string.
- *
- * Parameters:
- * extent - The extent as an OpenLayers.Bounds object.
- *
- * Returns:
- * String in the form of L_B_R_U where L is the left X value,
- * B is the bottom Y value, R is the right X value, and U is the upper
- * Y value.
- */
- ns.valueFromExtent = function(extent) {
- return extent.toBBOX().replace(/,/g, "_");
- };
-
-})(Worldview.Widget.Map);
-
diff --git a/test/Worldview/Widget/testMap.js b/test/Worldview/Widget/testMap.js
deleted file mode 100644
index 0d7ba884e..000000000
--- a/test/Worldview/Widget/testMap.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * NASA Worldview
- *
- * This code was originally developed at NASA/Goddard Space Flight Center for
- * the Earth Science Data and Information System (ESDIS) project.
- *
- * Copyright (C) 2013 United States Government as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All Rights Reserved.
- */
-
-TestCase("Widget.Map", TestSuite.Tests({
-
- ns: null,
-
- setUp: function() {
- ns = Worldview.Widget.Map;
- },
-
- // Check that an extent is encoded properly
- testValueFromExtent: function() {
- extent = new OpenLayers.Bounds(-2, -1, 1, 2);
- assertEquals("-2_-1_1_2", ns.valueFromExtent(extent));
- },
-
- // Check that the extent is correct when decoded
- testExtentFromValue: function() {
- value = ns.extentFromValue("-2_-1_1_2");
- assertEquals(-2, value.toArray()[0]);
- assertEquals(-1, value.toArray()[1]);
- assertEquals(1, value.toArray()[2]);
- assertEquals(2, value.toArray()[3]);
- },
-
- // Check that the extent is correct when decoded even if using commas
- testExtentFromValueCommas: function() {
- value = ns.extentFromValue("-2,-1,1,2");
- assertEquals(-2, value.toArray()[0]);
- assertEquals(-1, value.toArray()[1]);
- assertEquals(1, value.toArray()[2]);
- assertEquals(2, value.toArray()[3]);
- }
-
-}));
diff --git a/test/Worldview/testPermalink.js b/test/Worldview/testPermalink.js
index 5b947e216..a29606003 100644
--- a/test/Worldview/testPermalink.js
+++ b/test/Worldview/testPermalink.js
@@ -18,7 +18,7 @@ TestCase("Permalink.fromObject", TestSuite.Tests({
},
// Check that key/value pairs are encoded correctly
- testFromObjectValid: function() {
+ testvalid: function() {
var p = {
"foo": 1,
"bar": "baz"
@@ -27,12 +27,19 @@ TestCase("Permalink.fromObject", TestSuite.Tests({
},
// Check that special characters are encoded correclty.
- testFromObjectSpecialCharacters: function() {
+ testSpecialCharacters: function() {
var p = {
"foo": " Z",
"<bar": "baz"
};
assertEquals("?foo=%20Z&%3Cbar=baz", ns.fromObject(p));
+ },
+
+ testCommaException: function() {
+ var p = {
+ "foo": "1,2"
+ };
+ assertEquals("?foo=1,2", ns.fromObject(p));
}
}));