mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-25 17:36:21 +00:00
105 lines
3.5 KiB
HTML
105 lines
3.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!----------------------------------------------------------
|
|
|
|
Copyright (c) 2016-2018 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
|
|
------------------------------------------------------------>
|
|
<title>ol-ext: Snap guides interaction</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="an OL3 interaction to draw regular polygon" />
|
|
<meta name="keywords" content="ol3, interaction, draw, regular, rectangle, circle, triangle" />
|
|
|
|
<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: Snap guides interaction</h1>
|
|
</a>
|
|
<div class="info">
|
|
<b>ol.interaction.SnapGuide</b> handles snapping of vector features using guides lines while modifying or drawing them.
|
|
<br/>
|
|
The snap interaction modifies map browser event coordinate and pixel properties to force the snap to occur
|
|
to any interaction that them.
|
|
<ul>
|
|
<li>
|
|
You can add guidelines to snap to.
|
|
</li>
|
|
<li>
|
|
You can set an <i>ol.interaction.Draw</i> to control orthogonal drawing (similar to <a href="https://github.com/geops/ole">OLE snapping</a> with OL2).
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- Map div -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
|
|
<div class="options" >
|
|
<h2>Options:</h2>
|
|
<ul><li>
|
|
</li></ul>
|
|
<button onclick="addMeridian(0)">Add a Greenwich origin guideline</button>
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
// Layers
|
|
var layers = [ new ol.layer.Tile({ source: new ol.source.OSM() }) ];
|
|
|
|
// The map
|
|
var map = new ol.Map
|
|
({ target: 'map',
|
|
view: new ol.View
|
|
({ zoom: 17,
|
|
center: [269766, 6248649]
|
|
}),
|
|
controls: ol.control.defaults({ "attribution": false }),
|
|
layers: layers
|
|
});
|
|
|
|
// New vector layer
|
|
var vector = new ol.layer.Vector(
|
|
{ name: 'Vecteur',
|
|
source: new ol.source.Vector({ features: new ol.Collection() }),
|
|
})
|
|
map.addLayer(vector);
|
|
|
|
var drawi = new ol.interaction.Draw(
|
|
{ source: vector.getSource(),
|
|
//type: "LineString"
|
|
type: "Polygon"
|
|
});
|
|
map.addInteraction(drawi);
|
|
|
|
var snapi = new ol.interaction.SnapGuides();
|
|
snapi.setDrawInteraction(drawi);
|
|
map.addInteraction(snapi);
|
|
|
|
// New guide on meridian (default Greenwich)
|
|
function addMeridian (x)
|
|
{ var p1 = ol.proj.transform([x||0,1], 'EPSG:4326', map.getView().getProjection());
|
|
var p2 = ol.proj.transform([x||0,-1], 'EPSG:4326', map.getView().getProjection());
|
|
snapi.addGuide([ p1, p2 ]);
|
|
};
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |