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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>USA States</title>
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
<meta name="description" content="A demo that pulls in USA state data from GeoCommons">
<meta name="author" content="Ryan Westphal">
<link rel="stylesheet" href="css/style.css" />
<style type="text/css">
#map { position: fixed; left: 0; top: 0; right: 0; bottom: 0; }
</style>
</head>
<body>
<div>
<div id="map">
</div>
<div class="info">
<div class="links">
<a href="../" class="docLink">< docs</a>
<a href="http://jsfiddle.net/ryanttb/sh8uH/embedded/" class="fiddleLink"><img src="img/jsfiddle.png" alt="" /> jsFiddle ></a>
</div>
<h1>USA States</h1>
<p class="not-mobile">This map reads USA state boundary data as a GeoJSON FeatureCollection and draws it on top of OpenStreetMap.</p>
<p>Click a state to change its color!</p>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script src="js/iecors.js"></script>
<script src="http://code.jquerygeo.com/jquery.geo-1.0a4.min.js"></script>
<script>
$(function () {
var map = $("#map").geomap({
center: [-71.0595678, 42.3604823],
zoom: 6,
mode: "drawPoint",
shape: function (e, geo) {
var state = map.geomap("find", geo, 0);
if (state.length > 0) {
map.geomap("remove", state[0]);
var color = Math.round(0xffffff * Math.random()).toString(16);
map.geomap("append", state[0], {
color: "#" + ( color.length == 5 ? "0" : "" ) + color
});
}
}
}),
states = null;
$.ajax({
url: "http://data.jquerygeo.com/usastates.json",
dataType: "json",
success: function (result) {
states = result;
map.geomap("append", states);
},
error: function (xhr) {
alert(xhr.statusText);
}
});
});
</script>
</body>
</html>
|