ol-ext/examples/interaction/map.interaction.drawhole.html
2018-01-31 11:45:59 +01:00

105 lines
3.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>ol-ext: DrawHole interaction</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="an OL3 interaction to draw holes in polygons" />
<meta name="keywords" content="ol3, interaction, draw, hole, polygon, donut" />
<link rel="stylesheet" href="../style.css" />
<!-- jQuery -->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- Openlayers -->
<link rel="stylesheet" href="https://openlayers.org/en/master/css/ol.css" />
<script type="text/javascript" src="https://openlayers.org/en/master/build/ol.js"></script>
<!-- ol-ext -->
<link rel="stylesheet" href="../../dist/ol-ext.css" />
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
</head>
<body >
<a href="https://github.com/Viglino/ol3-ext"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
<a href="../../index.html">
<h1>ol-ext: DrawHole interaction</h1>
</a>
<div class="info">
<b>ol.interaction.DrawHole</b> is an interaction to draw holes in a polygon.
<p>
NB: The interaction prevents to add points outside the polygon but
does not ensure the result polygon is consistent.
<br/>
Non convexe polygons may result in drawing holes that cross the frontiers.
</p>
</div>
<!-- Map div -->
<div id="map" style="width:600px; height:400px;"></div>
<div class="options" >
<h2>Options:</h2>
<ul>
<input id="draw" type="radio" name="toggle" checked="checked" onchange="toggle(!$(this).prop('checked'))" />
<label for="draw"> draw polygon</label>
<br/>
<input id="drawhole" type="radio" name="toggle" onchange="toggle($(this).prop('checked'))" />
<label for="drawhole"> draw hole</label>
</ul>
</div>
<script type="text/javascript">
// Layers
var layers = [
new ol.layer.Tile({
name: "Natural Earth",
minResolution: 306,
source: new ol.source.XYZ(
{ url: 'https://{a-d}.tiles.mapbox.com/v3/mapbox.natural-earth-hypso-bathy/{z}/{x}/{y}.png',
attributions: [new ol.Attribution({ html: '&copy; <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' })]
})
})
]
// The map
var map = new ol.Map
({ target: 'map',
view: new ol.View
({ zoom: 5,
center: [261720, 5951081]
}),
controls: ol.control.defaults({ "attribution": false }),
layers: layers
});
// New vector layer
var vector = new ol.layer.Vector(
{ name: 'Vecteur',
source: new ol.source.Vector()
})
map.addLayer(vector);
vector.getSource().addFeature(new ol.Feature(new ol.geom.Polygon([[[34243, 6305749], [-288626, 5757848], [210354, 5576845], [34243, 6305749]]])));
var draw = new ol.interaction.Draw (
{ source: vector.getSource(),
type:'Polygon'
});
map.addInteraction(draw);
var drawhole = new ol.interaction.DrawHole (
{ layers: [ vector ]
});
drawhole.setActive(false);
map.addInteraction(drawhole);
function toggle(active)
{ draw.setActive(!active);
drawhole.setActive(active);
}
</script>
</body>
</html>