Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:17:38+00:00 2026-05-29T19:17:38+00:00

Ran into a small problem when change to OpenLayers 2.11 with showing the length

  • 0

Ran into a small problem when change to OpenLayers 2.11 with showing the length of each segment on the measuring line.

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.

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.

I understand the problem, but am having trouble working out the logic…

Below is the script I am using:

    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++ < 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 && !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
            });
        }
    }

2011-11-28

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.

Source: http://trac.osgeo.org/openlayers/ticket/3315

Could anyone elaborate a bit more about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:17:38+00:00Added an answer on May 29, 2026 at 7:17 pm

    Just in case anyone wants to know the answer. https://github.com/jorix/OL-DynamicMeasure

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a small problem. I created a UITableView where the user can
I've ran into one small problem. I am dynamically generating some controls and place
Just started working with android and ran into a small problem. I am have
In my program, I ran into a problem writing a small number to a
I'm doing a project for a comapny and I ran into a small problem
I've just began learning Python and I've ran into a small problem. I need
I kinda ran into a problem, I'm working on a small image site for
I ran into the problem that my primary key sequence is not in sync
This is the problem I ran into long time ago. I thought I may
I ran into a small roadblock this morning with HandleError. Users are directed properly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.