-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
130 lines (113 loc) · 3.41 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
<!DOCTYPE HTML>
<html>
<head>
<title>OpenLayers Demo</title>
<style type="text/css">
html, body, #basicMap {
width: 100%;
height: 95%;
margin: 0;
}
</style>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" language="javascript" src="/static/lib/OpenLayers.js"></script>
<script>
var running = 0;
var map;
var extent;
var glyphLayer;
var nodes = [];
$(document).ready(function() {
map = new OpenLayers.Map("basicMap");
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326"); // Transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var position = new OpenLayers.LonLat(-97.74306,30.26715).transform( fromProjection, toProjection);
var zoom = 15;
map.addLayer(mapnik);
glyphLayer = new OpenLayers.Layer.Vector("GlyphLayer");
map.addLayer(glyphLayer);
map.setCenter(position, zoom);
mapnik.setOpacity(0.5);
reset();
});
function reset()
{
n_nodes = $('#howMany').val();
scale = $('#howFar').val();
glyphLayer.removeAllFeatures();
extent = map.getExtent();
nodes = []
for (var i = 0; i < n_nodes; i ++)
{
px = extent.left + (Math.random() * (extent.right - extent.left));
py = extent.bottom + (Math.random() * (extent.top - extent.bottom));
dx = -scale + 2*Math.random()*scale;
dy = -scale + 2*Math.random()*scale;
var g = new OpenLayers.Geometry.Point(extent.left + (Math.random() * (extent.right - extent.left)), extent.bottom + (Math.random() * (extent.top - extent.bottom)));
var f = new OpenLayers.Feature.Vector(g, null, {fillColor: "#ff0000", fillOpacity: 1.0, strokeColor: "#00ff00", strokeWidth: 1.0, pointRadius: "4"});
f.delta = [dx,dy];
nodes.push(f)
}
glyphLayer.addFeatures(nodes);
glyphLayer.redraw();
glyphLayer.redraw();
}
function doit()
{
if (running == 0)
{
running = 1;
run();
}
else
{
running = 0;
}
}
function run()
{
if (running == 1)
{
for (var n in nodes)
{
var node = nodes[n];
node.geometry.x += node.delta[0];
if (node.geometry.x < extent.left)
{
node.geometry.x = extent.left;
node.delta[0] = -node.delta[0];
}
else if (node.geometry.x > extent.right)
{
node.geometry.x = extent.right;
node.delta[0] = -node.delta[0];
}
node.geometry.y += node.delta[1];
if (node.geometry.y < extent.bottom)
{
node.geometry.y = extent.bottom;
node.delta[1] = -node.delta[1];
}
else if (node.geometry.y > extent.top)
{
node.geometry.y = extent.top;
node.delta[1] = -node.delta[1];
}
}
glyphLayer.redraw();
setTimeout(run, 0);
}
}
</script>
</head>
<body>
<div id="basicMap"></div>
<input type="button" value="Reset" onclick=reset()>
<input type="button" value="Run/Stop" onclick=doit()>
count: <input type=text id=howMany value=100>
scale: <input type=text id=howFar value=5>
</body>
</html>