summaryrefslogtreecommitdiff
path: root/libs/js/jquery-geo-1.0a4/docs/examples/hurricane.html
blob: 9270a0d3132e65f36b7928b9d6d60af219c9caaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">

    <title>hurricane</title>
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">

    <meta name="description" content="Displaying storm activity in the Atlantic">
    <meta name="author" content="Ryan Westphal">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <style type="text/css">
      #map
      {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: 0;
      }
      #popup
      {
        background: #fff;
        border: solid 1px #444;
        border-radius: 8px;
        display: none;
        padding: 4px;
        position: absolute;
        opacity: .6;
        overflow: hidden;
        width: auto;
      }
    </style>
  </head>
  <body>
    <div id="hurricane">
      <div id="map">
        <div id="popup">
        </div>
      </div>
      <div class="info">
        <a href="../" class="docLink">&lt; docs</a>
          <h1>Hurricane tracking</h1>
          <p>Displaying a snapshot of storm data extracted from <a href="http://stormpulse.com">stormpulse.com</a></p>
      </div>
    </div>
    <script id="tmplHurricane" type="text/x-jquery-tmpl">
      <h2>{{=category}}</h2>
      <table>
        <tr><th>date</th><td>{{=date}}</td></tr>
        <tr><th>accuracy</th><td>{{=accuracy}}/40</td></tr>
        <tr><th>eye diameter</th><td>{{=eyeDiameter}}</td></tr>
        <tr><th>direction</th><td>{{#if direction}}{{=direction}}&deg{{/if}}</td></tr>
        <tr><th>pressure</th><td>{{=pressure}}</td></tr>
        <tr><th>wind radii</th><td>{{=windRadii}}</td></tr>
        <tr><th>wind speed</th><td>{{=windSpeed}}</td></tr>
        <tr><th>gusts</th><td>{{=gusts}}</td></tr>
      </table>
    </script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="js/iecors.js"></script>
    <script src="http://code.jquerygeo.com/jquery.geo-1.0a4.min.js"></script>
    <script>
      $(function () {
        $.template( "hurricane", $( "#tmplHurricane" ) );

        var map = $("#map").geomap({
            center: [-76.6, 30.4],
            zoom: 5,
            mode: "find",
            cursors: { find: "default" },
            move: function (e, geo) {
              $("#popup").hide().html("");
              var tracks = map.geomap("find", geo, 4);

              $.each(tracks, function() {
                if (this.type == "Feature") {
                  $( "#popup" ).append( $.render( this.properties, "hurricane" ) );
                  var popupLocation = map.geomap( "toPixel", geo.coordinates );
                  $("#popup").css({
                    left: popupLocation[ 0 ],
                    top: popupLocation[ 1 ]
                  }).css("display", "inline-block");
                }
              });
            }
          });

        $.ajax({
          url: "http://data.jquerygeo.com/hurricane.json",
          dataType: "json",
          success: function (result) {
            var shapeStyle = {
              color: "gray",
              strokeWidth: "4px"
            };

            $.each(result.stormData.storms.tracks[0].track, function(i) {
              var trackPoint = {
                type: "Feature",
                geometry: {
                  type: "Point",
                  coordinates: [
                    parseFloat(this[16]),
                    parseFloat(this[7])
                  ]
                },
                properties: {
                  eyeDiameter: this[0],
                  windRadii: this[1],
                  category: this[4],
                  accuracy: this[10] || 0,
                  direction: this[11],
                  pressure: this[14],
                  date: this[15],
                  gusts: this[17],
                  windSpeed: this[18]
                }
              };

              if (trackPoint.properties.date != null) {
                var dateStr = trackPoint.properties.date.toString(),
                    year = dateStr.substr(0, 4),
                    month = dateStr.substr(4, 2),
                    day = dateStr.substr(6);
                trackPoint.properties.date = year + "-" + month + "-" + day;
              }

              switch (trackPoint.properties.category) {
                case "Tropical Storm":
                  shapeStyle.color = "#eee";
                  break;

                case "Hurricane - Category 1":
                  shapeStyle.color = "#ff8";
                  break;

                case "Hurricane - Category 2":
                  shapeStyle.color = "orange";
                  break;

                case "Major Hurricane - Category 3":
                  shapeStyle.color = "#f88";
                  break;

                default:
                  shapeStyle.color = "gray";
                  break;
              }

              if (trackPoint.properties.accuracy != null) {
                var pos = trackPoint.geometry.coordinates,
                    a = .2 + (40 - trackPoint.properties.accuracy)/40;

                shapeStyle.strokeOpacity = trackPoint.properties.accuracy/40;

                map.geomap("append", {
                  type: "Polygon",
                  coordinates: [[
                    [pos[0] - a, pos[1] - a],
                    [pos[0] - a, pos[1] + a],
                    [pos[0] + a, pos[1] + a],
                    [pos[0] + a, pos[1] - a],
                    [pos[0] - a, pos[1] - a]
                  ]]
                }, $.extend({}, shapeStyle));
              }

              map.geomap("append", trackPoint, { color: "#444" });
            });
          },
          error: function (xhr) {
            alert("Sorry, we were unable to read the storm data.");
          }
        });
      });  
    </script>
  </body>
</html>