-
Notifications
You must be signed in to change notification settings - Fork 152
/
index.html
157 lines (126 loc) · 4.52 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
<html>
<head>
<title>Modest Maps JS - Zoom Box</title>
<script type="text/javascript" src="../../modestmaps.js"></script>
<script type="text/javascript">
function ZoomBox(map) {
this.map = map;
var theBox = this;
this.getMousePoint = function(e) {
// start with just the mouse (x, y)
var point = new com.modestmaps.Point(e.clientX, e.clientY);
// correct for scrolled document
point.x += document.body.scrollLeft + document.documentElement.scrollLeft;
point.y += document.body.scrollTop + document.documentElement.scrollTop;
// correct for nested offsets in DOM
for(var node = this.map.parent; node; node = node.offsetParent) {
point.x -= node.offsetLeft;
point.y -= node.offsetTop;
}
return point;
};
var boxDiv = document.createElement('div');
boxDiv.id = map.parent.id+'-zoombox';
boxDiv.width = map.dimensions.x;
boxDiv.height = map.dimensions.y;
boxDiv.style.margin = '0';
boxDiv.style.padding = '0';
boxDiv.style.position = 'absolute';
boxDiv.style.top = '0px';
boxDiv.style.left = '0px';
boxDiv.style.width = map.dimensions.x+'px';
boxDiv.style.height = map.dimensions.y+'px';
map.parent.appendChild(boxDiv);
var box = document.createElement('div');
box.id = map.parent.id+'-zoombox-box';
box.width = map.dimensions.x;
box.height = map.dimensions.y;
box.style.margin = '0';
box.style.padding = '0';
box.style.borderWidth = '2px';
box.style.borderColor = '#ff0000';
box.style.borderStyle = 'solid';
box.style.background = 'rgba(255,255,255,0.25)';
//box.style.outlineWidth = '1000px';
//box.style.outlineColor = 'rgba(0,0,0,0.2)';
//box.style.outlineStyle = 'solid';
box.style.position = 'absolute';
box.style.display = 'none';
box.style.top = '0px';
box.style.left = '0px';
box.style.width = '0px';
box.style.height = '0px';
boxDiv.appendChild(box);
// TODO: respond to resize
var mouseDownPoint = null;
this.mouseDown = function(e) {
if (e.shiftKey) {
mouseDownPoint = theBox.getMousePoint(e);
box.style.left = mouseDownPoint.x + 'px';
box.style.top = mouseDownPoint.y + 'px';
com.modestmaps.addEvent(map.parent, 'mousemove', theBox.mouseMove);
com.modestmaps.addEvent(map.parent, 'mouseup', theBox.mouseUp);
map.parent.style.cursor = 'crosshair';
return com.modestmaps.cancelEvent(e);
}
};
this.mouseMove = function(e) {
var point = theBox.getMousePoint(e);
box.style.display = 'block';
if (point.x < mouseDownPoint.x) {
box.style.left = point.x + 'px';
}
else {
box.style.left = mouseDownPoint.x + 'px';
}
box.style.width = Math.abs(point.x - mouseDownPoint.x) + 'px';
if (point.y < mouseDownPoint.y) {
box.style.top = point.y + 'px';
}
else {
box.style.top = mouseDownPoint.y + 'px';
}
box.style.height = Math.abs(point.y - mouseDownPoint.y) + 'px';
return com.modestmaps.cancelEvent(e);
};
this.mouseUp = function(e) {
var point = theBox.getMousePoint(e);
var l1 = map.pointLocation(point);
var l2 = map.pointLocation(mouseDownPoint);
map.setExtent([l1,l2]);
box.style.display = 'none';
com.modestmaps.removeEvent(map.parent, 'mousemove', theBox.mouseMove);
com.modestmaps.removeEvent(map.parent, 'mouseup', theBox.mouseUp);
map.parent.style.cursor = 'auto';
return com.modestmaps.cancelEvent(e);
};
com.modestmaps.addEvent(boxDiv, 'mousedown', this.mouseDown);
}
var map, zoombox;
function initMap() {
var container = document.getElementById('container');
var template = 'http://{S}tile.openstreetmap.org/{Z}/{X}/{Y}.png';
var subdomains = [ 'a.', 'b.', 'c.', ''];
var provider = new com.modestmaps.TemplatedMapProvider(template, subdomains);
map = new com.modestmaps.Map('map', provider);
map.setCenterZoom(new com.modestmaps.Location(37.811530, -122.2666097), 14);
zoombox = new com.modestmaps.ZoomBox(map);
}
</script>
<style type="text/css">
body {
margin: 0;
padding: 0;
border: 0
}
#map {
width: 100%;
height: 100%;
}
</style>
</head>
<body onload="initMap()">
<div id="map">
</div>
</body>
</html>