[OpenLayers-Dev] Re: Adding Segment Length to Path

Xavier Mamano (jorix) xavier.mamano at gmail.com
Fri Dec 9 19:38:20 EST 2011


Hi Yus,

Sorry, is not a good idea to take the same layer of the handler. Forget it!

Now callbacks no longer serve in the same way, I think it is better to use
"point" instead of "modify". And `destroyFeatures` in the first "point"
(`this.mouseMovements == 0`) , and in "create" only set `this.mouseMovements
= 0`.

The freehand is another problem, it is dirty.

I'll try step by step and answer tomorrow.

Xavier


Xavier Mamano (jorix) wrote
> 
> Hi Yus,
> 
> Interesting...
> 
> You will need to assign value to the `vlayer` in callbacks `create` and
> `modify` as:
> ```
> var vlayer = this.handler.layer;
> ```
> that's it!
> 
> Xavier
> 
> 
> Yus wrote
>> 
>> Hi.
>> 
>> 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); *<-- Believe the
>> problem is here*
>>             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
>>             });
>>         }
>>     }
>> }),
>> 
>> Any advice is very appreciated. Thanks in advance
>> 
> 


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Adding-Segment-Length-to-Path-tp7029815p7080319.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.


More information about the Dev mailing list