ol-ext/examples/map.popup.anim.html
2016-05-08 17:37:34 +02:00

165 lines
5.5 KiB
HTML

<!DOCTYPE html>
<!----------------------------------------------------------
Copyright (c) 2015 Jean-Marc VIGLINO,
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
------------------------------------------------------------>
<html>
<head>
<title>OL3-ext: Animated popup overlay</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 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>
<!-- http://openlayers.org/en/v3.2.0/build/ol.js -->
<!-- http://openlayers.org/en/v3.2.0/build/ol-debug.js -->
<link rel="stylesheet" href="../control/layerswitchercontrol.css" />
<script type="text/javascript" src="../control/layerswitchercontrol.js"></script>
<link rel="stylesheet" href="../overlay/popupoverlay.css" />
<link rel="stylesheet" href="../overlay/popupoverlay.anim.css" />
<!-- CSS with bounce effect -->
<script type="text/javascript" src="../overlay/popupoverlay.js"></script>
<link rel="stylesheet" href="style.css" />
<style>
/* popup style */
.ol-popup
{ max-width:300px;
min-width:100px;
min-height:1em;
}
/* Image on popup */
.ol-popup img
{ float: left;
margin: 0 0.5em 0 0;
max-width: 100px;
max-height: 100px;
}
</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>OL3-ext: Animated popup overlay</h1>
</a>
<div class="info">
This example uses the <i>ol.Overlay.Popup</i> to display popup on the map.
It uses the CSS properties to add a bounce effect to the popup display
<br/>
See <a href="map.popup.html">popup overlay example</a> form more options.
</div>
<!-- DIV pour la carte -->
<div id="map" style="width:600px; height:400px;"></div>
<div class="options">
<h2>Options:</h2>
Positioning:
<select id="positioning" onchange="popup.setPositioning(this.value); map.renderSync();">
<option value="auto">auto</option>
<option value="bottom-auto">bottom-auto</option>
<option value="bottom-left">bottom-left</option>
<option value="bottom-center" selected="selected">bottom-center</option>
<option value="bottom-right">bottom-right</option>
<option value="top-auto">top-auto</option>
<option value="top-left">top-left</option>
<option value="top-center">top-center</option>
<option value="top-right">top-right</option>
<option value="center-auto">center-auto</option>
<option value="center-left">center-left</option>
<option value="center-right">center-right</option>
</select>
</div>
<p>Click on the points to show a popup !</p>
<script type="text/javascript">
// Layers
var layers = [
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',
attributions: [new ol.Attribution({ html: '&copy; <a href="https://www.mapbox.com/map-feedback/">Mapbox</a> ' })]
})
})
]
// Popup overlay
var popup = new ol.Overlay.Popup (
{ popupClass: "default", //"tooltips", "warning" "black" "default", "tips", "shadow",
closeBox: true,
onclose: function(){ console.log("You close the box"); },
positioning: $("#positioning").val(),
autoPan: true,
autoPanAnimation: { duration: 100 }
});
// The map
var map = new ol.Map
({ target: 'map',
view: new ol.View
({ zoom: 5,
center: [166326, 5992663]
}),
layers: layers,
overlays: [popup]
});
// GeoJSON layer
var vectorSource = new ol.source.Vector(
{ url: 'data/fond_guerre.geojson',
projection: 'EPSG:3857',
format: new ol.format.GeoJSON(),
attributions: [new ol.Attribution({ html: "&copy; <a href='https://www.data.gouv.fr/fr/datasets/fonds-de-la-guerre-14-18-extrait-de-la-base-memoire/'>data.gouv.fr</a>" })],
logo:"https://www.data.gouv.fr/s/avatars/37/e56718abd4465985ddde68b33be1ef.jpg"
});
/* Preload images */
var listenerKey = vectorSource.on('change', function(e)
{ if (vectorSource.getState() == 'ready')
{ ol.Observable.unByKey(listenerKey);
var f = vectorSource.getFeatures();
for (var i=0; i<f.length; i++)
{ var img = new Image();
img.src = f[i].get("img");
}
}
});
/**/
map.addLayer(new ol.layer.Vector(
{ name: 'Fonds de guerre 14-18',
source: vectorSource
}));
// Control Select
var select = new ol.interaction.Select({});
map.addInteraction(select);
// On selected => show/hide popup
select.getFeatures().on(['add'], function(e)
{ var feature = e.element;
var content = "";
content += "<img src='"+feature.get("img")+"'/>";
content += feature.get("text");
popup.show(feature.getGeometry().getCoordinates(), content);
})
select.getFeatures().on(['remove'], function(e)
{ popup.hide();
})
</script>
</body>
</html>