JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.10.1/css/ol.css">
<script src="http://openlayers.org/en/v3.10.1/build/ol.js"></script>
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
JavaScript
var raster = new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
});
var source = new ol.source.Vector();
var vector = new ol.layer.Vector({
source: source
});
var map = new ol.Map({
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [-11000000, 4600000],
zoom: 4
})
});
var interaction = new ol.interaction.Draw({
type: 'LineString',
maxPoints: 2,
source: source,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'red',
width: 1,
// lineDash: [10],
})
})
});
map.addInteraction(interaction);
interaction.on('drawend', function(e) {
var style = new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 12
})
});
e.feature.setStyle(style);
var start = e.feature.getGeometry().getFirstCoordinate();
var end = e.feature.getGeometry().getLastCoordinate();
var dx = end[0] - start[0];
var dy = end[1] - start[1];
var rotation = Math.atan2(dy, dx);
var a = new ol.Feature({
geometry: new ol.geom.Point(end)
});
var b = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 0.5],
anchorOrigin: 'top-left',
offset: [0, 0],
scale: 3,
opacity: 1,
rotateWithView: false,
rotation: -rotation,
...