/
tipsy.html
157 lines (139 loc) · 3.57 KB
/
tipsy.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
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="../../lib/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../../lib/tipsy/jquery.tipsy.js"></script>
<script type="text/javascript" src="../../polymaps.js"></script>
<style type="text/css">
@import url("../../lib/tipsy/tipsy.css");
@import url("../example.css");
.layer circle {
fill: lightcoral;
fill-opacity: .5;
stroke: brown;
stroke-width: 1.5px;
}
.tipsy-inner {
padding: 3px;
line-height: 0;
}
.tipsy-inner img {
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
background: white;
}
</style>
</head>
<body>
<script type="text/javascript">
var po = org.polymaps;
var radius = 10, tips = {};
var map = po.map()
.container(document.body.appendChild(po.svg("svg")))
.center({lon: -122.20877392578124, lat: 37.65175620758778})
.zoom(10)
.add(po.interact())
.on("move", move)
.on("resize", move);
map.add(po.image()
.url(po.url("http://{S}tile.cloudmade.com"
+ "/1a1b06b230af4efdbb989ea99e9841af" // http://cloudmade.com/register
+ "/998/256/{Z}/{X}/{Y}.png")
.hosts(["a.", "b.", "c.", ""])));
map.add(po.geoJson()
.on("load", load)
.on("show", show)
.features([
{
"id": "stanford",
"properties": {
"html": "<img src='stanford.png' width=200 height=200>"
},
"geometry": {
"coordinates": [-122.16894848632812, 37.42961865341856],
"type": "Point"
}
},
{
"id": "berkeley",
"properties": {
"html": "<img src='berkeley.png' width=200 height=200>"
},
"geometry": {
"coordinates": [-122.26358225200948, 37.872092652605886],
"type": "Point"
}
}
]));
map.add(po.compass()
.pan("none"));
function load(e) {
for (var i = 0; i < e.features.length; i++) {
var f = e.features[i];
f.element.setAttribute("r", radius);
f.element.addEventListener("mousedown", toggle(f.data), false);
f.element.addEventListener("dblclick", cancel, false);
}
}
function show(e) {
for (var i = 0; i < e.features.length; i++) {
var f = e.features[i], tip = tips[f.data.id];
tip.feature = f.data;
tip.location = {
lat: f.data.geometry.coordinates[1],
lon: f.data.geometry.coordinates[0]
};
update(tip);
}
}
function move() {
for (var id in tips) {
update(tips[id]);
}
}
function cancel(e) {
e.stopPropagation();
e.preventDefault();
}
function update(tip) {
if (!tip.visible) return; // ignore
var p = map.locationPoint(tip.location);
tip.anchor.style.left = p.x - radius + "px";
tip.anchor.style.top = p.y - radius + "px";
$(tip.anchor).tipsy("show");
}
function toggle(f) {
var tip = tips[f.id];
if (!tip) {
tip = tips[f.id] = {
anchor: document.body.appendChild(document.createElement("a")),
visible: false,
toggle: function(e) {
tip.visible = !tip.visible;
update(tip);
$(tip.anchor).tipsy(tip.visible ? "show" : "hide");
cancel(e);
}
};
tip.anchor.style.position = "absolute";
tip.anchor.style.visibility = "hidden";
tip.anchor.style.width = radius * 2 + "px";
tip.anchor.style.height = radius * 2 + "px";
$(tip.anchor).tipsy({
html: true,
fallback: f.properties.html,
gravity: $.fn.tipsy.autoNS,
trigger: "manual"
});
}
return tip.toggle;
}
</script>
<span id="copy">
© 2010
<a href="http://www.cloudmade.com/">CloudMade</a>,
<a href="http://www.openstreetmap.org/">OpenStreetMap</a> contributors,
<a href="http://creativecommons.org/licenses/by-sa/2.0/">CCBYSA</a>.
</span>
</body>
</html>