JS API 4.11 DirectLineMeasurement3DViewModel clearMeasurement always starts new measurement

415
3
04-29-2019 06:59 AM
JustinKirtz
New Contributor II

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;
        }
    }
0 Kudos
3 Replies
SaschaBrunnerCH
Esri Contributor

Hi Justin,

Thanks for reporting this issue and the isolated example. We’ll get this fixed in the next release.

0 Kudos
JustinKirtz
New Contributor II

Thanks for the reply and the update, I'll comment out this code for now and wait for the fix in the next release. No biggie.

Thanks again!

-Justin

ParsaHonarmand
New Contributor

Hi Sascha, 

I'm currently having this same issue for arcgis/core 's NPM package version 4.18. I was wondering if there has been a fix for this, or a way around it. Calling clear() works fine for Area Measurements. But when used with Direct Measurement, it doesn't clear the measurement if I have not placed my first point down. 

0 Kudos