0

I have this class based on pure javascript:

var DrawFeatureP = /*@__PURE__*/(function (Draw) {
    function DrawFeatureP() {
        debugger
        Draw.call(this, {
            source: new ol.layer.Vector({ source: new ol.source.Vector() }),
            type: 'change this property from function in pottom'
        });

        document.getElementById('lineToggle').onclick = this.handleDrawFeature.bind(this);
     }


    if (Draw) DrawFeatureP.__proto__ = Draw;
    DrawFeatureP.prototype = Object.create(Draw && Draw.prototype);
    DrawFeatureP.prototype.constructor = DrawFeatureP;

    DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
        //when is function is fired how ca i set 'type' property?
    };

    return DrawFeatureP;
}(ol.interaction.Draw));

When this function is fired:

   DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
            //when is function is fired how ca I set 'type' property?
        };

I need to change the 'type' property :

type: 'change this property from function in the bottom'

My question is how to edit type property from handleDraw function?

1
  • In my opinion this function is impure. because there happens dom manipulation. imho. Change my mind if anyone can Commented Apr 8, 2020 at 21:35

1 Answer 1

1

Since you bind this when assigning the onclick handler, you can use this.type in the handler function.

    DrawFeatureP.prototype.handleDrawFeature = function handleDraw(evt) {
        this.type = "new type";
    };
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the post. But the example above not works. Any idea what can be the reason?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.