Your suggestions sounds fine. Also every geometry object has a distanceTo() function which can be used like:
geometry.distanceTo(anothergeometry)
EDIT:
After more thought and testing the example, i think it would be easiest for you add new layer for labeling purposes. Possibly a layer of just points which you would set the labelXOffset and labelYOffset to half the distance between each point in your measuring linestring. But i don't think you'll be able to rotate the labels.
Look at how this measure tool is, it's probably the best you'll be able to do:
http://chamaps.com/watervliet/
Check out how he does it:
http://chamaps.com/watervliet/js/map.js
var lineStyle = new OpenLayers.Style();
lineStyle.addRules([
new OpenLayers.Rule({
symbolizer: linemeasureStyles
})]);
var linemeasureStyleMap = new OpenLayers.StyleMap({
"default": lineStyle
});
var length = new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
displaySystem: "english",
geodesic: true,
persist: true,
handlerOptions: {
layerOptions: {
styleMap: linemeasureStyleMap
}
},
textNodes: null,
callbacks: {
create: function () {
this.textNodes = [];
layerRuler.removeFeatures(layerRuler.features);
mouseMovements = 0;
},
modify: function (point, line) {
if (mouseMovements++ < 5) {
return;
}
var len = line.geometry.components.length;
var from = line.geometry.components[len - 2];
var to = line.geometry.components[len - 1];
var ls = new OpenLayers.Geometry.LineString([from, to]);
var dist = this.getBestLength(ls);
if (!dist[0]) {
return;
}
var total = this.getBestLength(line.geometry);
var label = dist[0].toFixed(2) + " " + dist[1];
var textNode = this.textNodes[len - 2] || null;
if (textNode && !textNode.layer) {
this.textNodes.pop();
textNode = null;
}
if (!textNode) {
var c = ls.getCentroid();
textNode = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(c.x, c.y), {}, {
label: '',
fontColor: "#FF0000",
fontSize: "14px",
fontFamily: "Arial",
fontWeight: "bold",
labelAlign: "cm"
});
this.textNodes.push(textNode);
layerRuler.addFeatures([textNode]);
}
textNode.geometry.x = (from.x + to.x) / 2;
textNode.geometry.y = (from.y + to.y) / 2;
textNode.style.label = label;
textNode.layer.drawFeature(textNode);
this.events.triggerEvent("measuredynamic", {
measure: dist[0],
total: total[0],
units: dist[1],
order: 1,
geometry: ls
});
}
}
});
Best Answer
see the exemple on openlayers website and have a glance to the source code, adapting it you will be able to get the length of last segment
I would quickly adapt the code like that (not tested) :