-
Notifications
You must be signed in to change notification settings - Fork 20
/
complex.html
129 lines (129 loc) · 4.5 KB
/
complex.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
---
layout: default
---
<h3>Complex example with multiple options and method calls..</h3>
<div id = 'map'></div>
<p id = 'barrio'></p>
<p id = 'pueblo'></p>
<script type = 'text/javascript'>
// change the id for your node id.
var node = document.getElementById("map");
// get color scale
var color = d3.scale.category20b();
//whenever the map is ready, paint the pueblos with random colors.
var ready = function ready(atlas){
atlas.maps['pueblos'].style("fill", function(){
var index = Math.round(Math.random()*20);
return color(index);
});
atlas.maps['pueblos'].style("fill-opacity", 0.5);
var index = 0;
// three times, select a random pueblo, zoom the map into it.
var first_animation = function first_animation(){
index++;
if(index <= 3){
//"atlas" is the main object for atlaspr, it has the api.
//'_zoom_to_random_pueblo' is a non documented method that zooms to a pueblo.
var pueblo = atlas._zoom_to_random_pueblo(function(info, tile){
d3.select(tile).style("fill", "red");
//add the text to the bottom right corner.
d3.select("#pueblo").text(pueblo.properties.NAME);
});
} else{
//after three zooms, stop the animation, zoom the map back and start the second anim.
clearInterval(interval);
atlas.zoom_to_original();
d3.select("#pueblo").text("");
index = 0;
interval = setInterval(second_animation,100);
}
}
//the second animation selects a random barrio and paints it, until there are not more barrios.
var second_animation = function second_animation(){
var random_tile = atlas.maps['barrios'][0][index++];
var tile = d3.select(random_tile).style("fill", color(10));
d3.select("#barrio").text(tile.attr("data-name"));
if(index >= atlas.maps['barrios'][0].length){
clearInterval(interval);
}
}
var interval = setInterval(first_animation, 5000);
}
// display the pueblo name, whenever the map is hovered.
var hover = function hover(info, path){
d3.select("#pueblo").text(info.properties.NAME);
};
// magic.
new AtlasPR({
zoom: true,
node: node,
size: "large" ,
tiles: ["isla",'barrios','pueblos'],
on_ready: ready,
events: {
on_mouseover: hover
}
});
</script>
<div id = 'code'>
{% highlight js linenos%}
// change the id for your node id.
var node = document.getElementById("map");
// get color scale
var color = d3.scale.category20b();
//whenever the map is ready, paint the pueblos with random colors.
var ready = function ready(atlas){
atlas.maps['pueblos'].style("fill", function(){
var index = Math.round(Math.random()*20);
return color(index);
});
atlas.maps['pueblos'].style("fill-opacity", 0.5);
var index = 0;
// three times, select a random pueblo, zoom the map into it.
var first_animation = function first_animation(){
index++;
if(index <= 3){
//"atlas" is the main object for atlaspr, it has the api.
//'_zoom_to_random_pueblo' is a non documented method that zooms to a pueblo.
var pueblo = atlas._zoom_to_random_pueblo(function(info, tile){
d3.select(tile).style("fill", "red");
//add the text to the bottom right corner.
d3.select("#pueblo").text(pueblo.properties.NAME);
});
} else{
//after three zooms, stop the animation, zoom the map back and start the second anim.
clearInterval(interval);
atlas.zoom_to_original();
d3.select("#pueblo").text("");
index = 0;
interval = setInterval(second_animation,100);
}
}
//the second animation selects a random barrio and paints it, until there are not more barrios.
var second_animation = function second_animation(){
var random_tile = atlas.maps['barrios'][0][index++];
var tile = d3.select(random_tile).style("fill", color(10));
d3.select("#barrio").text(tile.attr("data-name"));
if(index >= atlas.maps['barrios'][0].length){
clearInterval(interval);
}
}
var interval = setInterval(first_animation, 5000);
}
// display the pueblo name, whenever the map is hovered.
var hover = function hover(info, path){
d3.select("#pueblo").text(info.properties.NAME);
};
// magic.
new AtlasPR({
zoom: true,
node: node,
size: "large" ,
tiles: ["isla",'barrios','pueblos'],
on_ready: ready,
events: {
on_mouseover: hover
}
});
{% endhighlight %}
</div>