-
Notifications
You must be signed in to change notification settings - Fork 1
/
animated_choropleth.html
165 lines (160 loc) · 4.88 KB
/
animated_choropleth.html
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
<html>
<head>
<title>Choroplethr Playr</title>
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/css/bootstrap-theme.min.css">
<style>
.animate-enter {
-webkit-transition: 1s linear all; /* Chrome */
transition: 1s linear all;
opacity: 0;
}
.animate-enter.animate-enter-active {
opacity: 1;
}
.mapImage {
width: 100%;
}
.ranger {
width: 500px;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body ng-app="AnimatedMaps" ng-cloak ng-controller="ClientApp">
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Choroplethr Playr</a>
</div>
<form class="navbar-form navbar-right" role="search">
<div class="form-group">
<button type="button" class="btn btn-default" ng-click="play()"> <span class="glyphicon glyphicon-play glyphicon-inverse"></span>
</button>
<button type="button" class="btn btn-default" ng-click="stop()"><span class="glyphicon glyphicon-stop"></span>
</button>
<button type="button" class="btn btn-default" ng-click="minusValue()">
<span class="glyphicon glyphicon-minus"></span> </button>
<input type="range" class="form-control ranger" ng-model="dateValue" min="{{minValue}}" max="{{maxValue}}">
<button type="button" class="btn btn-default" ng-click="plusValue()"> <span class="glyphicon glyphicon-plus"></span>
</button>
</div>
</form>
</div>
</nav>
</div>
<div class="container">
<div class="page-header">
</div>
</div>
<div class="container">
<img class="mapImage img-thumbnail" ng-animate=" "animate" " ng-src="{{mapURL()}}">
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular.min.js"></script>
<script src="http://code.angularjs.org/1.2.10/angular-animate.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.10/angular-resource.min.js"></script>
<script>
angular.module("AnimatedMaps", ["ngAnimate"])
.controller("ClientApp", ["$scope", "$window", "$interpolate", function($scope, $window, $interpolate) {
"use strict";
/**
* The normalized date
* @type {number}
*/
$scope.dateValue = 1;
/**
* A reference for storing the setInterval
* @type {null}
*/
$scope.intervalRef = null;
/**
* The starting map dateValue
* @type {number}
*/
$scope.maxValue = 28;
/**
* The ending map dateValue
* @type {number}
*/
$scope.minValue = 1;
/**
* url template for preloading images
* @type {string}
*/
$scope.urlTemplate = $interpolate("choropleth_{{dateValue}}.png");
/**
* The map image URL being displayed
* @type {string}
*/
$scope.mapURL = function() {
return $scope.urlTemplate({dateValue: $scope.dateValue});
}
/**
* Increment the date
*/
$scope.plusValue = function() {
if ($scope.dateValue < $scope.maxValue)
$scope.dateValue++;
}
/**
* Decrement the date
*/
$scope.minusValue = function() {
if ($scope.dateValue > $scope.minValue)
$scope.dateValue--;
}
/**
* Start animation traversing through all images in order
*/
$scope.play = function() {
if (Number($scope.dateValue) >= Number($scope.maxValue)) {
$scope.dateValue = $scope.minValue;
}
$scope.intervalRef = $window.setInterval($scope.nextMap, 1000);
};
/**
* Stop the animation
*/
$scope.stop = function() {
$window.clearInterval($scope.intervalRef);
};
/**
* Load Next Map Image
*/
$scope.nextMap = function() {
$scope.$apply(function() {
if ($scope.dateValue < $scope.maxValue) {
$scope.dateValue = Number($scope.dateValue) + 1;
} else {
$window.clearInterval($scope.intervalRef);
}
});
};
/**
* Preload Map Images
*/
$scope.preloadImages = function() {
for(var i = $scope.minValue; i <= $scope.maxValue; i++) {
var img = new Image();
img.src = $scope.urlTemplate({dateValue: i});
}
};
// Preload All Map Images
$scope.preloadImages();
}]).run([function() {
"use strict";
}]);
</script>
</body>
</html>