├── MagDec
├── css
│ └── MagDec.css
├── templates
│ └── MagDec.html
└── WMM.html
├── LICENSE
├── README.md
└── MagDec.js
/MagDec/css/MagDec.css:
--------------------------------------------------------------------------------
1 |
2 | .magDecWidget {
3 | white-space: nowrap;
4 | min-width: 310px;
5 | }
6 |
7 | .magDecWidget .valuesDiv {
8 | font-weight: normal;
9 | }
10 |
11 | .magDecWidget .attribute {
12 | display: inline-block;
13 | width: 130px;
14 | height: 15px;
15 | font-weight: bold;
16 | }
17 |
18 | .magDecWidget .value {
19 | font-weight: normal;
20 | }
21 |
22 | .magDecWidget .warning {
23 | color: red;
24 | font-weight: bold;
25 | }
26 | .magDecWidget .smallText {
27 | color: black;
28 | font-weight: normal;
29 | font-size: 7px;
30 | }
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MagDec/templates/MagDec.html:
--------------------------------------------------------------------------------
1 |
13 | Datum: WGS84
14 | Additional information on magnetic declination: click here
15 | Additional information on the World Magnetic Model 2015: click here
16 |
17 |
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MagneticDeclination-Widget
2 |
3 | ## Features
4 | An ArcGIS for JavaScript API widget for calculating magnetic declination.
5 |
6 | Model: World Magnetic Model 2015 (WMM-2015) Current until December 2019.
7 | Datum: WGS84
8 |
9 | Press spacebar to pause/resume updating.
10 |
11 | [View it live](http://joerogan.ca/maps/joegis/)
12 |
13 | ## Helpful Links
14 | * [Magnetic Declination](http://geomag.nrcan.gc.ca/mag_fld/magdec-en.php)
15 | * [World Magnetic Model](https://www.ngdc.noaa.gov/geomag/WMM/)
16 |
17 | ## Quickstart
18 | ```javascript
19 | on(mainMap, "load", function() {
20 | var magDec = new MagDec({
21 | map: mainMap
22 | }, "MagDecWindow");
23 | magDec.startup();
24 | });
25 | ```
26 |
27 | ## Requirements
28 | * Notepad or HTML editor
29 | * A little background with JavaScript
30 | * Experience with the [ArcGIS API for JavaScript](https://developers.arcgis.com/javascript/) would help.
31 |
32 | ## Setup
33 | Set your dojo config to load the module.
34 |
35 | ```javascript
36 | var package_path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));
37 | var dojoConfig = {
38 | // The locationPath logic below may look confusing but all its doing is
39 | // enabling us to load the api from a CDN and load local modules from the correct location.
40 | packages: [{
41 | name: "application",
42 | location: package_path + '/js'
43 | }]
44 | };
45 | ```
46 |
47 | ## Require module
48 | Include the module for the MagDec widget.
49 |
50 | ```javascript
51 | require(["application/MagDec", ... ], function(MagDec, ... ){ ... });
52 | ```
53 |
54 | ## Constructor
55 | MagDec(options, srcNode);
56 |
57 | ### Options (Object)
58 | |property|required|type|value|description|
59 | |---|---|---|---|---|
60 | |map|x|Map|null|ArcGIS JS Map.|
61 | |theme||string|magDecWidget|CSS Class for uniquely styling the widget.|
62 |
63 | ## Methods
64 | ### startup
65 | startup(): Start the widget. Map object must be loaded first.
66 |
67 | ## Issues
68 | Find a bug or want to request a new feature? Please let us know by submitting an issue.
69 |
70 | ## Contributing
71 | Anyone and everyone is welcome to contribute.
72 |
73 | ## Credits
74 | Modified from code create by Christopher Weiss (cmweiss@gmail.com) Copyright 2012
75 | Adapted from the geomagc software and World Magnetic Model of the NOAA
76 | Satellite and Information Service, National Geophysical Data Center
77 | [Source](http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml)
78 |
79 | ## Licensing
80 | The MIT License (MIT)
81 |
82 | Copyright (c) 2016 Joseph Rogan
83 |
84 | Permission is hereby granted, free of charge, to any person obtaining a copy
85 | of this software and associated documentation files (the "Software"), to deal
86 | in the Software without restriction, including without limitation the rights
87 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
88 | copies of the Software, and to permit persons to whom the Software is
89 | furnished to do so, subject to the following conditions:
90 |
91 | The above copyright notice and this permission notice shall be included in all
92 | copies or substantial portions of the Software.
93 |
94 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
95 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
96 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
97 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
98 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
99 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
100 | SOFTWARE.
101 |
102 |
--------------------------------------------------------------------------------
/MagDec/WMM.html:
--------------------------------------------------------------------------------
1 | 2015.0 WMM-2015 12/15/2014
2 | 1 0 -29438.5 0.0 10.7 0.0
3 | 1 1 -1501.1 4796.2 17.9 -26.8
4 | 2 0 -2445.3 0.0 -8.6 0.0
5 | 2 1 3012.5 -2845.6 -3.3 -27.1
6 | 2 2 1676.6 -642.0 2.4 -13.3
7 | 3 0 1351.1 0.0 3.1 0.0
8 | 3 1 -2352.3 -115.3 -6.2 8.4
9 | 3 2 1225.6 245.0 -0.4 -0.4
10 | 3 3 581.9 -538.3 -10.4 2.3
11 | 4 0 907.2 0.0 -0.4 0.0
12 | 4 1 813.7 283.4 0.8 -0.6
13 | 4 2 120.3 -188.6 -9.2 5.3
14 | 4 3 -335.0 180.9 4.0 3.0
15 | 4 4 70.3 -329.5 -4.2 -5.3
16 | 5 0 -232.6 0.0 -0.2 0.0
17 | 5 1 360.1 47.4 0.1 0.4
18 | 5 2 192.4 196.9 -1.4 1.6
19 | 5 3 -141.0 -119.4 0.0 -1.1
20 | 5 4 -157.4 16.1 1.3 3.3
21 | 5 5 4.3 100.1 3.8 0.1
22 | 6 0 69.5 0.0 -0.5 0.0
23 | 6 1 67.4 -20.7 -0.2 0.0
24 | 6 2 72.8 33.2 -0.6 -2.2
25 | 6 3 -129.8 58.8 2.4 -0.7
26 | 6 4 -29.0 -66.5 -1.1 0.1
27 | 6 5 13.2 7.3 0.3 1.0
28 | 6 6 -70.9 62.5 1.5 1.3
29 | 7 0 81.6 0.0 0.2 0.0
30 | 7 1 -76.1 -54.1 -0.2 0.7
31 | 7 2 -6.8 -19.4 -0.4 0.5
32 | 7 3 51.9 5.6 1.3 -0.2
33 | 7 4 15.0 24.4 0.2 -0.1
34 | 7 5 9.3 3.3 -0.4 -0.7
35 | 7 6 -2.8 -27.5 -0.9 0.1
36 | 7 7 6.7 -2.3 0.3 0.1
37 | 8 0 24.0 0.0 0.0 0.0
38 | 8 1 8.6 10.2 0.1 -0.3
39 | 8 2 -16.9 -18.1 -0.5 0.3
40 | 8 3 -3.2 13.2 0.5 0.3
41 | 8 4 -20.6 -14.6 -0.2 0.6
42 | 8 5 13.3 16.2 0.4 -0.1
43 | 8 6 11.7 5.7 0.2 -0.2
44 | 8 7 -16.0 -9.1 -0.4 0.3
45 | 8 8 -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| 12 6 0.1 0.7 0.1 0.0
86 | 12 7 0.5 -0.1 0.0 0.0
87 | 12 8 -0.4 0.3 0.0 0.0
88 | 12 9 -0.4 0.2 0.0 0.0
89 | 12 10 0.2 -0.9 0.0 0.0
90 | 12 11 -0.9 -0.2 0.0 0.0
91 | 12 12 0.0 0.7 0.0 0.0
92 | 999999999999999999999999999999999999999999999999
93 | 999999999999999999999999999999999999999999999999
94 |
--------------------------------------------------------------------------------
/MagDec.js:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////////////
2 | ///////////////////////////////--------MagDec.js-------//////////////////////////////
3 | /////////////////////////////////////////////////////////////////////////////////////
4 | //
5 | // Version: 1.2
6 | // Author: Joseph Rogan (joseph.rogan@forces.gc.ca canadajebus@gmail.com)
7 | //
8 | // Credits: Modified from code create by Christopher Weiss (cmweiss@gmail.com) Copyright 2012
9 | // Adapted from the geomagc software and World Magnetic Model of the NOAA
10 | // Satellite and Information Service, National Geophysical Data Center
11 | // http://www.ngdc.noaa.gov/geomag/WMM/DoDWMM.shtml
12 | //
13 | // This reusable widget allows the user to calculate magnetic declination at the point
14 | // of the mouse hover.
15 | //
16 | // on(mainMap, "load", function() {
17 | // //MagDec widget Example
18 | // var magDec = new MagDec({
19 | // map: mainMap
20 | // }, "MagDecWindow");
21 | // magDec.startup();
22 | // });
23 | //
24 | // Changes:
25 | // Version 1.2
26 | // -Minor tweak to size and warning text format.
27 | // Version 1.1
28 | // -Added .magDecWidget { white-space: nowrap; min-width: 300px; } to css file
29 | /////////////////////////////////////////////////////////////////////////////////////
30 | /////////////////////////////////////////////////////////////////////////////////////
31 |
32 | define([
33 | "dijit/_WidgetBase",
34 | "dijit/_TemplatedMixin",
35 | "dijit/_WidgetsInTemplateMixin",
36 |
37 | "dojo/_base/declare",
38 | "dojo/_base/lang",
39 | "dojo/on",
40 | "require",
41 |
42 | "esri/geometry/webMercatorUtils",
43 |
44 | "dojo/text!./MagDec/WMM.html",
45 |
46 | "dojo/text!./MagDec/templates/MagDec.html",
47 |
48 | "dojo/domReady!"
49 |
50 | ], function(_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin,
51 | declare, lang, on, require,
52 | webMercatorUtils,
53 | cof,
54 | dijitTemplate)
55 | {
56 |
57 | return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
58 |
59 | // Set the template .html file
60 | templateString: dijitTemplate,
61 |
62 | // Path to the templates .css file
63 | css_path: require.toUrl("./MagDec/css/MagDec.css"),
64 |
65 | // Vars
66 | cof: cof,
67 | wmm: null,
68 |
69 | maxord: null,
70 | tc: null,
71 | tc: null,
72 | sp: null,
73 | cp: null,
74 | pp: null,
75 | p: null,
76 | dp: null,
77 | a: null,
78 | b: null,
79 | re: null,
80 | a2: null,
81 | b2: null,
82 | c2: null,
83 | a4: null,
84 | b4: null,
85 | c4: null,
86 | c: null,
87 | cd: null,
88 | k: null,
89 | fn: null,
90 | fm: null,
91 |
92 |
93 |
94 |
95 | // The defaults
96 | defaults: {
97 | map: null,
98 | theme: "magDecWidget",
99 | autoUpdate: true
100 | },
101 |
102 |
103 | // Called when the widget is declared as new object
104 | constructor: function(options) {
105 | // Mix in the given options with the defaults
106 | var properties = lang.mixin({}, this.defaults, options);
107 | this.set(properties);
108 |
109 | this.css = {
110 | valuesDiv: "valuesDiv",
111 | attribute: "attribute",
112 | value: "value",
113 | smallText: "smallText",
114 | warning: "warning"
115 | };
116 |
117 |
118 | },
119 |
120 |
121 | // Called after the widget is created
122 | postCreate: function() {
123 | this.inherited(arguments);
124 |
125 | },
126 |
127 |
128 | // Called when the widget.startup() is used to view the widget
129 | startup: function() {
130 | this.inherited(arguments);
131 |
132 | // Calculate the model and initial math
133 | this.wmm = this._cof2Obj(this.cof)
134 | this._geoMagFactory(this.wmm);
135 |
136 |
137 | // Wire events for the mouse move
138 | var _this = this;
139 | on(this.map, "mouse-move", function (evt, $_this) {
140 | if (_this.autoUpdate) _this._mapMoveCalc(evt, _this);
141 | });
142 | on(this.map, "mouse-drag", function (evt, $_this) {
143 | if (_this.autoUpdate) _this._mapMoveCalc(evt, _this);
144 | });
145 |
146 | // Wire event for pausing updates with the keyboard
147 | on(this.map, "key-down", function (evt, $_this) {
148 | if (evt.keyCode == 32)
149 | {
150 | if (_this.autoUpdate) _this.autoUpdate = false;
151 | else _this.autoUpdate = true;
152 | }
153 | });
154 |
155 |
156 | },
157 |
158 |
159 |
160 | // Calculates geo mag on a map move event
161 | _mapMoveCalc: function(evt, _this) {
162 |
163 | // Get the map coordinates in lat/lon
164 | var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
165 |
166 | // Get the inputs
167 | var latitude = mp.y.toFixed(5);
168 | var longitude = mp.x.toFixed(5);
169 | var altitude = 0;
170 | var time = new Date();
171 |
172 | // Calculate geo mag
173 | var myGeoMag = _this.geoMag(latitude, longitude, altitude, time)
174 |
175 | // Calculate DMS values of the input lat lon
176 | var lat = this.DD2DMS(mp.y);
177 | var lon = this.DD2DMS(mp.x);
178 | var dec = this.DD2DMS(myGeoMag.dec);
179 |
180 | // Update the html
181 | _this.MagDecLatitude.innerHTML = latitude + " (" + lat.d + "°" + lat.m + "'" + lat.s + "\" " + lat.hemiLat + ")";
182 | _this.MagDecLongitude.innerHTML = longitude + " (" + lon.d + "°" + lon.m + "'" + lon.s + "\" " + lon.hemiLon + ")";
183 |
184 | var months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
185 | _this.MagDecDate.innerHTML = time.getDate() + " " + months[time.getMonth()] + " " + time.getFullYear();
186 |
187 | _this.MagDecDeclination.innerHTML = Math.round(100*myGeoMag.dec)/100 + " (" + dec.d + "°" + dec.m + "' " + dec.hemiLon + ")";
188 | _this.MagDecHorizontalIntensity.innerHTML = Math.round(myGeoMag.bh) + " nT";
189 |
190 | // Warning message if required
191 | if (myGeoMag.bh < 5000 & myGeoMag.bh > 1000)
192 | {
193 | this.Warning.innerHTML = "Warning: The horizontal field strength at this location is only " + Math.round(myGeoMag.bh) + " nT (Compass readings have large uncertainties in areas where H is smaller than 5000 nT)"
194 | }
195 | else if (myGeoMag.bh < 1000)
196 | {
197 | this.Warning.innerHTML = "Warning: The horizontal field strength at this location is only " + Math.round(myGeoMag.bh) + " nT (Compass readings have VERY LARGE uncertainties in areas where H is smaller than 1000 nT)"
198 | }
199 | else
200 | {
201 | this.Warning.innerHTML = " Press spacebar to pause/resume updating.