Multipath pointcount seems to skip number one

1721
1
05-31-2016 02:30 AM
by Anonymous User
Not applicable

Can anyone else verify this and is it expected behaviour for some reason or possibly a bug?

When creating a multipath object (e.g. a Polyline or a Polygon), the pointcount seems to skip from 0 to 2 without registering the first point.

E.g. I'm drawing a feature by capturing mouse clicks on screen, the empty Polyline json might look like this:

{"paths":[],"spatialReference":{"latestWkid":3857,"wkid":102100}}

Then I click once, and the json stays exactly the same, and the pointcount remains at zero, although that first click *is* stored in the object. Because, then when I click a second time, the json jumps to something like:

{"paths":[[[3944884.454986632,6214117.358888438],[12586059.927814495,5838414.077461138]]],"spatialReference":{"latestWkid":3857,"wkid":102100}}

and the pointcount jumps to 2.

A polygon exhibits similar behaviour.

I discovered this while trying to implement a simple "if pointcount is zero then startpath else lineto" logic. I can get around it easily enough with a separate bool property, something like isFirstPoint and manually set it, but it just seems like something isn't catching that first point properly.

Cheers,

-Paul

0 Kudos
1 Reply
nakulmanocha
Esri Regular Contributor

Hi Paul,

Ok, I can see what you are referring to here.

Remember paths or rings cannot have just one point. In order to have a legit polyline it must have atleast two points which means path has to have 2 points or more. Same for polygons.

If you want to check for the PointCount use MultiPoint approach. See the code below. This way I get the desired results

// No points yet

qml: {"points":[]}

qml: Point count is 0

qml: {"paths":[]}

// First point added

qml: {"points":[[-4207876.484103985,3465221.995640751]],"spatialReference":{"latestWkid":3857,"wkid":102100}}

qml: Point count is 1

qml: {"paths":[],"spatialReference":{"latestWkid":3857,"wkid":102100}}

// Next point added

qml: {"points":[[-4207876.484103985,3465221.995640751],[1903563.1713803783,5368785.167021126]],"spatialReference":{"latestWkid":3857,"wkid":102100}}

qml: Point count is 2

qml: {"paths":[[[-4207876.484103985,3465221.995640751],[1903563.1713803783,5368785.167021126]]],"spatialReference":{"latestWkid":3857,"wkid":102100}}

Does this help?

Thanks,

Nakul

onMouseClicked: {
            if (capturePoints == true) {
                if (numberOfClicks == 0) {
// No points yet
                    console.log(JSON.stringify(points.json))
                     console.log("Point count is ",points.pointCount)
                    console.log(JSON.stringify(featurePoly.json))
                    featurePoly.startPath(mouse.mapPoint)
                    points.add(mouse.mapPoint)

// First point added
                    console.log(JSON.stringify(points.json))
                    console.log("Point count is ",points.pointCount)
                    console.log(JSON.stringify(featurePoly.json))
                    pointGraphic.geometry = points
                    pointGraphic.symbol = markerSymbol
                } else {

// Next point added
                    points.add(mouse.mapPoint)
                    featurePoly.lineTo(mouse.mapPoint)
                    graphic.geometry = featurePoly
                    graphic.symbol = lineSym
                    pointGraphic.geometry = points
                    pointGraphic.symbol = markerSymbol
                    console.log(JSON.stringify(points.json))
                     console.log("Point count is ",points.pointCount)
                   console.log(JSON.stringify(featurePoly.json))
                }
                numberOfClicks++
            }

}
 Graphic {
            id: pointGraphic
        }

        MultiPoint {
            id: points
            spatialReference: {
                "latestWkid": 3857,
                        "wkid": 102100
            }
        }
 Polyline {
            id: featurePoly
            spatialReference: {
                "latestWkid": 3857,
                        "wkid": 102100
            }
        }
0 Kudos