Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have problem about measurecontrol . I can use measurecontrol and i can show length to use measure control . But my problem is that .i didnt use in snap because measurecontrol is a control not layer .enter code here

            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 openlayers snapp example enter code here

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

snap is using only vector but my measurecontrol not vector .Plz show me some way i hope i can explain my question ...Also is there another way to use measure in layer linestring layer???? thx everybody

share|improve this question

1 Answer 1

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

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.