Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 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(
            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';
        return str;
        'measure': function(evt) {

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: [{
                            tolerance: 15

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

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,

            //var line = lineLayer.features[0].geometry.transform(new OpenLayers.Projection("EPSG:4326"),map.getProjectionObject());
            var line =lineLayer.features[0].geometry;
            var dist = line.getLength();


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

        // 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


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.