-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmarkers.html
180 lines (147 loc) · 4.33 KB
/
markers.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<title>flag markers example</title>
<link rel="stylesheet" type="text/css" href="examples.css"/>
<script type="text/javascript" src="https://api.giscloud.com/1/api.js"></script>
<script type="text/javascript" src="examples.js"></script>
<script type="text/javascript">
var viewer, features, markers, $ = giscloud.exposeJQuery(), available = {};
giscloud.ready(function() {
// start loading features
var featuresLoading = giscloud.features.byLayer(layerId)
.done(function() {
// save loaded features
features = arguments[0];
});
// create a viewer
viewer = new giscloud.Viewer("mapViewer", mapId, { slider: true });
// after both the viewer and the features have been loaded,
// create the flag markers and the index
$.when(viewer.loading, featuresLoading)
.done(createMarkers)
.done(createIndex);
});
function createIndex () {
var i, k, e, l,
ind = $("#index"),
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
showMarkers = function (letter) {
for (name in markers) {
if (name.charAt(0) === letter) {
markers[name].visible(true);
} else {
markers[name].visible(false);
}
}
};
for (i = 0, k = abc.length; i < k; i++) {
l = abc.charAt(i);
$("<a/>", {
id: l,
href: "#",
click: function(evt) {
showMarkers(this.id);
evt.preventDefault();
},
css: {
"font-weight": available[l] ? "bold" : "normal"
}
}).html(l).appendTo(ind);
}
}
function createMarkers() {
var m, i, k, f, title, cont;
// create an object to hold the markers
markers = {};
// create a marker for each feature and add it to the viewer
for (var i = 0, k = features.length; i < k; i++) {
f = features[i];
// title
if (f.data.name3 !== "N.A.") {
title = f.data.name3;
} else if (f.data.name2 !== "N.A.") {
title = f.data.name2;
} else {
title = f.data.name1;
}
available[title.charAt(0)] = true;
// content
cont = "Population density: " + f.data.pop_density;
// create a hidden marker with a random color
m = new giscloud.FlagMarker(f.bounds.center(), title, cont, giscloud.Color.randomHue(70, 50));
m.visible(false);
// add a marker to the viewer
viewer.addMarker(m);
// add to markers
if (markers[title]) {
markers[title + "_" + Math.round(Math.random() * 100)] = m;
} else {
markers[title] = m;
}
}
}
</script>
<style type="text/css">
#index {
background-color: #fafafa;
border: solid thin #ccc;
height: 1.4em;
color: #999
}
#index a {
margin-left: 0.8em;
margin-bottom: 0.2em;
}
#index a:hover {
color: red;
}
</style>
<body>
<h1>Flag Markers</h1>
<p>
This example demonstrates use of viewer flag markers. <br/>
Features data is loaded and a flag marker is created for each feature.
</p>
<p>
Markers are positioned at the center of the feature's bounds. The title and the content of the markers are
filled with some feature data. All the markers are initially hidden, and you can display them by clicking
through the index above the map viewer.
</p>
<p>
Methods of <a target="_blank" href="http://api.jquery.com/deferred.promise/" title="deferred.promise()" >
jQuery promise</a> objects are used for synchronisation.
</p>
<div id ="index"></div>
<div id="mapViewer"></div>
<p>
The code:
</p>
<pre>
// create a hidden marker with a random color
m = new giscloud.FlagMarker(
f.bounds.center(),
title,
content,
giscloud.Color.randomHue(70, 50)
).visible(false);
// show the marker
m.visible(true);
//
// synchronization
//
// start loading features and save data to a variable when done
var featuresLoading = giscloud.features.byLayer(4)
.done(function() {
// save loaded features
features = arguments[0];
});
// create a viewer
viewer = new giscloud.Viewer("mapViewer", 1);
// after both the viewer and the features have been loaded,
// create the markers and the index
$.when(viewer.loading, featuresLoading)
.done(createMarkers)
.done(createIndex);
</pre>
</body>
</html>