jkirtz_synterra

JS API 4.11 DirectLineMeasurement3DViewModel clearMeasurement always starts new measurement

Discussion created by jkirtz_synterra on Apr 29, 2019
Latest reply on Apr 29, 2019 by jkirtz_synterra

I've created a button that the user can click to clear their current measurement. It works just fine for the DirectAreaMeasurement3D tool...I click the button, the clearMeasurement() method fires, it clears the measurement and resets the widget. However, whenever I do the same with DirectLineMeasurement3D, the clearMeasurement() method seems to be acting like the newMeasurement() method...it clears the drawing but always asks the user to start a new measurement. Can someone please let me know what I'm doing wrong?

 

app.clearMeasureButton3d.addEventListener('click', function(){
            try {
                app.measurementWidget_3D.viewModel.clearMeasurement();
            } catch (error) {
                console.log('Error message clearMeasureButton3d: ', error.message);
            }
        });

 

Here is the code that creates the appropriate widget:

 

function setActiveWidget_3dmeasurewidget(type) {
        switch (type) {
            case "distance":
                app.measurementWidget_3D = new DirectLineMeasurement3D({
                    view: app.activeView,
                    unit: "imperial"
                });
                if (app.measurementWidget_3D.view === null) {
                    app.measurementWidget_3D.view = app.activeView;
                }
                var distanceDiv = document.createElement("div");
                app.measurementWidget_3D.container = distanceDiv;
                document.getElementById("3DMeasureOutput").appendChild(distanceDiv);
                setActiveButton_3dmeasurewidget(
                    document.getElementById("distanceButton")
                );

                break;
            case "area":
                app.measurementWidget_3D = new AreaMeasurement3D({
                    view: app.activeView,
                    unit: "imperial"
                });
                var distanceDivArea = document.createElement("div");
                app.measurementWidget_3D.container = distanceDivArea;
                document.getElementById("3DMeasureOutput").appendChild(distanceDivArea);
                setActiveButton_3dmeasurewidget(document.getElementById("areaButton"));
                break;
            case null:
                if (app.measurementWidget_3D) {
                    app.activeView.ui.remove(app.measurementWidget_3D);
                    app.measurementWidget_3D.destroy();
                }
                break;
        }
    }

Outcomes