Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

Showing initial granule buttons

Mike McGann9e76c2830b95
diff --git a/etc/ant/js.build.xml b/etc/ant/js.build.xml
index e6178427f..7ea5bf18d 100644
--- a/etc/ant/js.build.xml
+++ b/etc/ant/js.build.xml
@@ -40,7 +40,8 @@
<file name="ext/openlayers/OpenLayers.debug.js"/>
<file name="ext/jcrop/jcrop.js"/>
<file name="ext/jquery.dd/jquery.dd.js"/>
-
+ <file name="ext/jscache/cache.js"/>
+
<file name="js/Date.js"/>
<file name="js/Logging.js"/>
diff --git a/etc/images/data-download-minus-button-blue.graffle b/etc/images/data-download-minus-button-blue.graffle
new file mode 100644
index 000000000..d6020b219
--- /dev/null
+++ b/etc/images/data-download-minus-button-blue.graffle
@@ -0,0 +1,315 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>ActiveLayerIndex</key>
+ <integer>0</integer>
+ <key>ApplicationVersion</key>
+ <array>
+ <string>com.omnigroup.OmniGrafflePro</string>
+ <string>139.17.0.185490</string>
+ </array>
+ <key>AutoAdjust</key>
+ <false/>
+ <key>BackgroundGraphic</key>
+ <dict>
+ <key>Bounds</key>
+ <string>{{0, 0}, {48, 48}}</string>
+ <key>Class</key>
+ <string>SolidGraphic</string>
+ <key>ID</key>
+ <integer>2</integer>
+ <key>Style</key>
+ <dict>
+ <key>shadow</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ </dict>
+ <key>stroke</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ </dict>
+ </dict>
+ </dict>
+ <key>BaseZoom</key>
+ <integer>0</integer>
+ <key>CanvasOrigin</key>
+ <string>{0, 0}</string>
+ <key>CanvasSize</key>
+ <string>{48, 48}</string>
+ <key>ColumnAlign</key>
+ <integer>1</integer>
+ <key>ColumnSpacing</key>
+ <real>36</real>
+ <key>CreationDate</key>
+ <string>2013-06-13 11:43:49 +0000</string>
+ <key>Creator</key>
+ <string>Mike McGann</string>
+ <key>DisplayScale</key>
+ <string>1 pt = 1 pt</string>
+ <key>GraphDocumentVersion</key>
+ <integer>8</integer>
+ <key>GraphicsList</key>
+ <array>
+ <dict>
+ <key>Bounds</key>
+ <string>{{22, 13}, {4, 22}}</string>
+ <key>Class</key>
+ <string>ShapedGraphic</string>
+ <key>ID</key>
+ <integer>30</integer>
+ <key>Layer</key>
+ <integer>0</integer>
+ <key>Rotation</key>
+ <real>90</real>
+ <key>Shape</key>
+ <string>Rectangle</string>
+ <key>Style</key>
+ <dict>
+ <key>stroke</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ <key>Width</key>
+ <real>0.5</real>
+ </dict>
+ </dict>
+ </dict>
+ <dict>
+ <key>Bounds</key>
+ <string>{{2, 2}, {44, 44}}</string>
+ <key>Class</key>
+ <string>ShapedGraphic</string>
+ <key>ID</key>
+ <integer>28</integer>
+ <key>Layer</key>
+ <integer>1</integer>
+ <key>Shape</key>
+ <string>Circle</string>
+ <key>Style</key>
+ <dict>
+ <key>fill</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>1</string>
+ <key>g</key>
+ <string>0.501961</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ <key>FillType</key>
+ <integer>2</integer>
+ <key>GradientAngle</key>
+ <real>90</real>
+ <key>GradientColor</key>
+ <dict>
+ <key>b</key>
+ <string>1</string>
+ <key>g</key>
+ <string>0</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ </dict>
+ <key>shadow</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>0</string>
+ <key>g</key>
+ <string>0</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ </dict>
+ <key>stroke</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>1</string>
+ <key>g</key>
+ <string>1</string>
+ <key>r</key>
+ <string>1</string>
+ </dict>
+ </dict>
+ </dict>
+ <key>Text</key>
+ <dict>
+ <key>VerticalPad</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ </array>
+ <key>GridInfo</key>
+ <dict>
+ <key>GridSpacing</key>
+ <real>1</real>
+ <key>ShowsGrid</key>
+ <string>YES</string>
+ <key>SnapsToGrid</key>
+ <string>YES</string>
+ </dict>
+ <key>GuidesLocked</key>
+ <string>NO</string>
+ <key>GuidesVisible</key>
+ <string>YES</string>
+ <key>HPages</key>
+ <integer>1</integer>
+ <key>ImageCounter</key>
+ <integer>1</integer>
+ <key>KeepToScale</key>
+ <false/>
+ <key>Layers</key>
+ <array>
+ <dict>
+ <key>Lock</key>
+ <string>NO</string>
+ <key>Name</key>
+ <string>Plus Fill</string>
+ <key>Print</key>
+ <string>YES</string>
+ <key>View</key>
+ <string>YES</string>
+ </dict>
+ <dict>
+ <key>Lock</key>
+ <string>NO</string>
+ <key>Name</key>
+ <string>Base</string>
+ <key>Print</key>
+ <string>YES</string>
+ <key>View</key>
+ <string>YES</string>
+ </dict>
+ </array>
+ <key>LayoutInfo</key>
+ <dict>
+ <key>Animate</key>
+ <string>NO</string>
+ <key>circoMinDist</key>
+ <real>18</real>
+ <key>circoSeparation</key>
+ <real>0.0</real>
+ <key>layoutEngine</key>
+ <string>dot</string>
+ <key>neatoSeparation</key>
+ <real>0.0</real>
+ <key>twopiSeparation</key>
+ <real>0.0</real>
+ </dict>
+ <key>LinksVisible</key>
+ <string>NO</string>
+ <key>MagnetsVisible</key>
+ <string>NO</string>
+ <key>MasterSheets</key>
+ <array/>
+ <key>ModificationDate</key>
+ <string>2013-06-14 18:46:47 +0000</string>
+ <key>Modifier</key>
+ <string>Mike McGann</string>
+ <key>NotesVisible</key>
+ <string>NO</string>
+ <key>Orientation</key>
+ <integer>2</integer>
+ <key>OriginVisible</key>
+ <string>NO</string>
+ <key>PageBreaks</key>
+ <string>YES</string>
+ <key>PrintInfo</key>
+ <dict>
+ <key>NSBottomMargin</key>
+ <array>
+ <string>float</string>
+ <string>41</string>
+ </array>
+ <key>NSHorizonalPagination</key>
+ <array>
+ <string>coded</string>
+ <string>BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG</string>
+ </array>
+ <key>NSLeftMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ <key>NSPaperSize</key>
+ <array>
+ <string>size</string>
+ <string>{612, 792}</string>
+ </array>
+ <key>NSPrintReverseOrientation</key>
+ <array>
+ <string>int</string>
+ <string>0</string>
+ </array>
+ <key>NSRightMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ <key>NSTopMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ </dict>
+ <key>PrintOnePage</key>
+ <false/>
+ <key>ReadOnly</key>
+ <string>NO</string>
+ <key>RowAlign</key>
+ <integer>1</integer>
+ <key>RowSpacing</key>
+ <real>36</real>
+ <key>SheetTitle</key>
+ <string>Canvas 1</string>
+ <key>SmartAlignmentGuidesActive</key>
+ <string>NO</string>
+ <key>SmartDistanceGuidesActive</key>
+ <string>NO</string>
+ <key>UniqueID</key>
+ <integer>1</integer>
+ <key>UseEntirePage</key>
+ <false/>
+ <key>VPages</key>
+ <integer>1</integer>
+ <key>WindowInfo</key>
+ <dict>
+ <key>CurrentSheet</key>
+ <integer>0</integer>
+ <key>ExpandedCanvases</key>
+ <array/>
+ <key>Frame</key>
+ <string>{{572, 476}, {656, 620}}</string>
+ <key>ListView</key>
+ <true/>
+ <key>OutlineWidth</key>
+ <integer>142</integer>
+ <key>RightSidebar</key>
+ <false/>
+ <key>Sidebar</key>
+ <true/>
+ <key>SidebarWidth</key>
+ <integer>173</integer>
+ <key>VisibleRegion</key>
+ <string>{{-5.875, -7.875}, {60.375, 65.75}}</string>
+ <key>Zoom</key>
+ <real>8</real>
+ <key>ZoomValues</key>
+ <array>
+ <array>
+ <string>Canvas 1</string>
+ <real>8</real>
+ <real>1</real>
+ </array>
+ </array>
+ </dict>
+</dict>
+</plist>
diff --git a/etc/images/data-download-plus-button-cyan.graffle b/etc/images/data-download-plus-button-cyan.graffle
new file mode 100644
index 000000000..e25908c36
--- /dev/null
+++ b/etc/images/data-download-plus-button-cyan.graffle
@@ -0,0 +1,342 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>ActiveLayerIndex</key>
+ <integer>0</integer>
+ <key>ApplicationVersion</key>
+ <array>
+ <string>com.omnigroup.OmniGrafflePro</string>
+ <string>139.17.0.185490</string>
+ </array>
+ <key>AutoAdjust</key>
+ <false/>
+ <key>BackgroundGraphic</key>
+ <dict>
+ <key>Bounds</key>
+ <string>{{0, 0}, {48, 48}}</string>
+ <key>Class</key>
+ <string>SolidGraphic</string>
+ <key>ID</key>
+ <integer>2</integer>
+ <key>Style</key>
+ <dict>
+ <key>shadow</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ </dict>
+ <key>stroke</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ </dict>
+ </dict>
+ </dict>
+ <key>BaseZoom</key>
+ <integer>0</integer>
+ <key>CanvasOrigin</key>
+ <string>{0, 0}</string>
+ <key>CanvasSize</key>
+ <string>{48, 48}</string>
+ <key>ColumnAlign</key>
+ <integer>1</integer>
+ <key>ColumnSpacing</key>
+ <real>36</real>
+ <key>CreationDate</key>
+ <string>2013-06-13 11:43:49 +0000</string>
+ <key>Creator</key>
+ <string>Mike McGann</string>
+ <key>DisplayScale</key>
+ <string>1 pt = 1 pt</string>
+ <key>GraphDocumentVersion</key>
+ <integer>8</integer>
+ <key>GraphicsList</key>
+ <array>
+ <dict>
+ <key>Bounds</key>
+ <string>{{22, 13}, {4, 22}}</string>
+ <key>Class</key>
+ <string>ShapedGraphic</string>
+ <key>ID</key>
+ <integer>30</integer>
+ <key>Layer</key>
+ <integer>0</integer>
+ <key>Rotation</key>
+ <real>90</real>
+ <key>Shape</key>
+ <string>Rectangle</string>
+ <key>Style</key>
+ <dict>
+ <key>fill</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>0</string>
+ <key>g</key>
+ <string>0</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ </dict>
+ <key>stroke</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ <key>Width</key>
+ <real>0.5</real>
+ </dict>
+ </dict>
+ </dict>
+ <dict>
+ <key>Bounds</key>
+ <string>{{22, 13}, {4, 22}}</string>
+ <key>Class</key>
+ <string>ShapedGraphic</string>
+ <key>ID</key>
+ <integer>1</integer>
+ <key>Layer</key>
+ <integer>0</integer>
+ <key>Shape</key>
+ <string>Rectangle</string>
+ <key>Style</key>
+ <dict>
+ <key>fill</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>0</string>
+ <key>g</key>
+ <string>0</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ </dict>
+ <key>stroke</key>
+ <dict>
+ <key>Draws</key>
+ <string>NO</string>
+ <key>Width</key>
+ <real>0.5</real>
+ </dict>
+ </dict>
+ </dict>
+ <dict>
+ <key>Bounds</key>
+ <string>{{2, 2}, {44, 44}}</string>
+ <key>Class</key>
+ <string>ShapedGraphic</string>
+ <key>ID</key>
+ <integer>28</integer>
+ <key>Layer</key>
+ <integer>1</integer>
+ <key>Shape</key>
+ <string>Circle</string>
+ <key>Style</key>
+ <dict>
+ <key>fill</key>
+ <dict>
+ <key>Color</key>
+ <dict>
+ <key>b</key>
+ <string>1</string>
+ <key>g</key>
+ <string>1</string>
+ <key>r</key>
+ <string>0</string>
+ </dict>
+ <key>FillType</key>
+ <integer>2</integer>
+ <key>GradientAngle</key>
+ <real>90</real>
+ <key>GradientColor</key>
+ <dict>
+ <key>b</key>
+ <string>1</string>
+ <key>g</key>
+ <string>0.8</string>
+ <key>r</key>
+ <string>0.4</string>
+ </dict>
+ </dict>
+ </dict>
+ <key>Text</key>
+ <dict>
+ <key>VerticalPad</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ </array>
+ <key>GridInfo</key>
+ <dict>
+ <key>GridSpacing</key>
+ <real>1</real>
+ <key>ShowsGrid</key>
+ <string>YES</string>
+ <key>SnapsToGrid</key>
+ <string>YES</string>
+ </dict>
+ <key>GuidesLocked</key>
+ <string>NO</string>
+ <key>GuidesVisible</key>
+ <string>YES</string>
+ <key>HPages</key>
+ <integer>1</integer>
+ <key>ImageCounter</key>
+ <integer>1</integer>
+ <key>KeepToScale</key>
+ <false/>
+ <key>Layers</key>
+ <array>
+ <dict>
+ <key>Lock</key>
+ <string>NO</string>
+ <key>Name</key>
+ <string>Plus Fill</string>
+ <key>Print</key>
+ <string>YES</string>
+ <key>View</key>
+ <string>YES</string>
+ </dict>
+ <dict>
+ <key>Lock</key>
+ <string>NO</string>
+ <key>Name</key>
+ <string>Base</string>
+ <key>Print</key>
+ <string>YES</string>
+ <key>View</key>
+ <string>YES</string>
+ </dict>
+ </array>
+ <key>LayoutInfo</key>
+ <dict>
+ <key>Animate</key>
+ <string>NO</string>
+ <key>circoMinDist</key>
+ <real>18</real>
+ <key>circoSeparation</key>
+ <real>0.0</real>
+ <key>layoutEngine</key>
+ <string>dot</string>
+ <key>neatoSeparation</key>
+ <real>0.0</real>
+ <key>twopiSeparation</key>
+ <real>0.0</real>
+ </dict>
+ <key>LinksVisible</key>
+ <string>NO</string>
+ <key>MagnetsVisible</key>
+ <string>NO</string>
+ <key>MasterSheets</key>
+ <array/>
+ <key>ModificationDate</key>
+ <string>2013-06-17 13:25:03 +0000</string>
+ <key>Modifier</key>
+ <string>Mike McGann</string>
+ <key>NotesVisible</key>
+ <string>NO</string>
+ <key>Orientation</key>
+ <integer>2</integer>
+ <key>OriginVisible</key>
+ <string>NO</string>
+ <key>PageBreaks</key>
+ <string>YES</string>
+ <key>PrintInfo</key>
+ <dict>
+ <key>NSBottomMargin</key>
+ <array>
+ <string>float</string>
+ <string>41</string>
+ </array>
+ <key>NSHorizonalPagination</key>
+ <array>
+ <string>coded</string>
+ <string>BAtzdHJlYW10eXBlZIHoA4QBQISEhAhOU051bWJlcgCEhAdOU1ZhbHVlAISECE5TT2JqZWN0AIWEASqEhAFxlwCG</string>
+ </array>
+ <key>NSLeftMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ <key>NSPaperSize</key>
+ <array>
+ <string>size</string>
+ <string>{612, 792}</string>
+ </array>
+ <key>NSPrintReverseOrientation</key>
+ <array>
+ <string>int</string>
+ <string>0</string>
+ </array>
+ <key>NSRightMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ <key>NSTopMargin</key>
+ <array>
+ <string>float</string>
+ <string>18</string>
+ </array>
+ </dict>
+ <key>PrintOnePage</key>
+ <false/>
+ <key>ReadOnly</key>
+ <string>NO</string>
+ <key>RowAlign</key>
+ <integer>1</integer>
+ <key>RowSpacing</key>
+ <real>36</real>
+ <key>SheetTitle</key>
+ <string>Canvas 1</string>
+ <key>SmartAlignmentGuidesActive</key>
+ <string>NO</string>
+ <key>SmartDistanceGuidesActive</key>
+ <string>NO</string>
+ <key>UniqueID</key>
+ <integer>1</integer>
+ <key>UseEntirePage</key>
+ <false/>
+ <key>VPages</key>
+ <integer>1</integer>
+ <key>WindowInfo</key>
+ <dict>
+ <key>CurrentSheet</key>
+ <integer>0</integer>
+ <key>ExpandedCanvases</key>
+ <array>
+ <dict>
+ <key>name</key>
+ <string>Canvas 1</string>
+ </dict>
+ </array>
+ <key>Frame</key>
+ <string>{{313, 261}, {656, 620}}</string>
+ <key>ListView</key>
+ <true/>
+ <key>OutlineWidth</key>
+ <integer>142</integer>
+ <key>RightSidebar</key>
+ <false/>
+ <key>Sidebar</key>
+ <true/>
+ <key>SidebarWidth</key>
+ <integer>173</integer>
+ <key>VisibleRegion</key>
+ <string>{{-5.875, -7.875}, {60.375, 65.75}}</string>
+ <key>Zoom</key>
+ <real>8</real>
+ <key>ZoomValues</key>
+ <array>
+ <array>
+ <string>Canvas 1</string>
+ <real>8</real>
+ <real>1</real>
+ </array>
+ </array>
+ </dict>
+</dict>
+</plist>
diff --git a/src/ext/jscache/cache.js b/src/ext/jscache/cache.js
new file mode 100644
index 000000000..38793025f
--- /dev/null
+++ b/src/ext/jscache/cache.js
@@ -0,0 +1,432 @@
+/*
+MIT LICENSE
+Copyright (c) 2007 Monsur Hossain (http://monsur.hossai.in)
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+// Avoid polluting the global namespace if we're using a module loader
+(function(){
+
+/**
+ * Creates a new Cache object.
+ * @param {number} maxSize The maximum size of the cache (or -1 for no max).
+ * @param {boolean} debug Whether to log events to the console.log.
+ * @constructor
+ */
+function Cache(maxSize, debug, storage) {
+ this.maxSize_ = maxSize || -1;
+ this.debug_ = debug || false;
+ this.storage_ = storage || new Cache.BasicCacheStorage();
+
+ this.fillFactor_ = .75;
+
+ this.stats_ = {};
+ this.stats_['hits'] = 0;
+ this.stats_['misses'] = 0;
+ this.log_('Initialized cache with size ' + maxSize);
+}
+
+/**
+ * An easier way to refer to the priority of a cache item
+ * @enum {number}
+ */
+Cache.Priority = {
+ 'LOW': 1,
+ 'NORMAL': 2,
+ 'HIGH': 4
+};
+
+/**
+ * Basic in memory cache storage backend.
+ * @constructor
+ */
+Cache.BasicCacheStorage = function() {
+ this.items_ = {};
+ this.count_ = 0;
+}
+Cache.BasicCacheStorage.prototype.get = function(key) {
+ return this.items_[key];
+}
+Cache.BasicCacheStorage.prototype.set = function(key, value) {
+ if (typeof this.get(key) === "undefined")
+ this.count_++;
+ this.items_[key] = value;
+}
+Cache.BasicCacheStorage.prototype.size = function(key, value) {
+ return this.count_;
+}
+Cache.BasicCacheStorage.prototype.remove = function(key) {
+ var item = this.get(key);
+ if (typeof item !== "undefined")
+ this.count_--;
+ delete this.items_[key];
+ return item;
+}
+Cache.BasicCacheStorage.prototype.keys = function() {
+ var ret = [], p;
+ for (p in this.items_) ret.push(p);
+ return ret;
+}
+
+/**
+ * Local Storage based persistant cache storage backend.
+ * If a size of -1 is used, it will purge itself when localStorage
+ * is filled. This is 5MB on Chrome/Safari.
+ * WARNING: The amortized cost of this cache is very low, however,
+ * when a the cache fills up all of localStorage, and a purge is required, it can
+ * take a few seconds to fetch all the keys and values in storage.
+ * Since localStorage doesn't have namespacing, this means that even if this
+ * individual cache is small, it can take this time if there are lots of other
+ * other keys in localStorage.
+ *
+ * @param {string} namespace A string to namespace the items in localStorage. Defaults to 'default'.
+ * @constructor
+ */
+Cache.LocalStorageCacheStorage = function(namespace) {
+ this.prefix_ = 'cache-storage.' + (namespace || 'default') + '.';
+ // Regexp String Escaping from http://simonwillison.net/2006/Jan/20/escape/#p-6
+ var escapedPrefix = this.prefix_.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+ this.regexp_ = new RegExp('^' + escapedPrefix)
+}
+Cache.LocalStorageCacheStorage.prototype.get = function(key) {
+ var item = window.localStorage[this.prefix_ + key];
+ if (item) return JSON.parse(item);
+ return null;
+}
+Cache.LocalStorageCacheStorage.prototype.set = function(key, value) {
+ window.localStorage[this.prefix_ + key] = JSON.stringify(value);
+}
+Cache.LocalStorageCacheStorage.prototype.size = function(key, value) {
+ return this.keys().length;
+}
+Cache.LocalStorageCacheStorage.prototype.remove = function(key) {
+ var item = this.get(key);
+ delete window.localStorage[this.prefix_ + key];
+ return item;
+}
+Cache.LocalStorageCacheStorage.prototype.keys = function() {
+ var ret = [], p;
+ for (p in window.localStorage) {
+ if (p.match(this.regexp_)) ret.push(p.replace(this.prefix_, ''));
+ };
+ return ret;
+}
+
+/**
+ * Retrieves an item from the cache.
+ * @param {string} key The key to retrieve.
+ * @return {Object} The item, or null if it doesn't exist.
+ */
+Cache.prototype.getItem = function(key) {
+
+ // retrieve the item from the cache
+ var item = this.storage_.get(key);
+
+ if (item != null) {
+ if (!this.isExpired_(item)) {
+ // if the item is not expired
+ // update its last accessed date
+ item.lastAccessed = new Date().getTime();
+ } else {
+ // if the item is expired, remove it from the cache
+ this.removeItem(key);
+ item = null;
+ }
+ }
+
+ // return the item value (if it exists), or null
+ var returnVal = item ? item.value : null;
+ if (returnVal) {
+ this.stats_['hits']++;
+ this.log_('Cache HIT for key ' + key)
+ } else {
+ this.stats_['misses']++;
+ this.log_('Cache MISS for key ' + key)
+ }
+ return returnVal;
+};
+
+
+Cache._CacheItem = function(k, v, o) {
+ if (!k) {
+ throw new Error("key cannot be null or empty");
+ }
+ this.key = k;
+ this.value = v;
+ o = o || {};
+ if (o.expirationAbsolute) {
+ o.expirationAbsolute = o.expirationAbsolute.getTime();
+ }
+ if (!o.priority) {
+ o.priority = Cache.Priority.NORMAL;
+ }
+ this.options = o;
+ this.lastAccessed = new Date().getTime();
+};
+
+
+/**
+ * Sets an item in the cache.
+ * @param {string} key The key to refer to the item.
+ * @param {Object} value The item to cache.
+ * @param {Object} options an optional object which controls various caching
+ * options:
+ * expirationAbsolute: the datetime when the item should expire
+ * expirationSliding: an integer representing the seconds since
+ * the last cache access after which the item
+ * should expire
+ * priority: How important it is to leave this item in the cache.
+ * You can use the values Cache.Priority.LOW, .NORMAL, or
+ * .HIGH, or you can just use an integer. Note that
+ * placing a priority on an item does not guarantee
+ * it will remain in cache. It can still be purged if
+ * an expiration is hit, or if the cache is full.
+ * callback: A function that gets called when the item is purged
+ * from cache. The key and value of the removed item
+ * are passed as parameters to the callback function.
+ */
+Cache.prototype.setItem = function(key, value, options) {
+
+ // add a new cache item to the cache
+ if (this.storage_.get(key) != null) {
+ this.removeItem(key);
+ }
+ this.addItem_(new Cache._CacheItem(key, value, options));
+ this.log_("Setting key " + key);
+
+ // if the cache is full, purge it
+ if ((this.maxSize_ > 0) && (this.size() > this.maxSize_)) {
+ var that = this;
+ setTimeout(function() {
+ that.purge_.call(that);
+ }, 0);
+ }
+};
+
+
+/**
+ * Removes all items from the cache.
+ */
+Cache.prototype.clear = function() {
+ // loop through each item in the cache and remove it
+ var keys = this.storage_.keys()
+ for (var i = 0; i < keys.length; i++) {
+ this.removeItem(keys[i]);
+ }
+ this.log_('Cache cleared');
+};
+
+
+/**
+ * @return {Object} The hits and misses on the cache.
+ */
+Cache.prototype.getStats = function() {
+ return this.stats_;
+};
+
+
+/**
+ * @return {string} Returns an HTML string representation of the cache.
+ */
+Cache.prototype.toHtmlString = function() {
+ var returnStr = this.size() + " item(s) in cache<br /><ul>";
+ var keys = this.storage_.keys()
+ for (var i = 0; i < keys.length; i++) {
+ var item = this.storage_.get(keys[i]);
+ returnStr = returnStr + "<li>" + item.key.toString() + " = " +
+ item.value.toString() + "</li>";
+ }
+ returnStr = returnStr + "</ul>";
+ return returnStr;
+};
+
+
+/**
+ * Allows it to resize the Cache capacity if needed.
+ * @param {integer} newMaxSize the new max amount of stored entries within the Cache
+ */
+Cache.prototype.resize = function(newMaxSize) {
+ this.log_('Resizing Cache from ' + this.maxSize_ + ' to ' + newMaxSize);
+ // Set new size before purging so we know how many items to purge
+ var oldMaxSize = this.maxSize_
+ this.maxSize_ = newMaxSize;
+
+ if (newMaxSize > 0 && (oldMaxSize < 0 || newMaxSize < oldMaxSize)) {
+ if (this.size() > newMaxSize) {
+ // Cache needs to be purged as it does contain too much entries for the new size
+ this.purge_();
+ } // else if cache isn't filled up to the new limit nothing is to do
+ }
+ // else if newMaxSize >= maxSize nothing to do
+ this.log_('Resizing done');
+}
+
+/**
+ * Removes expired items from the cache.
+ */
+Cache.prototype.purge_ = function() {
+ var tmparray = new Array();
+ var purgeSize = Math.round(this.maxSize_ * this.fillFactor_);
+ if (this.maxSize_ < 0)
+ purgeSize = this.size() * this.fillFactor_;
+ // loop through the cache, expire items that should be expired
+ // otherwise, add the item to an array
+ var keys = this.storage_.keys();
+ for (var i = 0; i < keys.length; i++) {
+ var key = keys[i];
+ var item = this.storage_.get(key);
+ if (this.isExpired_(item)) {
+ this.removeItem(key);
+ } else {
+ tmparray.push(item);
+ }
+ }
+
+ if (tmparray.length > purgeSize) {
+ // sort this array based on cache priority and the last accessed date
+ tmparray = tmparray.sort(function(a, b) {
+ if (a.options.priority != b.options.priority) {
+ return b.options.priority - a.options.priority;
+ } else {
+ return b.lastAccessed - a.lastAccessed;
+ }
+ });
+ // remove items from the end of the array
+ while (tmparray.length > purgeSize) {
+ var ritem = tmparray.pop();
+ this.removeItem(ritem.key);
+ }
+ }
+ this.log_('Purged cached');
+};
+
+
+/**
+ * Add an item to the cache.
+ * @param {Object} item The cache item to add.
+ * @private
+ */
+Cache.prototype.addItem_ = function(item, attemptedAlready) {
+ var cache = this;
+ try {
+ this.storage_.set(item.key, item);
+ } catch(err) {
+ if (attemptedAlready) {
+ this.log_('Failed setting again, giving up: ' + err.toString());
+ throw(err);
+ }
+ this.log_('Error adding item, purging and trying again: ' + err.toString());
+ this.purge_();
+ this.addItem_(item, true);
+ }
+};
+
+
+/**
+ * Remove an item from the cache, call the callback function (if it exists).
+ * @param {String} key The key of the item to remove
+ */
+Cache.prototype.removeItem = function(key) {
+ var item = this.storage_.remove(key);
+ this.log_("removed key " + key);
+
+ // if there is a callback function, call it at the end of execution
+ if (item && item.options && item.options.callback) {
+ setTimeout(function() {
+ item.options.callback.call(null, item.key, item.value);
+ }, 0);
+ }
+ return item ? item.value : null;
+};
+
+/**
+ * Scan through each item in the cache and remove that item if it passes the
+ * supplied test.
+ * @param {Function} test A test to determine if the given item should be removed.
+ * The item will be removed if test(key, value) returns true.
+ */
+Cache.prototype.removeWhere = function(test) {
+ // Get a copy of the keys array - it won't be modified when we remove items from storage
+ var keys = this.storage_.keys();
+ for (var i = 0; i < keys.length; i++) {
+ var key = keys[i];
+ var item = this.storage_.get(key);
+ if(test(key, item.value) === true) {
+ this.removeItem(key);
+ }
+ }
+};
+
+Cache.prototype.size = function() {
+ return this.storage_.size();
+}
+
+
+/**
+ * @param {Object} item A cache item.
+ * @return {boolean} True if the item is expired
+ * @private
+ */
+Cache.prototype.isExpired_ = function(item) {
+ var now = new Date().getTime();
+ var expired = false;
+ if (item.options.expirationAbsolute &&
+ (item.options.expirationAbsolute < now)) {
+ // if the absolute expiration has passed, expire the item
+ expired = true;
+ }
+ if (!expired && item.options.expirationSliding) {
+ // if the sliding expiration has passed, expire the item
+ var lastAccess =
+ item.lastAccessed + (item.options.expirationSliding * 1000);
+ if (lastAccess < now) {
+ expired = true;
+ }
+ }
+ return expired;
+};
+
+
+/**
+ * Logs a message to the console.log if debug is set to true.
+ * @param {string} msg The message to log.
+ * @private
+ */
+Cache.prototype.log_ = function(msg) {
+ if (this.debug_) {
+ console.log(msg);
+ }
+};
+
+// Establish the root object, `window` in the browser, or `global` on the server.
+var root = this;
+
+if (typeof module !== "undefined" && module.exports) {
+ module.exports = Cache;
+} else if (typeof define == "function" && define.amd) {
+ define(function() { return Cache; });
+} else {
+ root.Cache = Cache;
+}
+
+})();
diff --git a/src/ext/proj4js/proj4js.js b/src/ext/proj4js/proj4js.js
new file mode 100644
index 000000000..2f7f94bcb
--- /dev/null
+++ b/src/ext/proj4js/proj4js.js
@@ -0,0 +1,1816 @@
+/*
+Author: Mike Adair madairATdmsolutions.ca
+ Richard Greenwood [email protected]
+License: LGPL as per: http://www.gnu.org/copyleft/lesser.html
+
+$Id: Proj.js 2956 2007-07-09 12:17:52Z steven $
+*/
+
+/**
+ * Namespace: Proj4js
+ *
+ * Proj4js is a JavaScript library to transform point coordinates from one
+ * coordinate system to another, including datum transformations.
+ *
+ * This library is a port of both the Proj.4 and GCTCP C libraries to JavaScript.
+ * Enabling these transformations in the browser allows geographic data stored
+ * in different projections to be combined in browser-based web mapping
+ * applications.
+ *
+ * Proj4js must have access to coordinate system initialization strings (which
+ * are the same as for PROJ.4 command line). Thes can be included in your
+ * application using a <script> tag or Proj4js can load CS initialization
+ * strings from a local directory or a web service such as spatialreference.org.
+ *
+ * Similarly, Proj4js must have access to projection transform code. These can
+ * be included individually using a <script> tag in your page, built into a
+ * custom build of Proj4js or loaded dynamically at run-time. Using the
+ * -combined and -compressed versions of Proj4js includes all projection class
+ * code by default.
+ *
+ * Note that dynamic loading of defs and code happens ascynchrously, check the
+ * Proj.readyToUse flag before using the Proj object. If the defs and code
+ * required by your application are loaded through script tags, dynamic loading
+ * is not required and the Proj object will be readyToUse on return from the
+ * constructor.
+ *
+ * All coordinates are handled as points which have a .x and a .y property
+ * which will be modified in place.
+ *
+ * Override Proj4js.reportError for output of alerts and warnings.
+ *
+ * See http://trac.osgeo.org/proj4js/wiki/UserGuide for full details.
+*/
+
+/**
+ * Global namespace object for Proj4js library
+ */
+var Proj4js = {
+
+ /**
+ * Property: defaultDatum
+ * The datum to use when no others a specified
+ */
+ defaultDatum: 'WGS84', //default datum
+
+ /**
+ * Method: transform(source, dest, point)
+ * Transform a point coordinate from one map projection to another. This is
+ * really the only public method you should need to use.
+ *
+ * Parameters:
+ * source - {Proj4js.Proj} source map projection for the transformation
+ * dest - {Proj4js.Proj} destination map projection for the transformation
+ * point - {Object} point to transform, may be geodetic (long, lat) or
+ * projected Cartesian (x,y), but should always have x,y properties.
+ */
+ transform: function(source, dest, point) {
+ if (!source.readyToUse) {
+ this.reportError("Proj4js initialization for:"+source.srsCode+" not yet complete");
+ return point;
+ }
+ if (!dest.readyToUse) {
+ this.reportError("Proj4js initialization for:"+dest.srsCode+" not yet complete");
+ return point;
+ }
+
+ // Workaround for datum shifts towgs84, if either source or destination projection is not wgs84
+ if (source.datum && dest.datum && (
+ ((source.datum.datum_type == Proj4js.common.PJD_3PARAM || source.datum.datum_type == Proj4js.common.PJD_7PARAM) && dest.datumCode != "WGS84") ||
+ ((dest.datum.datum_type == Proj4js.common.PJD_3PARAM || dest.datum.datum_type == Proj4js.common.PJD_7PARAM) && source.datumCode != "WGS84"))) {
+ var wgs84 = Proj4js.WGS84;
+ this.transform(source, wgs84, point);
+ source = wgs84;
+ }
+
+ // DGR, 2010/11/12
+ if (source.axis!="enu") {
+ this.adjust_axis(source,false,point);
+ }
+
+ // Transform source points to long/lat, if they aren't already.
+ if ( source.projName=="longlat") {
+ point.x *= Proj4js.common.D2R; // convert degrees to radians
+ point.y *= Proj4js.common.D2R;
+ } else {
+ if (source.to_meter) {
+ point.x *= source.to_meter;
+ point.y *= source.to_meter;
+ }
+ source.inverse(point); // Convert Cartesian to longlat
+ }
+
+ // Adjust for the prime meridian if necessary
+ if (source.from_greenwich) {
+ point.x += source.from_greenwich;
+ }
+
+ // Convert datums if needed, and if possible.
+ point = this.datum_transform( source.datum, dest.datum, point );
+
+ // Adjust for the prime meridian if necessary
+ if (dest.from_greenwich) {
+ point.x -= dest.from_greenwich;
+ }
+
+ if( dest.projName=="longlat" ) {
+ // convert radians to decimal degrees
+ point.x *= Proj4js.common.R2D;
+ point.y *= Proj4js.common.R2D;
+ } else { // else project
+ dest.forward(point);
+ if (dest.to_meter) {
+ point.x /= dest.to_meter;
+ point.y /= dest.to_meter;
+ }
+ }
+
+ // DGR, 2010/11/12
+ if (dest.axis!="enu") {
+ this.adjust_axis(dest,true,point);
+ }
+
+ return point;
+ }, // transform()
+
+ /** datum_transform()
+ source coordinate system definition,
+ destination coordinate system definition,
+ point to transform in geodetic coordinates (long, lat, height)
+ */
+ datum_transform : function( source, dest, point ) {
+
+ // Short cut if the datums are identical.
+ if( source.compare_datums( dest ) ) {
+ return point; // in this case, zero is sucess,
+ // whereas cs_compare_datums returns 1 to indicate TRUE
+ // confusing, should fix this
+ }
+
+ // Explicitly skip datum transform by setting 'datum=none' as parameter for either source or dest
+ if( source.datum_type == Proj4js.common.PJD_NODATUM
+ || dest.datum_type == Proj4js.common.PJD_NODATUM) {
+ return point;
+ }
+
+ // Do we need to go through geocentric coordinates?
+ if( source.es != dest.es || source.a != dest.a
+ || source.datum_type == Proj4js.common.PJD_3PARAM
+ || source.datum_type == Proj4js.common.PJD_7PARAM
+ || dest.datum_type == Proj4js.common.PJD_3PARAM
+ || dest.datum_type == Proj4js.common.PJD_7PARAM)
+ {
+
+ // Convert to geocentric coordinates.
+ source.geodetic_to_geocentric( point );
+ // CHECK_RETURN;
+
+ // Convert between datums
+ if( source.datum_type == Proj4js.common.PJD_3PARAM || source.datum_type == Proj4js.common.PJD_7PARAM ) {
+ source.geocentric_to_wgs84(point);
+ // CHECK_RETURN;
+ }
+
+ if( dest.datum_type == Proj4js.common.PJD_3PARAM || dest.datum_type == Proj4js.common.PJD_7PARAM ) {
+ dest.geocentric_from_wgs84(point);
+ // CHECK_RETURN;
+ }
+
+ // Convert back to geodetic coordinates
+ dest.geocentric_to_geodetic( point );
+ // CHECK_RETURN;
+ }
+
+ return point;
+ }, // cs_datum_transform
+
+ /**
+ * Function: adjust_axis
+ * Normalize or de-normalized the x/y/z axes. The normal form is "enu"
+ * (easting, northing, up).
+ * Parameters:
+ * crs {Proj4js.Proj} the coordinate reference system
+ * denorm {Boolean} when false, normalize
+ * point {Object} the coordinates to adjust
+ */
+ adjust_axis: function(crs, denorm, point) {
+ var xin= point.x, yin= point.y, zin= point.z || 0.0;
+ var v, t;
+ for (var i= 0; i<3; i++) {
+ if (denorm && i==2 && point.z===undefined) { continue; }
+ if (i==0) { v= xin; t= 'x'; }
+ else if (i==1) { v= yin; t= 'y'; }
+ else { v= zin; t= 'z'; }
+ switch(crs.axis[i]) {
+ case 'e':
+ point[t]= v;
+ break;
+ case 'w':
+ point[t]= -v;
+ break;
+ case 'n':
+ point[t]= v;
+ break;
+ case 's':
+ point[t]= -v;
+ break;
+ case 'u':
+ if (point[t]!==undefined) { point.z= v; }
+ break;
+ case 'd':
+ if (point[t]!==undefined) { point.z= -v; }
+ break;
+ default :
+ alert("ERROR: unknow axis ("+crs.axis[i]+") - check definition of "+crs.projName);
+ return null;
+ }
+ }
+ return point;
+ },
+
+ /**
+ * Function: reportError
+ * An internal method to report errors back to user.
+ * Override this in applications to report error messages or throw exceptions.
+ */
+ reportError: function(msg) {
+ //console.log(msg);
+ },
+
+/**
+ *
+ * Title: Private Methods
+ * The following properties and methods are intended for internal use only.
+ *
+ * This is a minimal implementation of JavaScript inheritance methods so that
+ * Proj4js can be used as a stand-alone library.
+ * These are copies of the equivalent OpenLayers methods at v2.7
+ */
+
+/**
+ * Function: extend
+ * Copy all properties of a source object to a destination object. Modifies
+ * the passed in destination object. Any properties on the source object
+ * that are set to undefined will not be (re)set on the destination object.
+ *
+ * Parameters:
+ * destination - {Object} The object that will be modified
+ * source - {Object} The object with properties to be set on the destination
+ *
+ * Returns:
+ * {Object} The destination object.
+ */
+ extend: function(destination, source) {
+ destination = destination || {};
+ if(source) {
+ for(var property in source) {
+ var value = source[property];
+ if(value !== undefined) {
+ destination[property] = value;
+ }
+ }
+ }
+ return destination;
+ },
+
+/**
+ * Constructor: Class
+ * Base class used to construct all other classes. Includes support for
+ * multiple inheritance.
+ *
+ */
+ Class: function() {
+ var Class = function() {
+ this.initialize.apply(this, arguments);
+ };
+
+ var extended = {};
+ var parent;
+ for(var i=0; i<arguments.length; ++i) {
+ if(typeof arguments[i] == "function") {
+ // get the prototype of the superclass
+ parent = arguments[i].prototype;
+ } else {
+ // in this case we're extending with the prototype
+ parent = arguments[i];
+ }
+ Proj4js.extend(extended, parent);
+ }
+ Class.prototype = extended;
+
+ return Class;
+ },
+
+ /**
+ * Function: bind
+ * Bind a function to an object. Method to easily create closures with
+ * 'this' altered.
+ *
+ * Parameters:
+ * func - {Function} Input function.
+ * object - {Object} The object to bind to the input function (as this).
+ *
+ * Returns:
+ * {Function} A closure with 'this' set to the passed in object.
+ */
+ bind: function(func, object) {
+ // create a reference to all arguments past the second one
+ var args = Array.prototype.slice.apply(arguments, [2]);
+ return function() {
+ // Push on any additional arguments from the actual function call.
+ // These will come after those sent to the bind call.
+ var newArgs = args.concat(
+ Array.prototype.slice.apply(arguments, [0])
+ );
+ return func.apply(object, newArgs);
+ };
+ },
+
+/**
+ * The following properties and methods handle dynamic loading of JSON objects.
+ */
+
+ /**
+ * Property: scriptName
+ * {String} The filename of this script without any path.
+ */
+ scriptName: "proj4js.js",
+
+ /**
+ * Property: defsLookupService
+ * AJAX service to retreive projection definition parameters from
+ */
+ defsLookupService: 'http://spatialreference.org/ref',
+
+ /**
+ * Property: libPath
+ * internal: http server path to library code.
+ */
+ libPath: null,
+
+ /**
+ * Function: getScriptLocation
+ * Return the path to this script.
+ *
+ * Returns:
+ * Path to this script
+ */
+ getScriptLocation: function () {
+ if (this.libPath) return this.libPath;
+ var scriptName = this.scriptName;
+ var scriptNameLen = scriptName.length;
+
+ var scripts = document.getElementsByTagName('script');
+ for (var i = 0; i < scripts.length; i++) {
+ var src = scripts[i].getAttribute('src');
+ if (src) {
+ var index = src.lastIndexOf(scriptName);
+ // is it found, at the end of the URL?
+ if ((index > -1) && (index + scriptNameLen == src.length)) {
+ this.libPath = src.slice(0, -scriptNameLen);
+ break;
+ }
+ }
+ }
+ return this.libPath||"";
+ },
+
+ /**
+ * Function: loadScript
+ * Load a JS file from a URL into a <script> tag in the page.
+ *
+ * Parameters:
+ * url - {String} The URL containing the script to load
+ * onload - {Function} A method to be executed when the script loads successfully
+ * onfail - {Function} A method to be executed when there is an error loading the script
+ * loadCheck - {Function} A boolean method that checks to see if the script
+ * has loaded. Typically this just checks for the existance of
+ * an object in the file just loaded.
+ */
+ loadScript: function(url, onload, onfail, loadCheck) {
+ var script = document.createElement('script');
+ script.defer = false;
+ script.type = "text/javascript";
+ script.id = url;
+ script.src = url;
+ script.onload = onload;
+ script.onerror = onfail;
+ script.loadCheck = loadCheck;
+ if (/MSIE/.test(navigator.userAgent)) {
+ script.onreadystatechange = this.checkReadyState;
+ }
+ document.getElementsByTagName('head')[0].appendChild(script);
+ },
+
+ /**
+ * Function: checkReadyState
+ * IE workaround since there is no onerror handler. Calls the user defined
+ * loadCheck method to determine if the script is loaded.
+ *
+ */
+ checkReadyState: function() {
+ if (this.readyState == 'loaded') {
+ if (!this.loadCheck()) {
+ this.onerror();
+ } else {
+ this.onload();
+ }
+ }
+ }
+};
+
+/**
+ * Class: Proj4js.Proj
+ *
+ * Proj objects provide transformation methods for point coordinates
+ * between geodetic latitude/longitude and a projected coordinate system.
+ * once they have been initialized with a projection code.
+ *
+ * Initialization of Proj objects is with a projection code, usually EPSG codes,
+ * which is the key that will be used with the Proj4js.defs array.
+ *
+ * The code passed in will be stripped of colons and converted to uppercase
+ * to locate projection definition files.
+ *
+ * A projection object has properties for units and title strings.
+ */
+Proj4js.Proj = Proj4js.Class({
+
+ /**
+ * Property: readyToUse
+ * Flag to indicate if initialization is complete for this Proj object
+ */
+ readyToUse: false,
+
+ /**
+ * Property: title
+ * The title to describe the projection
+ */
+ title: null,
+
+ /**
+ * Property: projName
+ * The projection class for this projection, e.g. lcc (lambert conformal conic,
+ * or merc for mercator). These are exactly equivalent to their Proj4
+ * counterparts.
+ */
+ projName: null,
+ /**
+ * Property: units
+ * The units of the projection. Values include 'm' and 'degrees'
+ */
+ units: null,
+ /**
+ * Property: datum
+ * The datum specified for the projection
+ */
+ datum: null,
+ /**
+ * Property: x0
+ * The x coordinate origin
+ */
+ x0: 0,
+ /**
+ * Property: y0
+ * The y coordinate origin
+ */
+ y0: 0,
+ /**
+ * Property: localCS
+ * Flag to indicate if the projection is a local one in which no transforms
+ * are required.
+ */
+ localCS: false,
+
+ /**
+ * Property: queue
+ * Buffer (FIFO) to hold callbacks waiting to be called when projection loaded.
+ */
+ queue: null,
+
+ /**
+ * Constructor: initialize
+ * Constructor for Proj4js.Proj objects
+ *
+ * Parameters:
+ * srsCode - a code for map projection definition parameters. These are usually
+ * (but not always) EPSG codes.
+ */
+ initialize: function(srsCode, callback) {
+ this.srsCodeInput = srsCode;
+
+ //Register callbacks prior to attempting to process definition
+ this.queue = [];
+ if( callback ){
+ this.queue.push( callback );
+ }
+
+ //check to see if this is a WKT string
+ if ((srsCode.indexOf('GEOGCS') >= 0) ||
+ (srsCode.indexOf('GEOCCS') >= 0) ||
+ (srsCode.indexOf('PROJCS') >= 0) ||
+ (srsCode.indexOf('LOCAL_CS') >= 0)) {
+ this.parseWKT(srsCode);
+ this.deriveConstants();
+ this.loadProjCode(this.projName);
+ return;
+ }
+
+ // DGR 2008-08-03 : support urn and url
+ if (srsCode.indexOf('urn:') == 0) {
+ //urn:ORIGINATOR:def:crs:CODESPACE:VERSION:ID
+ var urn = srsCode.split(':');
+ if ((urn[1] == 'ogc' || urn[1] =='x-ogc') &&
+ (urn[2] =='def') &&
+ (urn[3] =='crs')) {
+ srsCode = urn[4]+':'+urn[urn.length-1];
+ }
+ } else if (srsCode.indexOf('http://') == 0) {
+ //url#ID
+ var url = srsCode.split('#');
+ if (url[0].match(/epsg.org/)) {
+ // http://www.epsg.org/#
+ srsCode = 'EPSG:'+url[1];
+ } else if (url[0].match(/RIG.xml/)) {
+ //http://librairies.ign.fr/geoportail/resources/RIG.xml#
+ //http://interop.ign.fr/registers/ign/RIG.xml#
+ srsCode = 'IGNF:'+url[1];
+ }
+ }
+ this.srsCode = srsCode.toUpperCase();
+ if (this.srsCode.indexOf("EPSG") == 0) {
+ this.srsCode = this.srsCode;
+ this.srsAuth = 'epsg';
+ this.srsProjNumber = this.srsCode.substring(5);
+ // DGR 2007-11-20 : authority IGNF
+ } else if (this.srsCode.indexOf("IGNF") == 0) {
+ this.srsCode = this.srsCode;
+ this.srsAuth = 'IGNF';
+ this.srsProjNumber = this.srsCode.substring(5);
+ // DGR 2008-06-19 : pseudo-authority CRS for WMS
+ } else if (this.srsCode.indexOf("CRS") == 0) {
+ this.srsCode = this.srsCode;
+ this.srsAuth = 'CRS';
+ this.srsProjNumber = this.srsCode.substring(4);
+ } else {
+ this.srsAuth = '';
+ this.srsProjNumber = this.srsCode;
+ }
+
+ this.loadProjDefinition();
+ },
+
+/**
+ * Function: loadProjDefinition
+ * Loads the coordinate system initialization string if required.
+ * Note that dynamic loading happens asynchronously so an application must
+ * wait for the readyToUse property is set to true.
+ * To prevent dynamic loading, include the defs through a script tag in
+ * your application.
+ *
+ */
+ loadProjDefinition: function() {
+ //check in memory
+ if (Proj4js.defs[this.srsCode]) {
+ this.defsLoaded();
+ return;
+ }
+
+ //else check for def on the server
+ var url = Proj4js.getScriptLocation() + 'defs/' + this.srsAuth.toUpperCase() + this.srsProjNumber + '.js';
+ Proj4js.loadScript(url,
+ Proj4js.bind(this.defsLoaded, this),
+ Proj4js.bind(this.loadFromService, this),
+ Proj4js.bind(this.checkDefsLoaded, this) );
+ },
+
+/**
+ * Function: loadFromService
+ * Creates the REST URL for loading the definition from a web service and
+ * loads it.
+ *
+ */
+ loadFromService: function() {
+ //else load from web service
+ var url = Proj4js.defsLookupService +'/' + this.srsAuth +'/'+ this.srsProjNumber + '/proj4js/';
+ Proj4js.loadScript(url,
+ Proj4js.bind(this.defsLoaded, this),
+ Proj4js.bind(this.defsFailed, this),
+ Proj4js.bind(this.checkDefsLoaded, this) );
+ },
+
+/**
+ * Function: defsLoaded
+ * Continues the Proj object initilization once the def file is loaded
+ *
+ */
+ defsLoaded: function() {
+ this.parseDefs();
+ this.loadProjCode(this.projName);
+ },
+
+/**
+ * Function: checkDefsLoaded
+ * This is the loadCheck method to see if the def object exists
+ *
+ */
+ checkDefsLoaded: function() {
+ if (Proj4js.defs[this.srsCode]) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+ /**
+ * Function: defsFailed
+ * Report an error in loading the defs file, but continue on using WGS84
+ *
+ */
+ defsFailed: function() {
+ Proj4js.reportError('failed to load projection definition for: '+this.srsCode);
+ Proj4js.defs[this.srsCode] = Proj4js.defs['WGS84']; //set it to something so it can at least continue
+ this.defsLoaded();
+ },
+
+/**
+ * Function: loadProjCode
+ * Loads projection class code dynamically if required.
+ * Projection code may be included either through a script tag or in
+ * a built version of proj4js
+ *
+ */
+ loadProjCode: function(projName) {
+ if (Proj4js.Proj[projName]) {
+ this.initTransforms();
+ return;
+ }
+
+ //the URL for the projection code
+ var url = Proj4js.getScriptLocation() + 'projCode/' + projName + '.js';
+ Proj4js.loadScript(url,
+ Proj4js.bind(this.loadProjCodeSuccess, this, projName),
+ Proj4js.bind(this.loadProjCodeFailure, this, projName),
+ Proj4js.bind(this.checkCodeLoaded, this, projName) );
+ },
+
+ /**
+ * Function: loadProjCodeSuccess
+ * Loads any proj dependencies or continue on to final initialization.
+ *
+ */
+ loadProjCodeSuccess: function(projName) {
+ if (Proj4js.Proj[projName].dependsOn){
+ this.loadProjCode(Proj4js.Proj[projName].dependsOn);
+ } else {
+ this.initTransforms();
+ }
+ },
+
+ /**
+ * Function: defsFailed
+ * Report an error in loading the proj file. Initialization of the Proj
+ * object has failed and the readyToUse flag will never be set.
+ *
+ */
+ loadProjCodeFailure: function(projName) {
+ Proj4js.reportError("failed to find projection file for: " + projName);
+ //TBD initialize with identity transforms so proj will still work?
+ },
+
+/**
+ * Function: checkCodeLoaded
+ * This is the loadCheck method to see if the projection code is loaded
+ *
+ */
+ checkCodeLoaded: function(projName) {
+ if (Proj4js.Proj[projName]) {
+ return true;
+ } else {
+ return false;
+ }
+ },
+
+/**
+ * Function: initTransforms
+ * Finalize the initialization of the Proj object
+ *
+ */
+ initTransforms: function() {
+ Proj4js.extend(this, Proj4js.Proj[this.projName]);
+ this.init();
+ this.readyToUse = true;
+ if( this.queue ) {
+ var item;
+ while( (item = this.queue.shift()) ) {
+ item.call( this, this );
+ }
+ }
+ },
+
+/**
+ * Function: parseWKT
+ * Parses a WKT string to get initialization parameters
+ *
+ */
+ wktRE: /^(\w+)\[(.*)\]$/,
+ parseWKT: function(wkt) {
+ var wktMatch = wkt.match(this.wktRE);
+ if (!wktMatch) return;
+ var wktObject = wktMatch[1];
+ var wktContent = wktMatch[2];
+ var wktTemp = wktContent.split(",");
+ var wktName;
+ if (wktObject.toUpperCase() == "TOWGS84") {
+ wktName = wktObject; //no name supplied for the TOWGS84 array
+ } else {
+ wktName = wktTemp.shift();
+ }
+ wktName = wktName.replace(/^\"/,"");
+ wktName = wktName.replace(/\"$/,"");
+
+ /*
+ wktContent = wktTemp.join(",");
+ var wktArray = wktContent.split("],");
+ for (var i=0; i<wktArray.length-1; ++i) {
+ wktArray[i] += "]";
+ }
+ */
+
+ var wktArray = new Array();
+ var bkCount = 0;
+ var obj = "";
+ for (var i=0; i<wktTemp.length; ++i) {
+ var token = wktTemp[i];
+ for (var j=0; j<token.length; ++j) {
+ if (token.charAt(j) == "[") ++bkCount;
+ if (token.charAt(j) == "]") --bkCount;
+ }
+ obj += token;
+ if (bkCount === 0) {
+ wktArray.push(obj);
+ obj = "";
+ } else {
+ obj += ",";
+ }
+ }
+
+ //do something based on the type of the wktObject being parsed
+ //add in variations in the spelling as required
+ switch (wktObject) {
+ case 'LOCAL_CS':
+ this.projName = 'identity'
+ this.localCS = true;
+ this.srsCode = wktName;
+ break;
+ case 'GEOGCS':
+ this.projName = 'longlat'
+ this.geocsCode = wktName;
+ if (!this.srsCode) this.srsCode = wktName;
+ break;
+ case 'PROJCS':
+ this.srsCode = wktName;
+ break;
+ case 'GEOCCS':
+ break;
+ case 'PROJECTION':
+ this.projName = Proj4js.wktProjections[wktName]
+ break;
+ case 'DATUM':
+ this.datumName = wktName;
+ break;
+ case 'LOCAL_DATUM':
+ this.datumCode = 'none';
+ break;
+ case 'SPHEROID':
+ this.ellps = wktName;
+ this.a = parseFloat(wktArray.shift());
+ this.rf = parseFloat(wktArray.shift());
+ break;
+ case 'PRIMEM':
+ this.from_greenwich = parseFloat(wktArray.shift()); //to radians?
+ break;
+ case 'UNIT':
+ this.units = wktName;
+ this.unitsPerMeter = parseFloat(wktArray.shift());
+ break;
+ case 'PARAMETER':
+ var name = wktName.toLowerCase();
+ var value = parseFloat(wktArray.shift());
+ //there may be many variations on the wktName values, add in case
+ //statements as required
+ switch (name) {
+ case 'false_easting':
+ this.x0 = value;
+ break;
+ case 'false_northing':
+ this.y0 = value;
+ break;
+ case 'scale_factor':
+ this.k0 = value;
+ break;
+ case 'central_meridian':
+ this.long0 = value*Proj4js.common.D2R;
+ break;
+ case 'latitude_of_origin':
+ this.lat0 = value*Proj4js.common.D2R;
+ break;
+ case 'more_here':
+ break;
+ default:
+ break;
+ }
+ break;
+ case 'TOWGS84':
+ this.datum_params = wktArray;
+ break;
+ //DGR 2010-11-12: AXIS
+ case 'AXIS':
+ var name= wktName.toLowerCase();
+ var value= wktArray.shift();
+ switch (value) {
+ case 'EAST' : value= 'e'; break;
+ case 'WEST' : value= 'w'; break;
+ case 'NORTH': value= 'n'; break;
+ case 'SOUTH': value= 's'; break;
+ case 'UP' : value= 'u'; break;
+ case 'DOWN' : value= 'd'; break;
+ case 'OTHER':
+ default : value= ' '; break;//FIXME
+ }
+ if (!this.axis) { this.axis= "enu"; }
+ switch(name) {
+ case 'x': this.axis= value + this.axis.substr(1,2); break;
+ case 'y': this.axis= this.axis.substr(0,1) + value + this.axis.substr(2,1); break;
+ case 'z': this.axis= this.axis.substr(0,2) + value ; break;
+ default : break;
+ }
+ case 'MORE_HERE':
+ break;
+ default:
+ break;
+ }
+ for (var i=0; i<wktArray.length; ++i) {
+ this.parseWKT(wktArray[i]);
+ }
+ },
+
+/**
+ * Function: parseDefs
+ * Parses the PROJ.4 initialization string and sets the associated properties.
+ *
+ */
+ parseDefs: function() {
+ this.defData = Proj4js.defs[this.srsCode];
+ var paramName, paramVal;
+ if (!this.defData) {
+ return;
+ }
+ var paramArray=this.defData.split("+");
+
+ for (var prop=0; prop<paramArray.length; prop++) {
+ var property = paramArray[prop].split("=");
+ paramName = property[0].toLowerCase();
+ paramVal = property[1];
+
+ switch (paramName.replace(/\s/gi,"")) { // trim out spaces
+ case "": break; // throw away nameless parameter
+ case "title": this.title = paramVal; break;
+ case "proj": this.projName = paramVal.replace(/\s/gi,""); break;
+ case "units": this.units = paramVal.replace(/\s/gi,""); break;
+ case "datum": this.datumCode = paramVal.replace(/\s/gi,""); break;
+ case "nadgrids": this.nagrids = paramVal.replace(/\s/gi,""); break;
+ case "ellps": this.ellps = paramVal.replace(/\s/gi,""); break;
+ case "a": this.a = parseFloat(paramVal); break; // semi-major radius
+ case "b": this.b = parseFloat(paramVal); break; // semi-minor radius
+ // DGR 2007-11-20
+ case "rf": this.rf = parseFloat(paramVal); break; // inverse flattening rf= a/(a-b)
+ case "lat_0": this.lat0 = paramVal*Proj4js.common.D2R; break; // phi0, central latitude
+ case "lat_1": this.lat1 = paramVal*Proj4js.common.D2R; break; //standard parallel 1
+ case "lat_2": this.lat2 = paramVal*Proj4js.common.D2R; break; //standard parallel 2
+ case "lat_ts": this.lat_ts = paramVal*Proj4js.common.D2R; break; // used in merc and eqc
+ case "lon_0": this.long0 = paramVal*Proj4js.common.D2R; break; // lam0, central longitude
+ case "alpha": this.alpha = parseFloat(paramVal)*Proj4js.common.D2R; break; //for somerc projection
+ case "lonc": this.longc = paramVal*Proj4js.common.D2R; break; //for somerc projection
+ case "x_0": this.x0 = parseFloat(paramVal); break; // false easting
+ case "y_0": this.y0 = parseFloat(paramVal); break; // false northing
+ case "k_0": this.k0 = parseFloat(paramVal); break; // projection scale factor
+ case "k": this.k0 = parseFloat(paramVal); break; // both forms returned
+ case "r_a": this.R_A = true; break; // sphere--area of ellipsoid
+ case "zone": this.zone = parseInt(paramVal,10); break; // UTM Zone
+ case "south": this.utmSouth = true; break; // UTM north/south
+ case "towgs84":this.datum_params = paramVal.split(","); break;
+ case "to_meter": this.to_meter = parseFloat(paramVal); break; // cartesian scaling
+ case "from_greenwich": this.from_greenwich = paramVal*Proj4js.common.D2R; break;
+ // DGR 2008-07-09 : if pm is not a well-known prime meridian take
+ // the value instead of 0.0, then convert to radians
+ case "pm": paramVal = paramVal.replace(/\s/gi,"");
+ this.from_greenwich = Proj4js.PrimeMeridian[paramVal] ?
+ Proj4js.PrimeMeridian[paramVal] : parseFloat(paramVal);
+ this.from_greenwich *= Proj4js.common.D2R;
+ break;
+ // DGR 2010-11-12: axis
+ case "axis": paramVal = paramVal.replace(/\s/gi,"");
+ var legalAxis= "ewnsud";
+ if (paramVal.length==3 &&
+ legalAxis.indexOf(paramVal.substr(0,1))!=-1 &&
+ legalAxis.indexOf(paramVal.substr(1,1))!=-1 &&
+ legalAxis.indexOf(paramVal.substr(2,1))!=-1) {
+ this.axis= paramVal;
+ } //FIXME: be silent ?
+ break
+ case "no_defs": break;
+ default: //alert("Unrecognized parameter: " + paramName);
+ } // switch()
+ } // for paramArray
+ this.deriveConstants();
+ },
+
+/**
+ * Function: deriveConstants
+ * Sets several derived constant values and initialization of datum and ellipse
+ * parameters.
+ *
+ */
+ deriveConstants: function() {
+ if (this.nagrids == '@null') this.datumCode = 'none';
+ if (this.datumCode && this.datumCode != 'none') {
+ var datumDef = Proj4js.Datum[this.datumCode];
+ if (datumDef) {
+ this.datum_params = datumDef.towgs84 ? datumDef.towgs84.split(',') : null;
+ this.ellps = datumDef.ellipse;
+ this.datumName = datumDef.datumName ? datumDef.datumName : this.datumCode;
+ }
+ }
+ if (!this.a) { // do we have an ellipsoid?
+ var ellipse = Proj4js.Ellipsoid[this.ellps] ? Proj4js.Ellipsoid[this.ellps] : Proj4js.Ellipsoid['WGS84'];
+ Proj4js.extend(this, ellipse);
+ }
+ if (this.rf && !this.b) this.b = (1.0 - 1.0/this.rf) * this.a;
+ if (this.rf === 0 || Math.abs(this.a - this.b)<Proj4js.common.EPSLN) {
+ this.sphere = true;
+ this.b= this.a;
+ }
+ this.a2 = this.a * this.a; // used in geocentric
+ this.b2 = this.b * this.b; // used in geocentric
+ this.es = (this.a2-this.b2)/this.a2; // e ^ 2
+ this.e = Math.sqrt(this.es); // eccentricity
+ if (this.R_A) {
+ this.a *= 1. - this.es * (Proj4js.common.SIXTH + this.es * (Proj4js.common.RA4 + this.es * Proj4js.common.RA6));
+ this.a2 = this.a * this.a;
+ this.b2 = this.b * this.b;
+ this.es = 0.;
+ }
+ this.ep2=(this.a2-this.b2)/this.b2; // used in geocentric
+ if (!this.k0) this.k0 = 1.0; //default value
+ //DGR 2010-11-12: axis
+ if (!this.axis) { this.axis= "enu"; }
+
+ this.datum = new Proj4js.datum(this);
+ }
+});
+
+Proj4js.Proj.longlat = {
+ init: function() {
+ //no-op for longlat
+ },
+ forward: function(pt) {
+ //identity transform
+ return pt;
+ },
+ inverse: function(pt) {
+ //identity transform
+ return pt;
+ }
+};
+Proj4js.Proj.identity = Proj4js.Proj.longlat;
+
+/**
+ Proj4js.defs is a collection of coordinate system definition objects in the
+ PROJ.4 command line format.
+ Generally a def is added by means of a separate .js file for example:
+
+ <SCRIPT type="text/javascript" src="defs/EPSG26912.js"></SCRIPT>
+
+ def is a CS definition in PROJ.4 WKT format, for example:
+ +proj="tmerc" //longlat, etc.
+ +a=majorRadius
+ +b=minorRadius
+ +lat0=somenumber
+ +long=somenumber
+*/
+Proj4js.defs = {
+ // These are so widely used, we'll go ahead and throw them in
+ // without requiring a separate .js file
+ 'WGS84': "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees",
+ 'EPSG:4326': "+title=long/lat:WGS84 +proj=longlat +a=6378137.0 +b=6356752.31424518 +ellps=WGS84 +datum=WGS84 +units=degrees",
+ 'EPSG:4269': "+title=long/lat:NAD83 +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees",
+ 'EPSG:3875': "+title= Google Mercator +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
+};
+Proj4js.defs['EPSG:3785'] = Proj4js.defs['EPSG:3875']; //maintain backward compat, official code is 3875
+Proj4js.defs['GOOGLE'] = Proj4js.defs['EPSG:3875'];
+Proj4js.defs['EPSG:900913'] = Proj4js.defs['EPSG:3875'];
+Proj4js.defs['EPSG:102113'] = Proj4js.defs['EPSG:3875'];
+
+Proj4js.common = {
+ PI : 3.141592653589793238, //Math.PI,
+ HALF_PI : 1.570796326794896619, //Math.PI*0.5,
+ TWO_PI : 6.283185307179586477, //Math.PI*2,
+ FORTPI : 0.78539816339744833,
+ R2D : 57.29577951308232088,
+ D2R : 0.01745329251994329577,
+ SEC_TO_RAD : 4.84813681109535993589914102357e-6, /* SEC_TO_RAD = Pi/180/3600 */
+ EPSLN : 1.0e-10,
+ MAX_ITER : 20,
+ // following constants from geocent.c
+ COS_67P5 : 0.38268343236508977, /* cosine of 67.5 degrees */
+ AD_C : 1.0026000, /* Toms region 1 constant */
+
+ /* datum_type values */
+ PJD_UNKNOWN : 0,
+ PJD_3PARAM : 1,
+ PJD_7PARAM : 2,
+ PJD_GRIDSHIFT: 3,
+ PJD_WGS84 : 4, // WGS84 or equivalent
+ PJD_NODATUM : 5, // WGS84 or equivalent
+ SRS_WGS84_SEMIMAJOR : 6378137.0, // only used in grid shift transforms
+
+ // ellipoid pj_set_ell.c
+ SIXTH : .1666666666666666667, /* 1/6 */
+ RA4 : .04722222222222222222, /* 17/360 */
+ RA6 : .02215608465608465608, /* 67/3024 */
+ RV4 : .06944444444444444444, /* 5/72 */
+ RV6 : .04243827160493827160, /* 55/1296 */
+
+// Function to compute the constant small m which is the radius of
+// a parallel of latitude, phi, divided by the semimajor axis.
+// -----------------------------------------------------------------
+ msfnz : function(eccent, sinphi, cosphi) {
+ var con = eccent * sinphi;
+ return cosphi/(Math.sqrt(1.0 - con * con));
+ },
+
+// Function to compute the constant small t for use in the forward
+// computations in the Lambert Conformal Conic and the Polar
+// Stereographic projections.
+// -----------------------------------------------------------------
+ tsfnz : function(eccent, phi, sinphi) {
+ var con = eccent * sinphi;
+ var com = .5 * eccent;
+ con = Math.pow(((1.0 - con) / (1.0 + con)), com);
+ return (Math.tan(.5 * (this.HALF_PI - phi))/con);
+ },
+
+// Function to compute the latitude angle, phi2, for the inverse of the
+// Lambert Conformal Conic and Polar Stereographic projections.
+// ----------------------------------------------------------------
+ phi2z : function(eccent, ts) {
+ var eccnth = .5 * eccent;
+ var con, dphi;
+ var phi = this.HALF_PI - 2 * Math.atan(ts);
+ for (var i = 0; i <= 15; i++) {
+ con = eccent * Math.sin(phi);
+ dphi = this.HALF_PI - 2 * Math.atan(ts *(Math.pow(((1.0 - con)/(1.0 + con)),eccnth))) - phi;
+ phi += dphi;
+ if (Math.abs(dphi) <= .0000000001) return phi;
+ }
+ alert("phi2z has NoConvergence");
+ return (-9999);
+ },
+
+/* Function to compute constant small q which is the radius of a
+ parallel of latitude, phi, divided by the semimajor axis.
+------------------------------------------------------------*/
+ qsfnz : function(eccent,sinphi) {
+ var con;
+ if (eccent > 1.0e-7) {
+ con = eccent * sinphi;
+ return (( 1.0- eccent * eccent) * (sinphi /(1.0 - con * con) - (.5/eccent)*Math.log((1.0 - con)/(1.0 + con))));
+ } else {
+ return(2.0 * sinphi);
+ }
+ },
+
+/* Function to eliminate roundoff errors in asin
+----------------------------------------------*/
+ asinz : function(x) {
+ if (Math.abs(x)>1.0) {
+ x=(x>1.0)?1.0:-1.0;
+ }
+ return Math.asin(x);
+ },
+
+// following functions from gctpc cproj.c for transverse mercator projections
+ e0fn : function(x) {return(1.0-0.25*x*(1.0+x/16.0*(3.0+1.25*x)));},
+ e1fn : function(x) {return(0.375*x*(1.0+0.25*x*(1.0+0.46875*x)));},
+ e2fn : function(x) {return(0.05859375*x*x*(1.0+0.75*x));},
+ e3fn : function(x) {return(x*x*x*(35.0/3072.0));},
+ mlfn : function(e0,e1,e2,e3,phi) {return(e0*phi-e1*Math.sin(2.0*phi)+e2*Math.sin(4.0*phi)-e3*Math.sin(6.0*phi));},
+
+ srat : function(esinp, exp) {
+ return(Math.pow((1.0-esinp)/(1.0+esinp), exp));
+ },
+
+// Function to return the sign of an argument
+ sign : function(x) { if (x < 0.0) return(-1); else return(1);},
+
+// Function to adjust longitude to -180 to 180; input in radians
+ adjust_lon : function(x) {
+ x = (Math.abs(x) < this.PI) ? x: (x - (this.sign(x)*this.TWO_PI) );
+ return x;
+ },
+
+// IGNF - DGR : algorithms used by IGN France
+
+// Function to adjust latitude to -90 to 90; input in radians
+ adjust_lat : function(x) {
+ x= (Math.abs(x) < this.HALF_PI) ? x: (x - (this.sign(x)*this.PI) );
+ return x;
+ },
+
+// Latitude Isometrique - close to tsfnz ...
+ latiso : function(eccent, phi, sinphi) {
+ if (Math.abs(phi) > this.HALF_PI) return +Number.NaN;
+ if (phi==this.HALF_PI) return Number.POSITIVE_INFINITY;
+ if (phi==-1.0*this.HALF_PI) return -1.0*Number.POSITIVE_INFINITY;
+
+ var con= eccent*sinphi;
+ return Math.log(Math.tan((this.HALF_PI+phi)/2.0))+eccent*Math.log((1.0-con)/(1.0+con))/2.0;
+ },
+
+ fL : function(x,L) {
+ return 2.0*Math.atan(x*Math.exp(L)) - this.HALF_PI;
+ },
+
+// Inverse Latitude Isometrique - close to ph2z
+ invlatiso : function(eccent, ts) {
+ var phi= this.fL(1.0,ts);
+ var Iphi= 0.0;
+ var con= 0.0;
+ do {
+ Iphi= phi;
+ con= eccent*Math.sin(Iphi);
+ phi= this.fL(Math.exp(eccent*Math.log((1.0+con)/(1.0-con))/2.0),ts)
+ } while (Math.abs(phi-Iphi)>1.0e-12);
+ return phi;
+ },
+
+// Needed for Gauss Schreiber
+// Original: Denis Makarov ([email protected])
+// Web Site: http://www.binarythings.com
+ sinh : function(x)
+ {
+ var r= Math.exp(x);
+ r= (r-1.0/r)/2.0;
+ return r;
+ },
+
+ cosh : function(x)
+ {
+ var r= Math.exp(x);
+ r= (r+1.0/r)/2.0;
+ return r;
+ },
+
+ tanh : function(x)
+ {
+ var r= Math.exp(x);
+ r= (r-1.0/r)/(r+1.0/r);
+ return r;
+ },
+
+ asinh : function(x)
+ {
+ var s= (x>= 0? 1.0:-1.0);
+ return s*(Math.log( Math.abs(x) + Math.sqrt(x*x+1.0) ));
+ },
+
+ acosh : function(x)
+ {
+ return 2.0*Math.log(Math.sqrt((x+1.0)/2.0) + Math.sqrt((x-1.0)/2.0));
+ },
+
+ atanh : function(x)
+ {
+ return Math.log((x-1.0)/(x+1.0))/2.0;
+ },
+
+// Grande Normale
+ gN : function(a,e,sinphi)
+ {
+ var temp= e*sinphi;
+ return a/Math.sqrt(1.0 - temp*temp);
+ },
+
+ //code from the PROJ.4 pj_mlfn.c file; this may be useful for other projections
+ pj_enfn: function(es) {
+ var en = new Array();
+ en[0] = this.C00 - es * (this.C02 + es * (this.C04 + es * (this.C06 + es * this.C08)));
+ en[1] = es * (this.C22 - es * (this.C04 + es * (this.C06 + es * this.C08)));
+ var t = es * es;
+ en[2] = t * (this.C44 - es * (this.C46 + es * this.C48));
+ t *= es;
+ en[3] = t * (this.C66 - es * this.C68);
+ en[4] = t * es * this.C88;
+ return en;
+ },
+
+ pj_mlfn: function(phi, sphi, cphi, en) {
+ cphi *= sphi;
+ sphi *= sphi;
+ return(en[0] * phi - cphi * (en[1] + sphi*(en[2]+ sphi*(en[3] + sphi*en[4]))));
+ },
+
+ pj_inv_mlfn: function(arg, es, en) {
+ var k = 1./(1.-es);
+ var phi = arg;
+ for (var i = Proj4js.common.MAX_ITER; i ; --i) { /* rarely goes over 2 iterations */
+ var s = Math.sin(phi);
+ var t = 1. - es * s * s;
+ //t = this.pj_mlfn(phi, s, Math.cos(phi), en) - arg;
+ //phi -= t * (t * Math.sqrt(t)) * k;
+ t = (this.pj_mlfn(phi, s, Math.cos(phi), en) - arg) * (t * Math.sqrt(t)) * k;
+ phi -= t;
+ if (Math.abs(t) < Proj4js.common.EPSLN)
+ return phi;
+ }
+ Proj4js.reportError("cass:pj_inv_mlfn: Convergence error");
+ return phi;
+ },
+
+/* meridinal distance for ellipsoid and inverse
+** 8th degree - accurate to < 1e-5 meters when used in conjuction
+** with typical major axis values.
+** Inverse determines phi to EPS (1e-11) radians, about 1e-6 seconds.
+*/
+ C00: 1.0,
+ C02: .25,
+ C04: .046875,
+ C06: .01953125,
+ C08: .01068115234375,
+ C22: .75,
+ C44: .46875,
+ C46: .01302083333333333333,
+ C48: .00712076822916666666,
+ C66: .36458333333333333333,
+ C68: .00569661458333333333,
+ C88: .3076171875
+
+};
+
+/** datum object
+*/
+Proj4js.datum = Proj4js.Class({
+
+ initialize : function(proj) {
+ this.datum_type = Proj4js.common.PJD_WGS84; //default setting
+ if (proj.datumCode && proj.datumCode == 'none') {
+ this.datum_type = Proj4js.common.PJD_NODATUM;
+ }
+ if (proj && proj.datum_params) {
+ for (var i=0; i<proj.datum_params.length; i++) {
+ proj.datum_params[i]=parseFloat(proj.datum_params[i]);
+ }
+ if (proj.datum_params[0] != 0 || proj.datum_params[1] != 0 || proj.datum_params[2] != 0 ) {
+ this.datum_type = Proj4js.common.PJD_3PARAM;
+ }
+ if (proj.datum_params.length > 3) {
+ if (proj.datum_params[3] != 0 || proj.datum_params[4] != 0 ||
+ proj.datum_params[5] != 0 || proj.datum_params[6] != 0 ) {
+ this.datum_type = Proj4js.common.PJD_7PARAM;
+ proj.datum_params[3] *= Proj4js.common.SEC_TO_RAD;
+ proj.datum_params[4] *= Proj4js.common.SEC_TO_RAD;
+ proj.datum_params[5] *= Proj4js.common.SEC_TO_RAD;
+ proj.datum_params[6] = (proj.datum_params[6]/1000000.0) + 1.0;
+ }
+ }
+ }
+ if (proj) {
+ this.a = proj.a; //datum object also uses these values
+ this.b = proj.b;
+ this.es = proj.es;
+ this.ep2 = proj.ep2;
+ this.datum_params = proj.datum_params;
+ }
+ },
+
+ /****************************************************************/
+ // cs_compare_datums()
+ // Returns TRUE if the two datums match, otherwise FALSE.
+ compare_datums : function( dest ) {
+ if( this.datum_type != dest.datum_type ) {
+ return false; // false, datums are not equal
+ } else if( this.a != dest.a || Math.abs(this.es-dest.es) > 0.000000000050 ) {
+ // the tolerence for es is to ensure that GRS80 and WGS84
+ // are considered identical
+ return false;
+ } else if( this.datum_type == Proj4js.common.PJD_3PARAM ) {
+ return (this.datum_params[0] == dest.datum_params[0]
+ && this.datum_params[1] == dest.datum_params[1]
+ && this.datum_params[2] == dest.datum_params[2]);
+ } else if( this.datum_type == Proj4js.common.PJD_7PARAM ) {
+ return (this.datum_params[0] == dest.datum_params[0]
+ && this.datum_params[1] == dest.datum_params[1]
+ && this.datum_params[2] == dest.datum_params[2]
+ && this.datum_params[3] == dest.datum_params[3]
+ && this.datum_params[4] == dest.datum_params[4]
+ && this.datum_params[5] == dest.datum_params[5]
+ && this.datum_params[6] == dest.datum_params[6]);
+ } else if ( this.datum_type == Proj4js.common.PJD_GRIDSHIFT ||
+ dest.datum_type == Proj4js.common.PJD_GRIDSHIFT ) {
+ alert("ERROR: Grid shift transformations are not implemented.");
+ return false
+ } else {
+ return true; // datums are equal
+ }
+ }, // cs_compare_datums()
+
+ /*
+ * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates
+ * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),
+ * according to the current ellipsoid parameters.
+ *
+ * Latitude : Geodetic latitude in radians (input)
+ * Longitude : Geodetic longitude in radians (input)
+ * Height : Geodetic height, in meters (input)
+ * X : Calculated Geocentric X coordinate, in meters (output)
+ * Y : Calculated Geocentric Y coordinate, in meters (output)
+ * Z : Calculated Geocentric Z coordinate, in meters (output)
+ *
+ */
+ geodetic_to_geocentric : function(p) {
+ var Longitude = p.x;
+ var Latitude = p.y;
+ var Height = p.z ? p.z : 0; //Z value not always supplied
+ var X; // output
+ var Y;
+ var Z;
+
+ var Error_Code=0; // GEOCENT_NO_ERROR;
+ var Rn; /* Earth radius at location */
+ var Sin_Lat; /* Math.sin(Latitude) */
+ var Sin2_Lat; /* Square of Math.sin(Latitude) */
+ var Cos_Lat; /* Math.cos(Latitude) */
+
+ /*
+ ** Don't blow up if Latitude is just a little out of the value
+ ** range as it may just be a rounding issue. Also removed longitude
+ ** test, it should be wrapped by Math.cos() and Math.sin(). NFW for PROJ.4, Sep/2001.
+ */
+ if( Latitude < -Proj4js.common.HALF_PI && Latitude > -1.001 * Proj4js.common.HALF_PI ) {
+ Latitude = -Proj4js.common.HALF_PI;
+ } else if( Latitude > Proj4js.common.HALF_PI && Latitude < 1.001 * Proj4js.common.HALF_PI ) {
+ Latitude = Proj4js.common.HALF_PI;
+ } else if ((Latitude < -Proj4js.common.HALF_PI) || (Latitude > Proj4js.common.HALF_PI)) {
+ /* Latitude out of range */
+ Proj4js.reportError('geocent:lat out of range:'+Latitude);
+ return null;
+ }
+
+ if (Longitude > Proj4js.common.PI) Longitude -= (2*Proj4js.common.PI);
+ Sin_Lat = Math.sin(Latitude);
+ Cos_Lat = Math.cos(Latitude);
+ Sin2_Lat = Sin_Lat * Sin_Lat;
+ Rn = this.a / (Math.sqrt(1.0e0 - this.es * Sin2_Lat));
+ X = (Rn + Height) * Cos_Lat * Math.cos(Longitude);
+ Y = (Rn + Height) * Cos_Lat * Math.sin(Longitude);
+ Z = ((Rn * (1 - this.es)) + Height) * Sin_Lat;
+
+ p.x = X;
+ p.y = Y;
+ p.z = Z;
+ return Error_Code;
+ }, // cs_geodetic_to_geocentric()
+
+
+ geocentric_to_geodetic : function (p) {
+/* local defintions and variables */
+/* end-criterium of loop, accuracy of sin(Latitude) */
+var genau = 1.E-12;
+var genau2 = (genau*genau);
+var maxiter = 30;
+
+ var P; /* distance between semi-minor axis and location */
+ var RR; /* distance between center and location */
+ var CT; /* sin of geocentric latitude */
+ var ST; /* cos of geocentric latitude */
+ var RX;
+ var RK;
+ var RN; /* Earth radius at location */
+ var CPHI0; /* cos of start or old geodetic latitude in iterations */
+ var SPHI0; /* sin of start or old geodetic latitude in iterations */
+ var CPHI; /* cos of searched geodetic latitude */
+ var SPHI; /* sin of searched geodetic latitude */
+ var SDPHI; /* end-criterium: addition-theorem of sin(Latitude(iter)-Latitude(iter-1)) */
+ var At_Pole; /* indicates location is in polar region */
+ var iter; /* # of continous iteration, max. 30 is always enough (s.a.) */
+
+ var X = p.x;
+ var Y = p.y;
+ var Z = p.z ? p.z : 0.0; //Z value not always supplied
+ var Longitude;
+ var Latitude;
+ var Height;
+
+ At_Pole = false;
+ P = Math.sqrt(X*X+Y*Y);
+ RR = Math.sqrt(X*X+Y*Y+Z*Z);
+
+/* special cases for latitude and longitude */
+ if (P/this.a < genau) {
+
+/* special case, if P=0. (X=0., Y=0.) */
+ At_Pole = true;
+ Longitude = 0.0;
+
+/* if (X,Y,Z)=(0.,0.,0.) then Height becomes semi-minor axis
+ * of ellipsoid (=center of mass), Latitude becomes PI/2 */
+ if (RR/this.a < genau) {
+ Latitude = Proj4js.common.HALF_PI;
+ Height = -this.b;
+ return;
+ }
+ } else {
+/* ellipsoidal (geodetic) longitude
+ * interval: -PI < Longitude <= +PI */
+ Longitude=Math.atan2(Y,X);
+ }
+
+/* --------------------------------------------------------------
+ * Following iterative algorithm was developped by
+ * "Institut f�r Erdmessung", University of Hannover, July 1988.
+ * Internet: www.ife.uni-hannover.de
+ * Iterative computation of CPHI,SPHI and Height.
+ * Iteration of CPHI and SPHI to 10**-12 radian resp.
+ * 2*10**-7 arcsec.
+ * --------------------------------------------------------------
+ */
+ CT = Z/RR;
+ ST = P/RR;
+ RX = 1.0/Math.sqrt(1.0-this.es*(2.0-this.es)*ST*ST);
+ CPHI0 = ST*(1.0-this.es)*RX;
+ SPHI0 = CT*RX;
+ iter = 0;
+
+/* loop to find sin(Latitude) resp. Latitude
+ * until |sin(Latitude(iter)-Latitude(iter-1))| < genau */
+ do
+ {
+ iter++;
+ RN = this.a/Math.sqrt(1.0-this.es*SPHI0*SPHI0);
+
+/* ellipsoidal (geodetic) height */
+ Height = P*CPHI0+Z*SPHI0-RN*(1.0-this.es*SPHI0*SPHI0);
+
+ RK = this.es*RN/(RN+Height);
+ RX = 1.0/Math.sqrt(1.0-RK*(2.0-RK)*ST*ST);
+ CPHI = ST*(1.0-RK)*RX;
+ SPHI = CT*RX;
+ SDPHI = SPHI*CPHI0-CPHI*SPHI0;
+ CPHI0 = CPHI;
+ SPHI0 = SPHI;
+ }
+ while (SDPHI*SDPHI > genau2 && iter < maxiter);
+
+/* ellipsoidal (geodetic) latitude */
+ Latitude=Math.atan(SPHI/Math.abs(CPHI));
+
+ p.x = Longitude;
+ p.y = Latitude;
+ p.z = Height;
+ return p;
+ }, // cs_geocentric_to_geodetic()
+
+ /** Convert_Geocentric_To_Geodetic
+ * The method used here is derived from 'An Improved Algorithm for
+ * Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996
+ */
+ geocentric_to_geodetic_noniter : function (p) {
+ var X = p.x;
+ var Y = p.y;
+ var Z = p.z ? p.z : 0; //Z value not always supplied
+ var Longitude;
+ var Latitude;
+ var Height;
+
+ var W; /* distance from Z axis */
+ var W2; /* square of distance from Z axis */
+ var T0; /* initial estimate of vertical component */
+ var T1; /* corrected estimate of vertical component */
+ var S0; /* initial estimate of horizontal component */
+ var S1; /* corrected estimate of horizontal component */
+ var Sin_B0; /* Math.sin(B0), B0 is estimate of Bowring aux variable */
+ var Sin3_B0; /* cube of Math.sin(B0) */
+ var Cos_B0; /* Math.cos(B0) */
+ var Sin_p1; /* Math.sin(phi1), phi1 is estimated latitude */
+ var Cos_p1; /* Math.cos(phi1) */
+ var Rn; /* Earth radius at location */
+ var Sum; /* numerator of Math.cos(phi1) */
+ var At_Pole; /* indicates location is in polar region */
+
+ X = parseFloat(X); // cast from string to float
+ Y = parseFloat(Y);
+ Z = parseFloat(Z);
+
+ At_Pole = false;
+ if (X != 0.0)
+ {
+ Longitude = Math.atan2(Y,X);
+ }
+ else
+ {
+ if (Y > 0)
+ {
+ Longitude = Proj4js.common.HALF_PI;
+ }
+ else if (Y < 0)
+ {
+ Longitude = -Proj4js.common.HALF_PI;
+ }
+ else
+ {
+ At_Pole = true;
+ Longitude = 0.0;
+ if (Z > 0.0)
+ { /* north pole */
+ Latitude = Proj4js.common.HALF_PI;
+ }
+ else if (Z < 0.0)
+ { /* south pole */
+ Latitude = -Proj4js.common.HALF_PI;
+ }
+ else
+ { /* center of earth */
+ Latitude = Proj4js.common.HALF_PI;
+ Height = -this.b;
+ return;
+ }
+ }
+ }
+ W2 = X*X + Y*Y;
+ W = Math.sqrt(W2);
+ T0 = Z * Proj4js.common.AD_C;
+ S0 = Math.sqrt(T0 * T0 + W2);
+ Sin_B0 = T0 / S0;
+ Cos_B0 = W / S0;
+ Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;
+ T1 = Z + this.b * this.ep2 * Sin3_B0;
+ Sum = W - this.a * this.es * Cos_B0 * Cos_B0 * Cos_B0;
+ S1 = Math.sqrt(T1*T1 + Sum * Sum);
+ Sin_p1 = T1 / S1;
+ Cos_p1 = Sum / S1;
+ Rn = this.a / Math.sqrt(1.0 - this.es * Sin_p1 * Sin_p1);
+ if (Cos_p1 >= Proj4js.common.COS_67P5)
+ {
+ Height = W / Cos_p1 - Rn;
+ }
+ else if (Cos_p1 <= -Proj4js.common.COS_67P5)
+ {
+ Height = W / -Cos_p1 - Rn;
+ }
+ else
+ {
+ Height = Z / Sin_p1 + Rn * (this.es - 1.0);
+ }
+ if (At_Pole == false)
+ {
+ Latitude = Math.atan(Sin_p1 / Cos_p1);
+ }
+
+ p.x = Longitude;
+ p.y = Latitude;
+ p.z = Height;
+ return p;
+ }, // geocentric_to_geodetic_noniter()
+
+ /****************************************************************/
+ // pj_geocentic_to_wgs84( p )
+ // p = point to transform in geocentric coordinates (x,y,z)
+ geocentric_to_wgs84 : function ( p ) {
+
+ if( this.datum_type == Proj4js.common.PJD_3PARAM )
+ {
+ // if( x[io] == HUGE_VAL )
+ // continue;
+ p.x += this.datum_params[0];
+ p.y += this.datum_params[1];
+ p.z += this.datum_params[2];
+
+ }
+ else if (this.datum_type == Proj4js.common.PJD_7PARAM)
+ {
+ var Dx_BF =this.datum_params[0];
+ var Dy_BF =this.datum_params[1];
+ var Dz_BF =this.datum_params[2];
+ var Rx_BF =this.datum_params[3];
+ var Ry_BF =this.datum_params[4];
+ var Rz_BF =this.datum_params[5];
+ var M_BF =this.datum_params[6];
+ // if( x[io] == HUGE_VAL )
+ // continue;
+ var x_out = M_BF*( p.x - Rz_BF*p.y + Ry_BF*p.z) + Dx_BF;
+ var y_out = M_BF*( Rz_BF*p.x + p.y - Rx_BF*p.z) + Dy_BF;
+ var z_out = M_BF*(-Ry_BF*p.x + Rx_BF*p.y + p.z) + Dz_BF;
+ p.x = x_out;
+ p.y = y_out;
+ p.z = z_out;
+ }
+ }, // cs_geocentric_to_wgs84
+
+ /****************************************************************/
+ // pj_geocentic_from_wgs84()
+ // coordinate system definition,
+ // point to transform in geocentric coordinates (x,y,z)
+ geocentric_from_wgs84 : function( p ) {
+
+ if( this.datum_type == Proj4js.common.PJD_3PARAM )
+ {
+ //if( x[io] == HUGE_VAL )
+ // continue;
+ p.x -= this.datum_params[0];
+ p.y -= this.datum_params[1];
+ p.z -= this.datum_params[2];
+
+ }
+ else if (this.datum_type == Proj4js.common.PJD_7PARAM)
+ {
+ var Dx_BF =this.datum_params[0];
+ var Dy_BF =this.datum_params[1];
+ var Dz_BF =this.datum_params[2];
+ var Rx_BF =this.datum_params[3];
+ var Ry_BF =this.datum_params[4];
+ var Rz_BF =this.datum_params[5];
+ var M_BF =this.datum_params[6];
+ var x_tmp = (p.x - Dx_BF) / M_BF;
+ var y_tmp = (p.y - Dy_BF) / M_BF;
+ var z_tmp = (p.z - Dz_BF) / M_BF;
+ //if( x[io] == HUGE_VAL )
+ // continue;
+
+ p.x = x_tmp + Rz_BF*y_tmp - Ry_BF*z_tmp;
+ p.y = -Rz_BF*x_tmp + y_tmp + Rx_BF*z_tmp;
+ p.z = Ry_BF*x_tmp - Rx_BF*y_tmp + z_tmp;
+ } //cs_geocentric_from_wgs84()
+ }
+});
+
+/** point object, nothing fancy, just allows values to be
+ passed back and forth by reference rather than by value.
+ Other point classes may be used as long as they have
+ x and y properties, which will get modified in the transform method.
+*/
+Proj4js.Point = Proj4js.Class({
+
+ /**
+ * Constructor: Proj4js.Point
+ *
+ * Parameters:
+ * - x {float} or {Array} either the first coordinates component or
+ * the full coordinates
+ * - y {float} the second component
+ * - z {float} the third component, optional.
+ */
+ initialize : function(x,y,z) {
+ if (typeof x == 'object') {
+ this.x = x[0];
+ this.y = x[1];
+ this.z = x[2] || 0.0;
+ } else if (typeof x == 'string' && typeof y == 'undefined') {
+ var coords = x.split(',');
+ this.x = parseFloat(coords[0]);
+ this.y = parseFloat(coords[1]);
+ this.z = parseFloat(coords[2]) || 0.0;
+ } else {
+ this.x = x;
+ this.y = y;
+ this.z = z || 0.0;
+ }
+ },
+
+ /**
+ * APIMethod: clone
+ * Build a copy of a Proj4js.Point object.
+ *
+ * Return:
+ * {Proj4js}.Point the cloned point.
+ */
+ clone : function() {
+ return new Proj4js.Point(this.x, this.y, this.z);
+ },
+
+ /**
+ * APIMethod: toString
+ * Return a readable string version of the point
+ *
+ * Return:
+ * {String} String representation of Proj4js.Point object.
+ * (ex. <i>"x=5,y=42"</i>)
+ */
+ toString : function() {
+ return ("x=" + this.x + ",y=" + this.y);
+ },
+
+ /**
+ * APIMethod: toShortString
+ * Return a short string version of the point.
+ *
+ * Return:
+ * {String} Shortened String representation of Proj4js.Point object.
+ * (ex. <i>"5, 42"</i>)
+ */
+ toShortString : function() {
+ return (this.x + ", " + this.y);
+ }
+});
+
+Proj4js.PrimeMeridian = {
+ "greenwich": 0.0, //"0dE",
+ "lisbon": -9.131906111111, //"9d07'54.862\"W",
+ "paris": 2.337229166667, //"2d20'14.025\"E",
+ "bogota": -74.080916666667, //"74d04'51.3\"W",
+ "madrid": -3.687938888889, //"3d41'16.58\"W",
+ "rome": 12.452333333333, //"12d27'8.4\"E",
+ "bern": 7.439583333333, //"7d26'22.5\"E",
+ "jakarta": 106.807719444444, //"106d48'27.79\"E",
+ "ferro": -17.666666666667, //"17d40'W",
+ "brussels": 4.367975, //"4d22'4.71\"E",
+ "stockholm": 18.058277777778, //"18d3'29.8\"E",
+ "athens": 23.7163375, //"23d42'58.815\"E",
+ "oslo": 10.722916666667 //"10d43'22.5\"E"
+};
+
+Proj4js.Ellipsoid = {
+ "MERIT": {a:6378137.0, rf:298.257, ellipseName:"MERIT 1983"},
+ "SGS85": {a:6378136.0, rf:298.257, ellipseName:"Soviet Geodetic System 85"},
+ "GRS80": {a:6378137.0, rf:298.257222101, ellipseName:"GRS 1980(IUGG, 1980)"},
+ "IAU76": {a:6378140.0, rf:298.257, ellipseName:"IAU 1976"},
+ "airy": {a:6377563.396, b:6356256.910, ellipseName:"Airy 1830"},
+ "APL4.": {a:6378137, rf:298.25, ellipseName:"Appl. Physics. 1965"},
+ "NWL9D": {a:6378145.0, rf:298.25, ellipseName:"Naval Weapons Lab., 1965"},
+ "mod_airy": {a:6377340.189, b:6356034.446, ellipseName:"Modified Airy"},
+ "andrae": {a:6377104.43, rf:300.0, ellipseName:"Andrae 1876 (Den., Iclnd.)"},
+ "aust_SA": {a:6378160.0, rf:298.25, ellipseName:"Australian Natl & S. Amer. 1969"},
+ "GRS67": {a:6378160.0, rf:298.2471674270, ellipseName:"GRS 67(IUGG 1967)"},
+ "bessel": {a:6377397.155, rf:299.1528128, ellipseName:"Bessel 1841"},
+ "bess_nam": {a:6377483.865, rf:299.1528128, ellipseName:"Bessel 1841 (Namibia)"},
+ "clrk66": {a:6378206.4, b:6356583.8, ellipseName:"Clarke 1866"},
+ "clrk80": {a:6378249.145, rf:293.4663, ellipseName:"Clarke 1880 mod."},
+ "CPM": {a:6375738.7, rf:334.29, ellipseName:"Comm. des Poids et Mesures 1799"},
+ "delmbr": {a:6376428.0, rf:311.5, ellipseName:"Delambre 1810 (Belgium)"},
+ "engelis": {a:6378136.05, rf:298.2566, ellipseName:"Engelis 1985"},
+ "evrst30": {a:6377276.345, rf:300.8017, ellipseName:"Everest 1830"},
+ "evrst48": {a:6377304.063, rf:300.8017, ellipseName:"Everest 1948"},
+ "evrst56": {a:6377301.243, rf:300.8017, ellipseName:"Everest 1956"},
+ "evrst69": {a:6377295.664, rf:300.8017, ellipseName:"Everest 1969"},
+ "evrstSS": {a:6377298.556, rf:300.8017, ellipseName:"Everest (Sabah & Sarawak)"},
+ "fschr60": {a:6378166.0, rf:298.3, ellipseName:"Fischer (Mercury Datum) 1960"},
+ "fschr60m": {a:6378155.0, rf:298.3, ellipseName:"Fischer 1960"},
+ "fschr68": {a:6378150.0, rf:298.3, ellipseName:"Fischer 1968"},
+ "helmert": {a:6378200.0, rf:298.3, ellipseName:"Helmert 1906"},
+ "hough": {a:6378270.0, rf:297.0, ellipseName:"Hough"},
+ "intl": {a:6378388.0, rf:297.0, ellipseName:"International 1909 (Hayford)"},
+ "kaula": {a:6378163.0, rf:298.24, ellipseName:"Kaula 1961"},
+ "lerch": {a:6378139.0, rf:298.257, ellipseName:"Lerch 1979"},
+ "mprts": {a:6397300.0, rf:191.0, ellipseName:"Maupertius 1738"},
+ "new_intl": {a:6378157.5, b:6356772.2, ellipseName:"New International 1967"},
+ "plessis": {a:6376523.0, rf:6355863.0, ellipseName:"Plessis 1817 (France)"},
+ "krass": {a:6378245.0, rf:298.3, ellipseName:"Krassovsky, 1942"},
+ "SEasia": {a:6378155.0, b:6356773.3205, ellipseName:"Southeast Asia"},
+ "walbeck": {a:6376896.0, b:6355834.8467, ellipseName:"Walbeck"},
+ "WGS60": {a:6378165.0, rf:298.3, ellipseName:"WGS 60"},
+ "WGS66": {a:6378145.0, rf:298.25, ellipseName:"WGS 66"},
+ "WGS72": {a:6378135.0, rf:298.26, ellipseName:"WGS 72"},
+ "WGS84": {a:6378137.0, rf:298.257223563, ellipseName:"WGS 84"},
+ "sphere": {a:6370997.0, b:6370997.0, ellipseName:"Normal Sphere (r=6370997)"}
+};
+
+Proj4js.Datum = {
+ "WGS84": {towgs84: "0,0,0", ellipse: "WGS84", datumName: "WGS84"},
+ "GGRS87": {towgs84: "-199.87,74.79,246.62", ellipse: "GRS80", datumName: "Greek_Geodetic_Reference_System_1987"},
+ "NAD83": {towgs84: "0,0,0", ellipse: "GRS80", datumName: "North_American_Datum_1983"},
+ "NAD27": {nadgrids: "@conus,@alaska,@ntv2_0.gsb,@ntv1_can.dat", ellipse: "clrk66", datumName: "North_American_Datum_1927"},
+ "potsdam": {towgs84: "606.0,23.0,413.0", ellipse: "bessel", datumName: "Potsdam Rauenberg 1950 DHDN"},
+ "carthage": {towgs84: "-263.0,6.0,431.0", ellipse: "clark80", datumName: "Carthage 1934 Tunisia"},
+ "hermannskogel": {towgs84: "653.0,-212.0,449.0", ellipse: "bessel", datumName: "Hermannskogel"},
+ "ire65": {towgs84: "482.530,-130.596,564.557,-1.042,-0.214,-0.631,8.15", ellipse: "mod_airy", datumName: "Ireland 1965"},
+ "nzgd49": {towgs84: "59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993", ellipse: "intl", datumName: "New Zealand Geodetic Datum 1949"},
+ "OSGB36": {towgs84: "446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894", ellipse: "airy", datumName: "Airy 1830"}
+};
+
+Proj4js.WGS84 = new Proj4js.Proj('WGS84');
+Proj4js.Datum['OSB36'] = Proj4js.Datum['OSGB36']; //as returned from spatialreference.org
+
+//lookup table to go from the projection name in WKT to the Proj4js projection name
+//build this out as required
+Proj4js.wktProjections = {
+ "Lambert Tangential Conformal Conic Projection": "lcc",
+ "Mercator": "merc",
+ "Popular Visualisation Pseudo Mercator": "merc",
+ "Mercator_1SP": "merc",
+ "Transverse_Mercator": "tmerc",
+ "Transverse Mercator": "tmerc",
+ "Lambert Azimuthal Equal Area": "laea",
+ "Universal Transverse Mercator System": "utm"
+};
+
+
diff --git a/src/images/data-download-minus-button-blue.svg b/src/images/data-download-minus-button-blue.svg
new file mode 100644
index 000000000..1a5f8157a
--- /dev/null
+++ b/src/images/data-download-minus-button-blue.svg
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 48 48" width="4pc" height="4pc"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>2013-06-14 18:46Z</dc:date><!-- Produced by OmniGraffle Professional 5.4.3 --></metadata><defs><filter id="Shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="3.488"/><feOffset in="blur" result="offset" dx="0" dy="4"/><feFlood flood-color="black" result="flood"/><feComposite in="flood" in2="offset" operator="in"/></filter><linearGradient x1="0" x2="1" id="Gradient" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0080ff"/><stop offset="1" stop-color="blue"/></linearGradient><linearGradient id="Obj_Gradient" xl:href="#Gradient" gradientTransform="translate(24 2) rotate(90) scale(44)"/><filter id="Shadow_2" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="3.488"/><feOffset in="blur" result="offset" dx="0" dy="4"/><feFlood flood-color="black" flood-opacity=".75" result="flood"/><feComposite in="flood" in2="offset" operator="in"/></filter></defs><g stroke="none" stroke-opacity="1" stroke-dasharray="none" fill="none" fill-opacity="1"><title>Canvas 1</title><g><title>Base</title><g><use xl:href="#id28_Graphic" filter="url(#Shadow)"/></g><g id="id28_Graphic"><circle cx="24" cy="24" r="22.000034" fill="url(#Obj_Gradient)"/><circle cx="24" cy="24" r="22.000034" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/></g></g><g><title>Plus Fill</title><g><use xl:href="#id30_Graphic" filter="url(#Shadow_2)"/></g><g id="id30_Graphic"><rect x="13" y="22" width="22" height="4" fill="white"/></g></g></g></svg>
diff --git a/src/images/data-download-plus-button-cyan.svg b/src/images/data-download-plus-button-cyan.svg
new file mode 100644
index 000000000..15a400c28
--- /dev/null
+++ b/src/images/data-download-plus-button-cyan.svg
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xl="http://www.w3.org/1999/xlink" version="1.1" viewBox="0 0 48 48" width="4pc" height="4pc"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>2013-06-17 13:25Z</dc:date><!-- Produced by OmniGraffle Professional 5.4.3 --></metadata><defs><filter id="Shadow" filterUnits="userSpaceOnUse"><feGaussianBlur in="SourceAlpha" result="blur" stdDeviation="3.488"/><feOffset in="blur" result="offset" dx="0" dy="4"/><feFlood flood-color="black" flood-opacity=".75" result="flood"/><feComposite in="flood" in2="offset" operator="in"/></filter><linearGradient x1="0" x2="1" id="Gradient" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="aqua"/><stop offset="1" stop-color="#6cf"/></linearGradient><linearGradient id="Obj_Gradient" xl:href="#Gradient" gradientTransform="translate(24 2) rotate(90) scale(44)"/></defs><g stroke="none" stroke-opacity="1" stroke-dasharray="none" fill="none" fill-opacity="1"><title>Canvas 1</title><g><title>Base</title><g><use xl:href="#id28_Graphic" filter="url(#Shadow)"/></g><g id="id28_Graphic"><circle cx="24" cy="24" r="22.000034" fill="url(#Obj_Gradient)"/><circle cx="24" cy="24" r="22.000034" stroke="black" stroke-linecap="round" stroke-linejoin="round" stroke-width="1"/></g></g><g><title>Plus Fill</title><g><use xl:href="#id1_Graphic" filter="url(#Shadow)"/><use xl:href="#id30_Graphic" filter="url(#Shadow)"/></g><g id="id1_Graphic"><rect x="22" y="13" width="4" height="22" fill="black"/></g><g id="id30_Graphic"><rect x="13" y="22" width="22" height="4" fill="black"/></g></g></g></svg>
diff --git a/src/index.html b/src/index.html
index 19460c36d..7ae7faa9e 100644
--- a/src/index.html
+++ b/src/index.html
@@ -102,6 +102,7 @@
<!-- link.dev --> <script type="text/javascript" src="ext/openlayers/OpenLayers.debug.js?mobile"></script>
<!-- link.dev --> <script type="text/javascript" src="ext/jcrop/jcrop.js"></script>
<!-- link.dev --> <script type="text/javascript" src="ext/jquery.dd/jquery.dd.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="ext/jscache/cache.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Logging.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Date.js"></script>
@@ -148,8 +149,10 @@
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/Model.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHOClient.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ECHOGeometry.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ProductSelector.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/ControlDialog.js"></script>
+ <!-- link.dev --> <script type="text/javascript" src="js/Worldview/DataDownload/MapView.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Map.js"></script>
<!-- link.dev --> <script type="text/javascript" src="js/Worldview/Widget/Palette.js"></script>
diff --git a/src/js/Worldview/DataDownload/ControlDialog.js b/src/js/Worldview/DataDownload/ControlDialog.js
index 3755b3a7c..b4fa47181 100644
--- a/src/js/Worldview/DataDownload/ControlDialog.js
+++ b/src/js/Worldview/DataDownload/ControlDialog.js
@@ -41,11 +41,7 @@ Worldview.DataDownload.ControlDialog = function(model) {
].join("\n"));
dialog.hideEvent.subscribe(function() {
- setTimeout(function() {
- dialog.destroy();
- dialog == null;
- self.events.trigger("close");
- }, 5);
+ self.events.trigger("hide");
});
dialog.render(document.body);
@@ -53,13 +49,14 @@ Worldview.DataDownload.ControlDialog = function(model) {
Worldview.DataDownload.ProductSelector(model,
"#dataDownload_controlDialog .productSelector");
- dialog.show();
};
- self.close = function() {
- if ( dialog ) {
- dialog.hide();
- }
+ self.show = function() {
+ dialog.show();
+ };
+
+ self.hide = function() {
+ dialog.hide();
};
init();
diff --git a/src/js/Worldview/DataDownload/ECHOClient.js b/src/js/Worldview/DataDownload/ECHOClient.js
index 02a833dcd..a77f93f95 100644
--- a/src/js/Worldview/DataDownload/ECHOClient.js
+++ b/src/js/Worldview/DataDownload/ECHOClient.js
@@ -15,42 +15,76 @@
Worldview.namespace("DataDownload");
Worldview.DataDownload.ECHOClient = function(spec) {
-
+
+ // Hold a maximum of ten results
+ var CACHE_SIZE = 10;
+ // Hold results for a maximum of ten minutes
+ var CACHE_TIME = 10 * 60;
+
var log = Logging.getLogger("ECHOClient");
var endpoint = "data/echo.cgi";
var errorHandler;
-
+ var cache;
+ var active = false;
+
var self = {};
+ self.events = Worldview.Events();
+
+ self.EVENT_QUERY = "query";
+ self.EVENT_RESULTS = "results";
+ self.EVENT_CANCEL = "cancel";
+ self.EVENT_ERROR = "error";
+
var init = function() {
spec = spec || {};
- errorHandler = spec.errorHandler || defaultErrorHandler;
+ cache = new Cache(CACHE_SIZE);
};
- self.query = function(parameters, callback) {
- request = $.ajax({
- url: endpoint,
- data: parameters,
- dataType: "json",
- success: onSuccess,
- error: onError
- });
+ self.query = function(parameters) {
+ if ( active ) {
+ throw new Error("Another query is already executing");
+ }
+
+ var key = $.param(parameters, true);
+ var results = cache.getItem(key);
+ if ( results ) {
+ onSuccess(results, parameters);
+ } else {
+ active = true;
+ request = $.ajax({
+ url: endpoint,
+ data: parameters,
+ traditional: true,
+ dataType: "json",
+ success: function(results) {
+ onSuccess(results, parameters);
+ },
+ error: function(jqXHR, status, error) {
+ onError(jqXHR, status, error, parameters);
+ }
+ });
+ self.events.trigger(self.EVENT_QUERY);
+ }
};
- var onSuccess = function(results) {
- console.log(results);
+ var onSuccess = function(results, parameters) {
+ active = false;
+
+ var key = $.param(parameters, true);
+ cache.setItem(key, results);
+
+ self.events.trigger(self.EVENT_RESULTS, results.feed.entry);
};
- var onError = function(jqXHR, status, error) {
+ var onError = function(jqXHR, status, error, parameters) {
+ active = false;
// It is not an error if the query was aborted
if ( status === "abort" ) {
+ self.events.trigger(self.EVENT_CANCEL);
return;
}
- errorHandler(status, error);
- };
-
- var defaultErrorHandler = function(status, error) {
- log.error("[" + status + "] Unable to query ECHO: " + error);
+ self.events.trigger(self.EVENT_ERROR, status, error, parameters);
};
init();
diff --git a/src/js/Worldview/DataDownload/ECHOGeometry.js b/src/js/Worldview/DataDownload/ECHOGeometry.js
new file mode 100644
index 000000000..321e5ded5
--- /dev/null
+++ b/src/js/Worldview/DataDownload/ECHOGeometry.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+/**
+ * @module Worldview.DataDownload
+ */
+Worldview.namespace("DataDownload");
+
+Worldview.DataDownload.ECHOGeometry = function(result) {
+
+ var self = {};
+ self.polygons = [];
+
+ var init = function() {
+ if ( result.polygons ) {
+ initFromPolygons(result.polygons);
+ } else {
+ throw new Error("Unable to find spatial field");
+ }
+ };
+
+ self.toOpenLayers = function() {
+ olPolygons = [];
+ $.each(self.polygons, function(index, polygon) {
+ var olRings = [];
+ $.each(polygon, function(index, ring) {
+ var olPoints = [];
+ $.each(ring, function(index, point) {
+ var p = new OpenLayers.Geometry.Point(point.x, point.y);
+ olPoints.push(p);
+ });
+ olRings.push(new OpenLayers.Geometry.LinearRing(olPoints));
+ });
+ olPolygons.push(new OpenLayers.Geometry.Polygon(olRings));
+ });
+ return new OpenLayers.Geometry.MultiPolygon(olPolygons);
+ };
+
+ var initFromPolygons = function(echoPolygons) {
+ $.each(echoPolygons, function(index, echoPolygon) {
+ var rings = [];
+ $.each(echoPolygon, function(index, echoRing) {
+ var ring = [];
+ var parts = echoRing.split(" ");
+ for ( var i = 0; i < parts.length; i+= 2 ) {
+ var y = parseFloat(parts[i]);
+ var x = parseFloat(parts[i + 1]);
+ ring.push({x: x, y: y});
+ }
+ rings.push(ring);
+ });
+ self.polygons.push(rings);
+ });
+ };
+
+ init();
+ return self;
+}
diff --git a/src/js/Worldview/DataDownload/MapView.js b/src/js/Worldview/DataDownload/MapView.js
new file mode 100644
index 000000000..069890367
--- /dev/null
+++ b/src/js/Worldview/DataDownload/MapView.js
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+Worldview.namespace("DataDownload");
+
+Worldview.DataDownload.MapView = function(model, maps) {
+
+ var self = {};
+ var results = null;
+
+ var GRANULE_LAYER_NAME = "Granule_Layer";
+
+ var IMAGE_BUTTON_SELECT = "images/data-download-plus-button-cyan.svg";
+ var IMAGE_BUTTON_UNSELECT = "images/data-download-minus-button-blue.svg";
+
+ var init = function() {
+ model.events
+ .on("queryResults", onQueryResults)
+ .on("projectionUpdate", onProjectionUpdate)
+ .on("deactivate", onDeactivate)
+ .on("activate", updateGranules);
+ };
+
+ var onQueryResults = function(r) {
+ results = r;
+ updateGranules();
+ };
+
+ var updateGranules = function() {
+ if ( !results ) {
+ return;
+ }
+ var layer = maps.map.getLayersByName(GRANULE_LAYER_NAME)[0];
+ if ( !layer ) {
+ size = {w: 20, h: 20};
+ layer = new OpenLayers.Layer.Vector(GRANULE_LAYER_NAME, {
+ styleMap: new OpenLayers.StyleMap({
+ externalGraphic: IMAGE_BUTTON_SELECT,
+ graphicWidth: size.w,
+ graphicHeight: size.h
+ })
+ });
+ maps.map.addLayer(layer);
+ }
+ layer.removeAllFeatures();
+
+ features = [];
+ $.each(results, function(index, result) {
+ if ( !result.geometry ) {
+ result.geometry = {};
+ }
+ if ( !result.geometry[model.epsg] ) {
+ g = Worldview.DataDownload.ECHOGeometry(result).toOpenLayers();
+ result.geometry[model.epsg] = g;
+ }
+ var geometry = result.geometry[model.epsg];
+ var feature = new OpenLayers.Feature.Vector(geometry.getCentroid());
+ features.push(feature);
+ });
+ layer.addFeatures(features);
+ }
+
+ var onProjectionUpdate = function() {
+ console.log("projection", model.projection, model.epsg);
+ };
+
+ var onDeactivate = function() {
+ $.each(maps.projections, function(index, map) {
+ var layer = map.getLayersByName(GRANULE_LAYER_NAME)[0];
+ if ( layer ) {
+ map.removeLayer(layer);
+ }
+ });
+ };
+
+ init();
+ return self;
+}
diff --git a/src/js/Worldview/DataDownload/Model.js b/src/js/Worldview/DataDownload/Model.js
index eb43909cd..2a419488e 100644
--- a/src/js/Worldview/DataDownload/Model.js
+++ b/src/js/Worldview/DataDownload/Model.js
@@ -22,7 +22,8 @@ Worldview.namespace("DataDownload");
Worldview.DataDownload.Model = function(config) {
var state = {};
-
+ var client = Worldview.DataDownload.ECHOClient();
+
var self = {};
/**
@@ -36,13 +37,18 @@ Worldview.DataDownload.Model = function(config) {
/**
* Fired when the data download mode is deEVENT_ACTIVATEd.
*
- * @event DEEVENT_ACTIVATE
+ * @event EVENT_ACTIVATE
* @final
*/
self.EVENT_DEACTIVATE = "deactivate";
self.EVENT_LAYER_SELECT = "layerSelect";
self.EVENT_LAYER_UPDATE = "layerUpdate";
+ self.EVENT_QUERY = "query";
+ self.EVENT_QUERY_RESULTS = "queryResults";
+ self.EVENT_QUERY_CANCEL = "queryCancel";
+ self.EVENT_QUERY_ERROR = "queryError";
+ self.EVENT_PROJECTION_UPDATE = "projectionUpdate";
/**
* Indicates if data download mode is active.
@@ -64,12 +70,34 @@ Worldview.DataDownload.Model = function(config) {
self.selectedLayer = null;
self.layers = [];
-
+
+ self.granules = [];
+ self.projection = null;
+ self.epsg = null;
+
+ var init = function() {
+ client.events
+ .on("query", function() {
+ self.events.trigger(self.EVENT_QUERY);
+ })
+ .on("results", function(results, parameters) {
+ self.events.trigger(self.EVENT_QUERY_RESULTS, results,
+ parameters);
+ })
+ .on("cancel", function() {
+ self.events.trigger(self.EVENT_QUERY_CANCEL);
+ })
+ .on("error", function(status, error, parameters) {
+ self.events.trigger(self.EVENT_QUERY_ERROR, status, error,
+ parameters);
+ });
+ };
+
/**
- * EVENT_ACTIVATEs data download mode. If the mode is already active, this method
+ * Activates data download mode. If the mode is already active, this method
* does nothing.
*
- * @method EVENT_ACTIVATE
+ * @method activate
*/
self.activate = function() {
if ( !self.active ) {
@@ -82,10 +110,10 @@ Worldview.DataDownload.Model = function(config) {
};
/**
- * DeEVENT_ACTIVATEs data download mode. If the mode is not already active, this
+ * Deactivates data download mode. If the mode is not already active, this
* method does nothing.
*
- * @method deEVENT_ACTIVATE
+ * @method deactivate
*/
self.deactivate = function() {
if ( self.active ) {
@@ -117,15 +145,35 @@ Worldview.DataDownload.Model = function(config) {
}
self.selectedLayer = layerName;
self.events.trigger(self.EVENT_LAYER_SELECT, self.selectedLayer);
+ query();
};
self.update = function(newState) {
if ( newState.productsString !== state.productsString ) {
updateLayers(newState);
}
+ if ( newState.projection !== state.projection ||
+ newState.epsg !== state.epsg ) {
+ updateProjection(newState);
+ }
state = newState;
};
+ var query = function() {
+ var layerConfig = config.products[self.selectedLayer];
+ if ( !layerConfig.echo ) {
+ self.events.trigger(self.EVENT_QUERY_RESULTS, []);
+ return;
+ }
+
+ var parameters = {
+ shortName: layerConfig.echo.shortName,
+ dataCenterId: layerConfig.echo.dataCenterId,
+ day: state.time.toISOStringDate()
+ }
+ client.query(parameters);
+ };
+
var updateLayers = function(newState) {
self.layers = [];
$.each(newState.products, function(index, layer) {
@@ -146,6 +194,13 @@ Worldview.DataDownload.Model = function(config) {
self.events.trigger(self.EVENT_LAYER_UPDATE);
};
+ var updateProjection = function(newState) {
+ self.projection = newState.projection;
+ self.epsg = newState.epsg;
+ self.events.trigger(self.EVENT_PROJECTION_UPDATE, self.projection,
+ self.epsg);
+ };
+
var findAvailableLayer = function() {
// Find the top most layer that has a product entry in ECHO
for ( var i = state.products.length - 1; i >= 0; i-- ) {
@@ -161,5 +216,6 @@ Worldview.DataDownload.Model = function(config) {
}
}
+ init();
return self;
}
\ No newline at end of file
diff --git a/src/js/Worldview/Events.js b/src/js/Worldview/Events.js
index 8cc0398b8..481d7acd5 100644
--- a/src/js/Worldview/Events.js
+++ b/src/js/Worldview/Events.js
@@ -42,10 +42,14 @@ Worldview.Events = function() {
* Registers a listener for an event.
*
* @method on
+ *
* @param {string} event Type of event to register for.
+ *
* @param {function} callback Function called when the event of the given
* type is fired. Arguments to the fire method are passed to the callback
* function.
+ *
+ * @return {Events} this object useful for chaining.
*/
self.on = function(event, callback) {
if ( !event ) {
@@ -56,17 +60,22 @@ Worldview.Events = function() {
listeners = [];
types[event] = listeners;
}
- listeners.push(callback);
+ listeners.push(callback);
+ return self;
};
/**
* Unregisteres a listenet for an evcent.
*
* @method off
+ *
* @param {string} event Type of event to unregister for.
+ *
* @param {Object} callback Function that was previously registered for
* this type of event. If this function has not been registered, this
* method does nothing.
+ *
+ * @return {Events} this object useful for chaining.
*/
self.off = function(event, callback) {
var listeners = types[event];
@@ -75,17 +84,22 @@ Worldview.Events = function() {
if ( index >= 0 ) {
listeners.splice(index, 1);
}
- }
+ }
+ return self;
};
/**
* Notifies all listeners of an event.
*
* @method trigger
+ *
* @param {string} event Type of event to fire. If no listeners are
* registered for this event, this method does nothing.
+ *
* @param {Object} [arguments]* Additional arguments to pass back to the
* function of each listener.
+ *
+ * @return {Events} this object useful for chaining.
*/
self.trigger = function(event) {
var listeners = types[event];
@@ -96,6 +110,7 @@ Worldview.Events = function() {
$.each(types[event], function(index, listener) {
listener.apply(self, eventArguments);
});
+ return self;
};
return self;
diff --git a/src/js/Worldview/Map/ProductMap.js b/src/js/Worldview/Map/ProductMap.js
index 8a7b4cd89..7924d8493 100644
--- a/src/js/Worldview/Map/ProductMap.js
+++ b/src/js/Worldview/Map/ProductMap.js
@@ -31,10 +31,7 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
var log = Logging.getLogger("Worldview.Map");
var self = {};
-
- // Map objects, one for each supported projection
- var activeMaps = {};
-
+
// Configurations for each available product
var productConfigs = {};
@@ -58,6 +55,9 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
* The <Wordlview.JSON.MapConfig> used in configuration (read only).
*/
self.mapConfig = mapConfig;
+
+ // Map objects, one for each supported projection
+ self.projections = {};
/**
* Property: map
@@ -120,7 +120,7 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
}
newMap.products = {};
- activeMaps[projection] = newMap;
+ self.projections[projection] = newMap;
activeProducts[projection] = [];
newMap.events.register("addlayer", self, onAddLayer);
@@ -155,7 +155,7 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
* An exception if the specified projection is not supported.
*/
self.setProjection = function(projection) {
- if ( !(projection in activeMaps) ) {
+ if ( !(projection in self.projections) ) {
throw new Error("Unsupported projection: " + projection);
}
log.debug("Switch projection: " + projection);
@@ -171,7 +171,7 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
}
// Update convenience variables
- self.map = activeMaps[projection];
+ self.map = self.projections[projection];
self.products = activeProducts[projection];
self.projection = projection;
@@ -292,7 +292,7 @@ Worldview.Map.ProductMap = function(containerId, mapConfig, component) {
* and palette names as values.
*/
self.setPalettes = function(activePalettes) {
- $.each(activeMaps, function(projection, map) {
+ $.each(self.projections, function(projection, map) {
$.each(map.products, function(productName, product) {
var paletteName = activePalettes[productName];
if ( paletteName ) {
diff --git a/src/js/Worldview/State.js b/src/js/Worldview/State.js
new file mode 100644
index 000000000..b2fb5313e
--- /dev/null
+++ b/src/js/Worldview/State.js
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+
+/**
+ * @module Worldview
+ */
+
+/**
+ * State of the application.
+ *
+ * This is an object representation of all key/value pairs in the query string.
+ * To object an instance of this class:
+ *
+ * var state = REGISTRY.getState();
+ *
+ * This object is a copy of the state when the getState method was invoked.
+ * Always call getState to get the latest information. Instances of this
+ * class are not updated as state changes.
+ *
+ * @class State
+ */
+
+/**
+ * Array of active base layers.
+ * @attribute baseLayers {Array(string)}
+ */
+
+/**
+ * All components that have been registered, keyed by the component identifier
+ * (name used in the query string)
+ * @attribute components {Object}
+ */
+
+/**
+ * EPSG projection code for the current display. for arctic, this could be
+ * 3995 or 3413 depending on the day.
+ *
+ * @attribute epsg {string}
+ */
+
+/**
+ * Products that are in the active layers list but are hiddent from view.
+ * @attribute hiddenProducts {Array(string)}
+ */
+
+/**
+ * TODO
+ * @attribute opacity
+ */
+
+/**
+ * TODO
+ * @attribute opacityString
+ */
+
+/**
+ * TODO
+ * @attribute palettes
+ */
+
+/**
+ * TODO
+ * @attribute palettesString
+ */
+
+/**
+ * All products in the active layers list (base layers and overlays)
+ *
+ * @attribute products {Array(String)}
+ */
+
+/**
+ * Value of the query string segment for the product list. In the form of:
+ *
+ * baselayers,LAYER,LAYER~overlays,LAYER,LAYER
+ *
+ * where LAYER is a layer name. Hidden layers are prefixed with an exclamation
+ * point (!).
+ *
+ * @attribute productsString
+ */
+
+/**
+ * Current map projection. Either "geographic", "arctic", or "antarctic"
+ *
+ * @attribute projection {string}
+ */
+
+/**
+ * Current day being viewed. Hours, minutes, and seconds will always be
+ * UTC zero.
+ *
+ * @attribute time {Date}
+ */
\ No newline at end of file
diff --git a/src/js/Worldview/Widget/DataDownload.js b/src/js/Worldview/Widget/DataDownload.js
index 62f1486c7..0b1f6b727 100644
--- a/src/js/Worldview/Widget/DataDownload.js
+++ b/src/js/Worldview/Widget/DataDownload.js
@@ -18,15 +18,14 @@ Worldview.namespace("Widget");
* @class DataDownload
* @constructor
*
- * @param model {Worldview.DataDownload.Model} model for which this widget
- * will be a view for.
+ * @param model {Worldview.DataDownload.Model} FIXME
*
* @param config Worldview config
*
* @param spec.selector {string} jQuery selector for where the mode activation
* button should be rendered.
*/
-Worldview.Widget.DataDownload = function(model, config, spec) {
+Worldview.Widget.DataDownload = function(spec) {
var log = Logging.getLogger("Widget.DataDownload");
Logging.debug("Widget.DataDownload");
@@ -36,19 +35,27 @@ Worldview.Widget.DataDownload = function(model, config, spec) {
var preloader = Worldview.Preloader([
"images/activity.gif",
- "images/cameraon.png"
+ "images/cameraon.png",
+ "images/red-x.svg"
]);
+ var model = spec.model;
var controlDialog = null;
+ var mapView = null;
var self = {};
self.containerId = "dataDownload";
var init = function() {
- model.events.on("activate", onActivate);
- model.events.on("deactivate", onDeactivate);
- model.events.on("layerSelect", onLayerSelect);
+ model.events
+ .on("activate", onActivate)
+ .on("deactivate", onDeactivate)
+ .on("layerSelect", onLayerSelect)
+ .on("query", onQuery)
+ .on("queryResults", onQueryResults)
+ .on("queryCancel", onQueryCancel)
+ .on("queryError", onQueryError);
- $(spec.selector).on("click", function() { toggleMode(); } );
+ $(spec.selector).on("click", toggleMode);
$(spec.selector).html(HTML_WIDGET_INACTIVE);
REGISTRY.register(self.containerId, self);
@@ -67,29 +74,72 @@ Worldview.Widget.DataDownload = function(model, config, spec) {
var toggleMode = function() {
preloader.execute(function() {
- model.toggleMode();
+ try {
+ model.toggleMode();
+ } catch ( error ) {
+ Worldview.error("Internal error", error);
+ }
});
}
var onActivate = function() {
log.debug("activate");
$(spec.selector).html(HTML_WIDGET_ACTIVE);
- controlDialog = Worldview.DataDownload.ControlDialog(model);
- controlDialog.events.on("close", function() {
- model.deactivate();
- });
+
+ if ( !controlDialog ) {
+ controlDialog = Worldview.DataDownload.ControlDialog(model);
+ controlDialog.events.on("hide", function() {
+ try {
+ model.deactivate();
+ } catch ( error ) {
+ Worldview.error("Internal error", error);
+ }
+ });
+ }
+ controlDialog.show();
+
+ if ( !mapView ) {
+ mapView = Worldview.DataDownload.MapView(model, spec.maps);
+ }
+
};
var onDeactivate = function() {
log.debug("deactivate");
$(spec.selector).html(HTML_WIDGET_INACTIVE);
- controlDialog && controlDialog.close();
+ controlDialog.hide();
+ Worldview.Indicator.hide();
};
var onLayerSelect = function(layerName) {
log.debug("selectLayer", layerName);
};
+ var onQuery = function() {
+ log.debug("query");
+ Worldview.Indicator.searching();
+ };
+
+ var onQueryResults = function(results) {
+ log.debug("queryResults", results);
+ Worldview.Indicator.hide();
+ if ( results.length === 0 ) {
+ Worldview.Indicator.noData();
+ }
+ };
+
+ var onQueryCancel = function() {
+ log.debug("queryCancel");
+ Worldview.Indicator.hide();
+ };
+
+ var onQueryError = function(status, error, parameters) {
+ log.debug("queryError", status, error, parameters);
+ Worldview.Indicator.hide();
+ Worldview.notify("Unable to query at this time. Please try again later",
+ error);
+ };
+
init();
return self;
diff --git a/src/js/Worldview/Widget/EPSG.js b/src/js/Worldview/Widget/EPSG.js
index 2946e0177..fb4c862fc 100644
--- a/src/js/Worldview/Widget/EPSG.js
+++ b/src/js/Worldview/Widget/EPSG.js
@@ -74,6 +74,12 @@ Worldview.Widget.EPSG = function(config) {
self.loadFromQuery = self.updateComponent;
+ self.parse = function(queryString, object) {
+ var epsg = Worldview.extractFromQuery("epsg", queryString);
+ object.epsg = epsg;
+ return object;
+ };
+
init();
return self;
}
diff --git a/src/js/main.js b/src/js/main.js
index 900067710..f0494d0c6 100644
--- a/src/js/main.js
+++ b/src/js/main.js
@@ -131,10 +131,12 @@ $(function() {// Initialize "static" vars
wvEPSG:epsg});
var dataDownloadModel = Worldview.DataDownload.Model(config);
- var dataDownloadWidget =
- Worldview.Widget.DataDownload(dataDownloadModel, config, {
- selector: ".dataDownload-modeButton"
- });
+ var dataDownloadWidget = Worldview.Widget.DataDownload({
+ selector: ".dataDownload-modeButton",
+ model: dataDownloadModel,
+ config: config,
+ maps: m.productMap
+ });
// Get rid of address bar on iphone/ipod
var fixSize = function() {