Note that there are some explanatory texts on larger screens.

plurals
  1. POMeasure segment length fix for OpenLayers 2.11
    primarykey
    data
    text
    <p>Ran into a small problem when change to OpenLayers 2.11 with showing the length of each segment on the measuring line.</p> <p>Previously after placing points A --> B, B --> C. The length of segment A to B would show up between those points, likewise with B to C and after ending the line the total would be displayed.</p> <p>My script worked fine with OpenLayers 2.10, but after changing to OpenLayers 2.11 as soon as I end the line only the segment values disappear from the vector layer.</p> <p>I understand the problem, but am having trouble working out the logic... </p> <p>Below is the script I am using:</p> <pre><code> line: new OpenLayers.Control.Measure(OpenLayers.Handler.Path, { persist: true, handlerOptions: { layerOptions: { renderers: renderer, styleMap: styleMap } }, textNodes: null, callbacks:{ create: function(){ this.textNodes = []; vlayer.destroyFeatures(vlayer.features); /*-- figured this area is the problem */ mouseMovements = 0; }, modify: function(point, line){ if(mouseMovements++ &lt; 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(3) + " " + dist[1]; var textNode = this.textNodes[len -2] || null; if(textNode &amp;&amp; !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: "#800517", fontSize: "12px", fontFamily: "Tahoma", fontWeight: "bold", labelAlign: "cm" }); this.textNodes.push(textNode); vlayer.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 }); } } </code></pre> <p>2011-11-28</p> <p>After researching a bit, I've come to the conclusion that in OpenLayers 2.11 the measure partial control is activated as soon as the button is clicked. Previously in OpenLayers 2.10 the measure partial control was activated when the map was clicked and ended at the same time the path was ended, so the reason it worked before was that the textnodes array would be empty only at the start of a new line, but in 2.11 the measure partial control does not deactivate once at the end of the path, so in effect reverting back to an empty array and erasing the layer features when I end the line.</p> <p>Source: <a href="http://trac.osgeo.org/openlayers/ticket/3315" rel="nofollow">http://trac.osgeo.org/openlayers/ticket/3315</a></p> <p>Could anyone elaborate a bit more about this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload