Select to view content in your preferred language

Measurement Tool - "clearResult() is not a function"

1368
8
Jump to solution
01-23-2014 05:29 AM
DarrinBaldinelli
Emerging Contributor
I'm having an issue where the measurement tool's graphics are not going away after I dismiss the measurement tool.

The tool's markup looks like this:

<td align="center" align="left" id="tdMeasure" class="tdHeader">
                                <img alt="Measure" src="images/measure.png" class="imgOptions" title="Measure"
                                    onclick="
                                    if (measureDialog.open){
                                    measureDialog.clearResult();
                                    measureDialog.hide();
                                    alert('worked');
                                    }
                                    else{
                                    measureDialog.show();
                                    }
                                    " />
                            </td>

According to the documentation (https://developers.arcgis.com/en/javascript/jsapi/measurement.html), clearResult() is indeed a method that should remove the graphics (apparently it was added in v2.4). My application is using the 3.5compact version of the API, so why would the browser tell me clearResult() is not a function? I am completely stumped here.

Thanks for the help.
0 Kudos
1 Solution

Accepted Solutions
JeffPace
MVP Alum
ITs not a scoping issue.

measureDialog.open is a property of a DOM element, not the measurement dijit

therefore measureDialog.clearResult() does not exist, since the clearResult method doesnt exist on the DOM element

your (pseudocode) should be

if(measureDialog.open){
measureDijit.clearResult();
}

View solution in original post

0 Kudos
8 Replies
JonathanUihlein
Esri Regular Contributor
This is a scope issue.

Instead of using javascript inline with your HTML, try creating the event inside your require block using dojo/on.
0 Kudos
DarrinBaldinelli
Emerging Contributor
Jon,

Thanks for the reply. I removed the inline code and instead tried using dojo/on as you suggested. Here's my code:

require(["dojo/on", "dojo/_base/window", "dojo/query"], function (on, win) {
    on(win.doc, ".imgOptions:click", clickHandler);
});

function clickHandler() {
    measureDialog.clearResult();
}

When the user clicks the element with class "imgOptions", I still get the same message: "TypeError: measureDialog.clearResult is not a function"...Am I just using the wrong version of the API? Here's my script reference:

<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5compact"></script>

This is all contained within the Tax Parcel Viewer (http://www.arcgis.com/home/item.html?id=23cc5b90b78d45e0bd51ede193328568). Thanks again for your help!
0 Kudos
JeffPace
MVP Alum
ITs not a scoping issue.

measureDialog.open is a property of a DOM element, not the measurement dijit

therefore measureDialog.clearResult() does not exist, since the clearResult method doesnt exist on the DOM element

your (pseudocode) should be

if(measureDialog.open){
measureDijit.clearResult();
}
0 Kudos
JonathanUihlein
Esri Regular Contributor
Actually, I think Jeff is right!

I wrongfully assumed measureDialog was a reference to the dijit from lack of context.
A reference to the dijit is not the same thing as a reference to its domNode.

Thanks Jeff!
0 Kudos
DarrinBaldinelli
Emerging Contributor
Thank you guys for the help.

I initially wasn't thinking in terms of variable scope, but thanks to you and others now I do have most of the functionality working the way I need it. However, there is still one oddity left that I'm wondering about:

Even after using the setTool and clearResult methods as shown in the API reference (https://developers.arcgis.com/en/javascript/jsapi/measurement.html), the small flag graphic is still showing on the map after clicking on an adjacent parcel to the one the user was originally trying to measure.

Here's my code:

require(["dojo/on", "dojo/_base/window", "dojo/query"], function (on, win) {
            on(win.doc, ".imgOptions:click", clickHandler);
        });
        function clickHandler() {
           
            if (measurement.open) {
                measurement.clearResult();
                measurement.hide();
                measurement.setTool("area", false);
                measurement.setTool("distance", false);
                measurement.setTool("location", false);
            }
            else {
                measurement.show();
                measurement.clearResult();
                measurement.setTool("area", true);
                measurement.setTool("distance", true);
                measurement.setTool("location", true);
            }
        }

imgOptions is the class of the widget image the user clicks to show/hide the measurement widget. Also, can anyone explain exactly what the destroy() method does? Maybe it's just me, but the description "Destroy the measurement widget." is a little ambiguous.
0 Kudos
JeffPace
MVP Alum
map.graphics.clear()

do this right after you clear results
0 Kudos
JeffPace
MVP Alum
and destroy should delete the widget DOM elements and remove it from the dijit registry.  This is necessary if you ever want to re-instatiate the widget with the same name/id
0 Kudos
DarrinBaldinelli
Emerging Contributor
Thank you very much!
0 Kudos