mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-25 17:36:21 +00:00
149 lines
4.8 KiB
HTML
149 lines
4.8 KiB
HTML
<!DOCTYPE html>
|
|
<!----------------------------------------------------------
|
|
|
|
Copyright (c) 2016 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
|
|
------------------------------------------------------------>
|
|
<html>
|
|
<head>
|
|
<title>OL3-ext: Map pulse</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="An example of ol.featureAnimation to add pulses on a map." />
|
|
<meta name="keywords" content="ol3, animation, pulse, map" />
|
|
|
|
<!-- jQuery -->
|
|
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
|
|
<!-- OL3 -->
|
|
<link rel="stylesheet" href="http://openlayers.org/en/master/css/ol.css" />
|
|
<script type="text/javascript" src="http://openlayers.org/en/master/build/ol.js"></script>
|
|
|
|
<script type="text/javascript" src="../featureanimation/featureanimation.js"></script>
|
|
<script type="text/javascript" src="../featureanimation/zoomanimation.js"></script>
|
|
|
|
<link rel="stylesheet" href="style.css" />
|
|
</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>OL3-ext: Map pulse</h1>
|
|
</a>
|
|
<p class="info">
|
|
This example use ol.featureAnimation to add pulses on a map.
|
|
</p>
|
|
|
|
<!-- DIV pour la carte -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
|
|
<div class="options">
|
|
<h2>Options:</h2>
|
|
Form:
|
|
<select id="form">
|
|
<option value="Circle">circle</option>
|
|
<option value="RegularShape">square</option>
|
|
<option value="Icon">icon</option>
|
|
</select>
|
|
<br />
|
|
Easing:
|
|
<select id="easing">
|
|
<option value="easeOut">easeOut</option>
|
|
<option value="upAndDown">upAndDown</option>
|
|
<option value="bounce">bounce</option>
|
|
</select>
|
|
<br />
|
|
Color:
|
|
<select id="color">
|
|
<option value="red">red</option>
|
|
<option value="orange">orange</option>
|
|
<option value="black">black</option>
|
|
<option value="green">green</option>
|
|
</select>
|
|
<br />
|
|
<button onclick="pulse([2.351828, 48.856578])">Paris</button>
|
|
<button onclick="pulse([-0.1275,51.507222])">London</button>
|
|
<button onclick="pulse([6.149985,46.200013])">Geneve</button>
|
|
<button onclick="pulse([4.35,50.83])">Bruxelles</button>
|
|
<button onclick="pulse([13.383333,52.516667])">Berlin</button>
|
|
<button onclick="pulse([-3.683333,40.433333])">Madrid</button>
|
|
<button onclick="pulse([12.48657,41.888732])">Roma</button>
|
|
<p>
|
|
> <i>Click on the map to pulse!</i>
|
|
</p>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
// Layers
|
|
var layer = new ol.layer.Tile({
|
|
name: "Natural Earth",
|
|
minResolution: 306,
|
|
source: new ol.source.XYZ(
|
|
{ url: 'http://{a-d}.tiles.mapbox.com/v3/mapbox.natural-earth-hypso-bathy/{z}/{x}/{y}.png',
|
|
crossOrigin: "Anonymous",
|
|
attributions: [new ol.Attribution({ html: '© <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: [166326, 5992663]
|
|
}),
|
|
layers: [layer]
|
|
});
|
|
|
|
// Bounce easing (custom)
|
|
var bounce = 5;
|
|
var a = (2*bounce+1) * Math.PI/2;
|
|
var b = -0.01;
|
|
var c = -Math.cos(a) * Math.pow(2, b);
|
|
ol.easing.bounce = function(t)
|
|
{ t = 1-Math.cos(t*Math.PI/2);
|
|
return (1 + Math.abs( Math.cos(a*t) ) * Math.pow(2, b*t) + c*t)/2;
|
|
}
|
|
|
|
// Preload image (?)
|
|
var icon = new ol.style.Icon ({ src:"data/smile.png" });
|
|
icon.load();
|
|
|
|
// Pulse feature at coord
|
|
function pulseFeature(coord)
|
|
{ var f = new ol.Feature (new ol.geom.Point(coord));
|
|
f.setStyle (new ol.style.Style(
|
|
{ image: new ol.style[$("#form").val()] (
|
|
{ radius: 30,
|
|
points: 4,
|
|
src: "data/smile.png",
|
|
stroke: new ol.style.Stroke ({ color: $("#color").val(), width:2 })
|
|
})
|
|
}));
|
|
map.animateFeature (f, new ol.featureAnimation.Zoom(
|
|
{ fade: ol.easing.easeOut,
|
|
duration:3000,
|
|
easing: ol.easing[$("#easing").val()]
|
|
}));
|
|
}
|
|
|
|
// Pulse on click
|
|
map.on('singleclick', function(evt)
|
|
{ pulseFeature(evt.coordinate);
|
|
});
|
|
|
|
// Pulse at lonlat
|
|
function pulse(lonlat)
|
|
{ var nb = $("#easing").val()=='bounce' ? 1:3;
|
|
for (var i=0; i<nb; i++)
|
|
{ setTimeout (function()
|
|
{ pulseFeature (ol.proj.transform(lonlat, 'EPSG:4326', map.getView().getProjection()));
|
|
}, i*500);
|
|
};
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |