Use ol.geom.LineString#getCoordinateAtM in igc example

This commit is contained in:
Frederic Junod
2014-02-28 10:25:19 +01:00
committed by Tom Payne
parent c0f9b1de19
commit bca9512478
2 changed files with 48 additions and 0 deletions

View File

@@ -36,6 +36,7 @@
<div id="docs"> <div id="docs">
<p>See the <a href="igc.js" target="_blank">igc.js source</a> to see how this is done.</p> <p>See the <a href="igc.js" target="_blank">igc.js source</a> to see how this is done.</p>
</div> </div>
<input id="time" type="range" value="0" steps="1"></input>
<div id="tags">complex-geometry, closest-feature, igc, opencyclemap</div> <div id="tags">complex-geometry, closest-feature, igc, opencyclemap</div>
</div> </div>
<div class="span4 offset4"> <div class="span4 offset4">

View File

@@ -1,4 +1,6 @@
goog.require('ol.Attribution'); goog.require('ol.Attribution');
goog.require('ol.Feature');
goog.require('ol.FeatureOverlay');
goog.require('ol.Map'); goog.require('ol.Map');
goog.require('ol.View2D'); goog.require('ol.View2D');
goog.require('ol.geom.LineString'); goog.require('ol.geom.LineString');
@@ -8,6 +10,7 @@ goog.require('ol.layer.Vector');
goog.require('ol.source.IGC'); goog.require('ol.source.IGC');
goog.require('ol.source.OSM'); goog.require('ol.source.OSM');
goog.require('ol.style.Circle'); goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke'); goog.require('ol.style.Stroke');
goog.require('ol.style.Style'); goog.require('ol.style.Style');
@@ -47,6 +50,19 @@ var vectorSource = new ol.source.IGC({
] ]
}); });
var time = {
start: Infinity,
stop: -Infinity,
duration: 0
};
vectorSource.on('addfeature', function(event) {
var geometry = event.feature.getGeometry();
time.start = Math.min(time.start, geometry.getFirstCoordinate()[2]);
time.stop = Math.max(time.stop, geometry.getLastCoordinate()[2]);
time.duration = time.stop - time.start;
});
var map = new ol.Map({ var map = new ol.Map({
layers: [ layers: [
new ol.layer.Tile({ new ol.layer.Tile({
@@ -137,3 +153,34 @@ map.on('postcompose', function(evt) {
vectorContext.drawLineStringGeometry(line); vectorContext.drawLineStringGeometry(line);
} }
}); });
var featureOverlay = new ol.FeatureOverlay({
map: map,
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.9)'
}),
stroke: null
})
})
});
$('#time').on('input', function(event) {
var value = parseInt($(this).val(), 10) / 100;
var m = time.start + (time.duration * value);
vectorSource.forEachFeature(function(feature) {
var geometry = /** @type {ol.geom.LineString} */ (feature.getGeometry());
var coordinate = geometry.getCoordinateAtM(m, true);
var highlight = feature.get('highlight');
if (highlight == undefined) {
highlight = new ol.Feature(new ol.geom.Point(coordinate));
feature.set('highlight', highlight);
featureOverlay.addFeature(highlight);
} else {
highlight.getGeometry().setCoordinates(coordinate);
}
});
map.render();
});