forked from geoffmcl/map-test2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
highlight-feature.html
106 lines (90 loc) · 3.81 KB
/
highlight-feature.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
<!DOCTYPE html>
<html>
<head>
<!-- from : http://openlayers.org/dev/examples/highlight-feature.html -->
<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>SelectFeature Control for Select and Highlight</title>
<link rel="stylesheet" href="js/theme/default/style.css" type="text/css">
<!--[if lte IE 6]>
<link rel="stylesheet" href="../theme/default/ie6-style.css" type="text/css">
<![endif]-->
<link rel="stylesheet" href="css/style2.css" type="text/css">
<style type="text/css">
#controlToggle li {
list-style: none;
}
</style>
<!-- <script src="../lib/Firebug/firebug.js"></script> -->
<script src="js/OpenLayers.js"></script>
<script type="text/javascript">
var map, controls;
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = 2;
function init(){
map = new OpenLayers.Map('map');
var vectors = new OpenLayers.Layer.Vector("vector", {isBaseLayer: true});
map.addLayers([vectors]);
var feature = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON((28.828125 0.3515625, 132.1875 -13.0078125, -1.40625 -59.4140625, 28.828125 0.3515625))"
)
);
vectors.addFeatures([feature]);
var feature2 = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON((-120.828125 -50.3515625, -80.1875 -80.0078125, -40.40625 -20.4140625, -120.828125 -50.3515625))"
)
);
vectors.addFeatures([feature2]);
var feature3 = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON((28.828125 60.3515625, 132.1875 53.0078125, -1.40625 19.4140625, 28.828125 60.3515625))"
)
);
vectors.addFeatures([feature3]);
// "POLYGON(-20 10,-10 -10,10 10,10 -10,20 10,10 12,-20 10)"
var feature4 = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON(-30 10, -40 40, -20 40, -10 20, -30 10)"
)
);
vectors.addFeatures([feature4]);
var report = function(e) {
//OpenLayers.Console.log(e.type, e.feature.id);
console.log('type: '+e.type+' id: '+e.feature.id);
};
var highlightCtrl = new OpenLayers.Control.SelectFeature(vectors, {
hover: true,
highlightOnly: true,
renderIntent: "temporary",
eventListeners: {
beforefeaturehighlighted: report,
featurehighlighted: report,
featureunhighlighted: report
}
});
var selectCtrl = new OpenLayers.Control.SelectFeature(vectors,
{clickout: true}
);
map.addControl(highlightCtrl);
map.addControl(selectCtrl);
highlightCtrl.activate();
selectCtrl.activate();
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
}
</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers Select and Highlight Feature Example</h1>
<div id="tags">
select, highlight, hover, onmouseover, click, vector
</div>
<p id="shortdesc">
Select features on click, highlight features on hover.
</p>
<div id="map" class="smallmap"></div>
<p>Select features by clicking on them. Just highlight features by hovering over
them.</p>
</body>
</html>