mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-25 17:36:21 +00:00
139 lines
3.6 KiB
HTML
139 lines
3.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!--
|
|
Copyright (c) 2015-2019 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
-->
|
|
<title>ol-ext: Profile style</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="Draw profiles on a map with Openlayers." />
|
|
<meta name="keywords" content="ol, openlayers, vector, style, stroke, variable, gpx, profile" />
|
|
|
|
<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://cdn.jsdelivr.net/npm/ol@latest/ol.css" />
|
|
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/ol@latest/dist/ol.js"></script>
|
|
|
|
|
|
<!-- ol-ext -->
|
|
<link rel="stylesheet" href="../../dist/ol-ext.css" />
|
|
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
|
|
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
|
|
<script src="https://unpkg.com/elm-pep"></script>
|
|
|
|
<style>
|
|
.ol-legend {
|
|
background: #fff;
|
|
padding: 2px 1em;
|
|
}
|
|
.ol-legend ul {
|
|
margin-bottom: 12px;
|
|
}
|
|
.ol-legend ul li {
|
|
overflow: visible;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
|
|
|
|
<a href="../../index.html">
|
|
<h1>ol-ext: Profile style</h1>
|
|
</a>
|
|
<div class="info">
|
|
<i>ol/style/Profile</i> is a style to draw line profiles on a map.
|
|
</div>
|
|
|
|
<!-- Map div -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
|
|
<div class="options" style="min-width:300px;">
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
// Layers
|
|
var layer = new ol.layer.Geoportail({
|
|
layer: 'ORTHOIMAGERY.ORTHOPHOTOS'
|
|
});
|
|
|
|
// The map
|
|
var map = new ol.Map({
|
|
target: 'map',
|
|
view: new ol.View({
|
|
zoom: 13,
|
|
//center: [740741, 5776642]
|
|
center: [646752, 5407059]
|
|
}),
|
|
layers: [layer]
|
|
});
|
|
|
|
// GPX vetor layer
|
|
var source = new ol.source.Vector({
|
|
//url: '../data/192553.gpx',
|
|
url: '../data/2009-09-04_rando.gpx',
|
|
format: new ol.format.GPX()
|
|
});
|
|
var style = ol.style.Style.defaultStyle();
|
|
style.push(new ol.style.Profile({
|
|
stroke: new ol.style.Stroke({ color: [255, 255, 255, .5], width: 1 }),
|
|
fill: new ol.style.Fill({ color: [255, 255, 255, .3] }),
|
|
scale: .2
|
|
}))
|
|
var vector = new ol.layer.Vector({
|
|
source: source,
|
|
style: style
|
|
});
|
|
map.addLayer(vector);
|
|
|
|
// Profile control
|
|
var profile = new ol.control.Profile({
|
|
target: $('.options').get(0),
|
|
skipFirst: 5
|
|
});
|
|
map.addControl(profile);
|
|
source.once('change',function(e) {
|
|
if (source.getState() === 'ready'){
|
|
profile.setGeometry(source.getFeatures()[0]);
|
|
}
|
|
});
|
|
|
|
|
|
// Show feature profile when loaded
|
|
var pt = new ol.Feature(new ol.geom.Point([0,0]));
|
|
var overlay = new ol.layer.Vector({ source: new ol.source.Vector() });
|
|
overlay.getSource().addFeature(pt);
|
|
overlay.setMap(map);
|
|
|
|
source.once('change',function(e) {
|
|
if (source.getState() === 'ready'){
|
|
profile.setGeometry(source.getFeatures()[0]);
|
|
}
|
|
});
|
|
|
|
// Show a popup on over
|
|
profile.on(["over","out"], function(e){
|
|
if (!pt) return;
|
|
if (e.type=="over"){
|
|
// Show point at coord
|
|
pt.setGeometry(new ol.geom.Point(e.coord));
|
|
pt.setStyle(style);
|
|
} else {
|
|
// hide point
|
|
pt.setStyle([]);
|
|
}
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |