Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a problem about measurecontrol. I can use measurecontrol and I can show length to use measure control . But my problem is that I didn't use in snap because measurecontrol is a control, not a layer.

    measureControl = new OpenLayers.Control.Measure(
        OpenLayers.Handler.Path,
        {
            immediate: true,
            persist: true
        }
    );  

    measureControl.getCustomLength = function(evt) {
        var str = '';
        str = 'Toplam: ' + (evt.units === 'km' ? evt.measure.toFixed(3) : evt.measure.toFixed(1)) + ' ' + evt.units + '   ';
           // uzunluk =evt.units ==='km';
            uzunluk=evt.measure;
        return str;
    }
    map.addControl(measureControl);
    measureControl.events.on({
        'measure': function(evt) {
            $("#mesafe").html(measureControl.getCustomLength(evt));
        }
    });
    measureControl.activate();

This is my measure control. And I want to snap this to point to my another vector. So when I look openlayer's snap:

    var snap = new OpenLayers.Control.Snapping({
        layer: measurecontrollayer,
        targets: [{
            layer:mylayer,
            tolerance: 15
            }]
        });
        snap.activate(); 

snap is using only vector but my measurecontrol is not a vector. Please show me some way to achieve this. Also is there another way to use measure in layer linestring layer?

share|improve this question

Firstly i want to say measurecontrol is not using on snapp control. So u create own your linestring like that

          var lineLayer = new OpenLayers.Layer.Vector("Line Layer");  

            drawControls = {
            line: new OpenLayers.Control.DrawFeature(lineLayer,
                    OpenLayers.Handler.Path)

            };
              $("#yollayer").click(function(){
            drawControls.line.activate();
            });
             $("#mapDiv").dblclick(function(){
            //var line = lineLayer.features[0].geometry.transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
            var line =lineLayer.features[0].geometry;
            var dist = line.getLength();
            uzunluk=dist/1000;
            alert(dist/1000);
            }); 

            map.addControl(drawControls.line);
            map.addLayers([lineLayer]);`

be careful line.getlength() result is meter distanceee .This is give you when u draw linestring in lineLayer result is meausure this linestring.

Then u must add snapp control like that .

            snap = new OpenLayers.Control.Snapping({
            layer: lineLayer,
            targets: [kullaniciparsel],
            greedy: false
        });
        snap.activate();

        // add some editing tools to a panel
        var panel = new OpenLayers.Control.Panel({
            displayClass: "olControlEditingToolbar"
        });
        modify = new OpenLayers.Control.ModifyFeature(
            lineLayer, {displayClass: "olControlModifyFeature", title: "Modify Features"}
        );  `

Dont remember snap contral layer must be editable layer . This is result .When u draw linestring automatically snapping your target layer.

share|improve this answer

I just found your answer. While your solution was that Measure doesn't use the Snapping Control, it seems to me, that in my application this is not true. When I disable the OpenLayers.Control.Snapping, then no snapping occurs. So it is used.

The only difference to your application is, that I use the DynamicMeasure.js lib which extends the Measure.js from OpenLayers but doesn't change the Snap-Handling.

By the way: I am using OpenLayers 2.13 in my example

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.