overlay.html
1.88 KB
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
<html>
<head>
<title>Overlay example</title>
<link rel="stylesheet" href="http://www.openlayers.org/api/2.11/theme/default/style.css" type="text/css" />
<script src="http://www.openlayers.org/api/2.11/OpenLayers.js"></script>
<script type="text/javascript" src="https://github.com/bjornharrtell/jsts/raw/master/lib/javascript.util.js"></script>
<script type="text/javascript" src="https://github.com/bjornharrtell/jsts/raw/master/lib/jsts.js"></script>
<script type="text/javascript">
function init() {
var reader = new jsts.io.WKTReader();
var a = reader.read('POLYGON((10 10, 100 10, 100 100, 10 100, 10 10))');
var b = reader.read('POLYGON((50 50, 200 50, 200 200, 50 200, 50 50))');
var union = a.union(b);
var intersection = a.intersection(b);
var map = new OpenLayers.Map('map', {
maxExtent: new OpenLayers.Bounds(0, 0, 200, 200),
maxResolution: 100,
units: 'm',
controls: [new OpenLayers.Control.MousePosition(), new OpenLayers.Control.Navigation()]
});
var layer = new OpenLayers.Layer.Vector('test', {
isBaseLayer: true
});
map.addLayer(layer);
var feature1 = new OpenLayers.Feature.Vector(a, null, { fillColor: 'blue'});
layer.addFeatures([feature1]);
var feature2 = new OpenLayers.Feature.Vector(b, null, { fillColor: 'red'});
layer.addFeatures([feature2]);
var feature3 = new OpenLayers.Feature.Vector(union, null, { strokeColor: 'green', fillOpacity: 0});
layer.addFeatures([feature3]);
var feature4 = new OpenLayers.Feature.Vector(intersection, null, { strokeColor: 'yellow', fillOpacity: 0});
layer.addFeatures([feature4]);
map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
Input polygons (blue and red) have union outlined by green and intersection outlined by yellow.
<div id="map" style="width:500px;height=500px;"></div>
</body>
</html>