ol-ext/examples/interaction/map.interaction.modifytouch.html

152 lines
4.7 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: Modify interaction for touch device</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="transform interaction for OL3" />
<meta name="keywords" content="ol3, vector, transform, rotate, scale, stretch" />
<link rel="stylesheet" href="../style.css" />
<!-- jQuery -->
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
<!-- FontAwesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Openlayers -->
<link rel="stylesheet" href="https://openlayers.org/en/latest/css/ol.css" />
<script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
<!-- ol-ext -->
<link rel="stylesheet" href="../../dist/ol-ext.css" />
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
<style>
.ol-popup.modifytouch a:before {
content: "\274C";
margin-right:.2em;
}
</style>
</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: Modify interaction for touch device</h1>
</a>
<div class="info">
<b>ol.interaction.ModifyTouch</b> is a modify interaction for touch devices
that display a poppup to delete a point when click on it.
<br/>
You can customize the popup using the <i>setPopupContent()</i> function.
<br/>
You can overide the <i>showDeleteBt()</i> function to do have a different behavior tha a popup (display a button on the map).
</div>
<!-- Map div -->
<div id="map" style="width:600px; height:400px;"></div>
<div class="options" >
<h2>Options:</h2>
<label><input id="menu" type="checkbox" onclick="showmenu();" checked="checked" />
show popup/show menu
</label>
</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: [ '&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]
}),
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, 6000000], [-288626, 5757848], [-200000, 5500000], [210354, 5576845], [210354, 6000000], [34243, 6305749]]])));
vector.getSource().addFeature(new ol.Feature(new ol.geom.LineString([[400000, 5664901], [480000, 5600000], [650000, 5718712], [700000, 6000000], [600000, 6200000], [425601, 6183449]])));
vector.getSource().addFeature(new ol.Feature(new ol.geom.Point( [269914, 6248592])));
var select = new ol.interaction.Select({
layers: [ vector ],
hitTolerance: 5
});
map.addInteraction(select);
// Interaction
var modify = new ol.interaction.ModifyTouch({
// source: vector.getSource(),
features: select.getFeatures()
});
map.addInteraction(modify);
//
var bar = new ol.control.Bar();
map.addControl(bar);
var removeBt = new ol.control.Toggle({
html: '<i class="fa fa-trash"></i>',
onToggle: function(b) {
// Prevent openning on click
removeBt.setActive(false);
},
bar: new ol.control.Bar({
controls: [
new ol.control.TextButton({
html:"remove&nbsp;point",
handleClick: function(b) {
modify.removePoint();
}
})
]
})
});
bar.addControl(removeBt);
// Handle bar
modify.on('showpopup', function(e) {
//console.log(e)
if (!modify.get('usePopup')) removeBt.setActive(true);
});
modify.on('hidepopup', function(e) {
//console.log(e)
removeBt.setActive(false);
});
function showmenu () {
modify.set('usePopup', $("#menu").prop('checked'));
modify.setActive(true);
}
</script>
</body>
</html>