forked from stamen/modestmaps-js
/
index.html
216 lines (187 loc) · 7.04 KB
/
index.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html>
<head>
<title>ModestMaps JS: Extent Selector</title>
<script type="text/javascript" src="../../modestmaps.js"></script>
<script type="text/javascript" src="modestmaps.extent-selector.js"></script>
<script type="text/javascript">
var MM = com.modestmaps,
map, selector, extent;
function initMap() {
// the map
var layer = new MM.TemplatedLayer("http://acetate.geoiq.com/tiles/acetate-base/{Z}/{X}/{Y}.png");
map = new MM.Map("map", layer);
// the initial extent
var extent = new MM.Extent(37.837, -122.522, 37.691, -122.350);
map.setExtent(extent);
// the selector is a map "layer"
selector = new MM.ExtentSelector(document.getElementById("extent"));
map.addLayer(selector);
// update the northwest and south east labels when the extent
// changes
var nwLabel = document.getElementById("nw-label"),
seLabel = document.getElementById("se-label"),
extentField = document.getElementById("extent-string");
selector.addCallback("extentset", function(o, ext) {
// these setters all coerce to strings, which implicitly
// calls toString() on the Location and Extent instances
nwLabel.innerText = ext.northWest();
seLabel.innerText = ext.southEast();
// and update the extent string field for good measure
extentField.value = ext;
});
selector.setExtent(extent);
// when the from-map button is pressed, set the selector's
// extent to the map's
MM.addEvent(document.getElementById("from-map"), "click", function(e) {
selector.setExtent(map.getExtent());
return MM.cancelEvent(e);
});
// when the update-extent button is pressed, parse the input
// field's value as an extent and attempt to set it on the
// selector
MM.addEvent(document.getElementById("from-text"), "click", function(e) {
// keep the old extent around in case there's an issue,
// so we can reset the field
var old = selector.getExtent();
try {
var ext = MM.Extent.fromString(extentField.value);
selector.setExtent(ext);
} catch (e) {
alert("Whoops: " + e);
selector.setExtent(old);
}
return MM.cancelEvent(e);
});
// when the to-map button is pressed, set the map's extent to the
// selector's
MM.addEvent(document.getElementById("to-map"), "click", function(e) {
map.setExtent(selector.extent, false);
return MM.cancelEvent(e);
});
// the checkbox determines if you can drag the extent selector
// by its center
var checkbox = document.getElementById("move-center");
MM.addEvent(checkbox, "change", function(e) {
selector.allowMoveCenter = checkbox.checked;
});
}
</script>
<style type="text/css">
body {
margin: 0;
padding: 20px;
}
h1,
p { margin: 0 0 .5em 0; }
#map {
height: 500px;
}
.map-extent {
background-color: rgba(255,0,0,.1);
background-color: transparent;
z-index: 1000;
}
/*
* FIXME: IE apparently needs the transparent PNG background to
* receive mouse events.
*/
.map-extent .handles {
cursor: move;
border: 1px solid red;
background-image: url(1px.png);
}
.map-extent .handle {
background-image: url(1px.png);
}
.map-extent .handle:hover {
background-color: red;
}
.map-extent .handle-north,
.map-extent .handle-south { cursor: ns-resize; }
.map-extent .handle-east,
.map-extent .handle-west { cursor: ew-resize; }
.map-extent .handle-northwest,
.map-extent .handle-southeast { cursor: nwse-resize; }
.map-extent .handle-northeast,
.map-extent .handle-southwest { cursor: nesw-resize; }
.map-extent .handle-north {
height: 5px;
width: 100%;
top: -1px;
}
.map-extent .handle-south {
height: 5px;
width: 100%;
bottom: -1px;
}
.map-extent .handle-east {
width: 5px;
height: 100%; right: -1px;
}
.map-extent .handle-west {
width: 5px;
height: 100%;
left: -1px;
}
.map-extent .handle-northwest,
.map-extent .handle-northeast,
.map-extent .handle-southeast,
.map-extent .handle-southwest {
width: 9px;
height: 9px;
border-radius: 5px;
}
.map-extent .handle-northeast {
top: -4px;
right: -4px;
}
.map-extent .handle-southeast {
bottom: -4px;
right: -4px;
}
.map-extent .handle-southwest {
bottom: -4px;
left: -4px;
}
.map-extent .handle-northwest {
top: -4px;
left: -4px;
}
/* labels (optional) */
.map-extent .label {
position: absolute;
display: block;
text-align: center;
width: 10em;
}
#nw-label {
top: -1em;
margin-top: -10px;
left: -5em;
}
#se-label {
top: 100%;
margin-top: 10px;
right: -5em;
}
</style>
</head>
<body onload="initMap()">
<h1>ModestMaps JS: Extent Selector</h1>
<p>Extent (N,W,S,E):
<input id="extent-string" type="text" size="40">
<button id="from-text">update from input</button>
<button id="from-map">grab from map</button>
<button id="to-map">snap map to selector</button>
<br>
<label><input id="move-center" type="checkbox" checked> allow moving the extent by its center</label>
</p>
<div id="map">
<div id="extent" class="map-extent">
<span id="nw-label" class="label"></span>
<span id="se-label" class="label"></span>
</div>
</div>
</body>
</html>