﻿<!DOCTYPE html>
<html>
<head>
<!----------------------------------------------------------
 
	Copyright (c) 2016 Jean-Marc VIGLINO, 
	released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
	
------------------------------------------------------------>
	<title>ol-ext: Long touch interaction</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

	<meta name="description" content="an OL3 interaction handle long touch." />
	<meta name="keywords" content="ol3, interaction, touch lonh" />

	<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/latest/css/ol.css" />
	<script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
	<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></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/ol-ext" class="icss-github-corner"><i></i></a>

	<a href="../../index.html">
		<h1>ol-ext: Long touch interaction</h1>
	</a>
	<div class="info">
		<b>ol.interaction.LongTouch</b> is an interaction to handle a long touch event. 
		<ul>
			<li>
				<i>handleLongTouchEvent</i> option will receive a mapBrowserEvent.
			</li>
			<li>
				The <i>delay</i> option control the duration of the lonftouch.
			</li>
		</ul>
	</div>

	<!-- Map div -->
	<div id="map" style="width:600px; height:400px;"></div>

	<div class="options" >
		<h2>Information:</h2>
		<p>Touch or click the map for more than a 1 second to add a point.</p>
		<ul><li>
		</li></ul>
		<div style="background:white; padding:0 0.45em;"></div>
	</div>
	

	<script type="text/javascript">
		// Layers
		var layers = [
			new ol.layer.Tile({
				title:'terrain-background',
				source: new ol.source.Stamen({ layer: 'terrain' })
			})
		]
		// 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({ features: new ol.Collection() }),
			updateWhileInteracting: true
		})
		map.addLayer(vector);

		function pulseFeature(coord)
		{	var f = new ol.Feature (new ol.geom.Point(coord));
			f.setStyle (new ol.style.Style(
						{	image: new ol.style.Circle (
							{	radius: 30, 
								stroke: new ol.style.Stroke ({ color:"red", width:2 })
							})
						}));
			map.animateFeature (f, new ol.featureAnimation.Zoom(
				{	fade: ol.easing.easeOut, 
					duration:800, 
					easing: ol.easing[$("#easing").val()] 
				}));
		};

		var touchi = new ol.interaction.LongTouch(
			{	handleLongTouchEvent: function(e)
				{	var f = new ol.Feature(new ol.geom.Point(e.coordinate));
					vector.getSource().addFeature(f);
					pulseFeature(e.coordinate);
					setTimeout( function(){pulseFeature(e.coordinate);}, 400);
					$(".options div").text(vector.getSource().getFeatures().length+" features added!");
				} 
			});
		map.addInteraction(touchi);

	</script>

</body>
</html>