-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
142 lines (121 loc) · 5.38 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>Draw Feature Example</title>
<link rel="stylesheet" href="http://openlayers.org/dev/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="http://openlayers.org/dev/examples/style.css" type="text/css">
<style type="text/css">
#controlToggle li {
list-style: none;
}
p {
width: 512px;
}
/* avoid pink tiles */
.olImageLoadError {
background-color: transparent !important;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://openlayers.org/dev/OpenLayers.js"></script>
<script type="text/javascript">
var map, drawControls, markers;
function addMarker(id, name, lat, lon) {
var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
var marker = new OpenLayers.Marker(new OpenLayers.LonLat(lon, lat), icon);
var markerClick = function(evt) {
OpenLayers.Event.stop(evt);
//console.log('Location:', id, name);
$('#location').text(name +' (' +id +')');
};
marker.events.register("mouseover", marker, markerClick);
//marker.events.register("mousedown", marker, markerClick);
markers.addMarker(marker);
}
function logVertices(vertices) {
var points = '';
vertices.forEach(function(vertice){
points += vertice.y +',' +vertice.x +':';
});
points = points.substr(0, points.length-1);
var url = '/search.xqy?points=' +points;
$.ajax({
dataType: 'xml',
url: url,
success: function(data) {
$(data).find("location").each(function() {
addMarker(
$(this).find("id").text(),
$(this).find("name").text(),
$(this).find("latitude").text(),
$(this).find("longitude").text()
);
});
}
});
}
function init(){
map = new OpenLayers.Map('map');
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'});
var polygonLayer = new OpenLayers.Layer.Vector("Polygon Layer");
markers = new OpenLayers.Layer.Markers( "Markers" );
polygonLayer.events.on({
featuresadded: function(event) {
var vertices = event.features[0].geometry.getVertices();
logVertices(vertices);
drawControls.polygon.deactivate();
}
});
map.addLayers([wmsLayer, polygonLayer, markers]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
drawControls = {
polygon: new OpenLayers.Control.DrawFeature(polygonLayer,
OpenLayers.Handler.Polygon),
};
for(var key in drawControls) {
map.addControl(drawControls[key]);
}
//map.setCenter(new OpenLayers.LonLat(0.1062, 51.5171), 3);
map.setCenter(new OpenLayers.LonLat(0.106, 51.517), 10);
//document.getElementById('noneToggle').checked = true;
}
function drawPolygon() {
drawControls.polygon.activate();
}
function toggleControl(element) {
for(key in drawControls) {
var control = drawControls[key];
if(element.value == key && element.checked) {
control.activate();
} else {
control.deactivate();
}
}
}
function allowPan(element) {
var stop = !element.checked;
for(var key in drawControls) {
drawControls[key].handler.stopDown = stop;
drawControls[key].handler.stopUp = stop;
}
}
</script>
</head>
<body onload="init()">
<h2 id="location">Draw a polygon</h2>
<div id="map" class="smallmap"></div>
<ul id="controlToggle">
<li>
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="drawPolygon(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
</ul>
</body>
</html>