Changing the vertices of a line graphic is not working

3814
3
Jump to solution
05-13-2015 02:58 PM
RainerFarsch
New Contributor III

I'm adding a line graphic to a graphic layer and then later trying to change its vertices. I'm using the MutliPoint's setPoint() to change the vertices, but after doing so, the line graphic disappears.  Below is simplified code of what I'm trying to do. On creation, the line graphic shows. I then call upon sendWaypointClicked() to update the line graphic's vertices (to hard-coded values in this example). The debugging console.log() statements are putting out the correct coordinates, but the line disappears after calling setPoint() on the line graphic's polyline. Any help is appreciated in getting the line to appear with updated vertices.

Thanks!

import ArcGIS.Runtime 10.25

GraphicsLayer {
    id: root
    renderingMode: Enums.RenderingModeDynamic
    function sendWaypointClicked()
    {
        console.log("Point count: ", polyline.pointCount);
        console.log("Old heloCoord - x:", polyline.point(0).x, ", y:", polyline.point(0).y);
        console.log("Old waypointCoord - x:", polyline.point(1).x, ", y:", polyline.point(1).y);
        console.log("New heloCoord - x:", heloCoord.x, ", y:", heloCoord.y);
        console.log("New waypointCoord - x:", waypointCoord.x, ", y:", waypointCoord.y);
        polyline.setPoint(0, heloCoord)
        polyline.setPoint(1, waypointCoord)
        console.log("Latest heloCoord - x:", polyline.point(0).x, ", y:", polyline.point(0).y);
        console.log("Latest waypointCoord - x:", polyline.point(1).x, ", y:", polyline.point(1).y);
    }
    property Point waypointCoord:
        Point {
            x: 13357521
            y: 1571120
            spatialReference: SpatialReference {wkid: 102100}
        }
    property Point heloCoord:
        Point {
            x: 13387521
            y: 1571120
            spatialReference: SpatialReference {wkid: 102100}
        }
    Graphic {
        id: courseTrack
        geometry: Polyline {
            id: polyline
            json: {
                "spatialReference":{"latestWkid": 3857, "wkid": 102100},
                "paths": [[ [13367521, 1571120], [13397521, 1571120] ]]
            }
        }
        symbol: SimpleLineSymbol {
            color: "red"
            width: 4
        }
    }
}

					
				
			
			
				
			
			
				
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Hey Rainer-

There are some cases where editing a geometry that belongs to the graphic can cause unexpected behavior in a multithreaded environment, such as what you are seeing. This is one of the driving factors for us changing how you will work with geometries across all of the runtime APIs at our Quartz release (coming later this year). In that release, geometries will be immutable. With the current release, and the upcoming 10.2.6 release, if you want to modify geometries that belong to graphics, you will need to create a new geometry, or use the clone method. In your case, you could want to clone the polyline with the clone() method, and then set the new instance of the polyline to the graphic's geometry. Here is an example based on your above code:

var polyline2 = polyline.clone();
polyline2.setPoint(0, heloCoord);
polyline2.setPoint(1, waypointCoord);
courseTrack.geometry = polyline2;

Thanks,

Luke

View solution in original post

0 Kudos
3 Replies
LucasDanzinger
Esri Frequent Contributor

Hey Rainer-

There are some cases where editing a geometry that belongs to the graphic can cause unexpected behavior in a multithreaded environment, such as what you are seeing. This is one of the driving factors for us changing how you will work with geometries across all of the runtime APIs at our Quartz release (coming later this year). In that release, geometries will be immutable. With the current release, and the upcoming 10.2.6 release, if you want to modify geometries that belong to graphics, you will need to create a new geometry, or use the clone method. In your case, you could want to clone the polyline with the clone() method, and then set the new instance of the polyline to the graphic's geometry. Here is an example based on your above code:

var polyline2 = polyline.clone();
polyline2.setPoint(0, heloCoord);
polyline2.setPoint(1, waypointCoord);
courseTrack.geometry = polyline2;

Thanks,

Luke

0 Kudos
RainerFarsch
New Contributor III

Like,

I was revisiting this the other day and tried changing geometry from 'Polyline' to 'Line' - this failed. So I cut it down to simply put a line graphic with fixed coordinates, using the 'Line' geometry in place of the 'Polyline' geometry. What am I doing wrong? When I changed the geometry to be a 'Point' and changed the symbol to be 'SimpleMarkerSymbol', all is good.

As an aside, how can I paste in code blocks like you have done in your responses? I tried the advanced editor features and didn't see anything.

Thanks!

-Rainer

Here's the code:

GraphicsLayer {

    id: root

.

.

.

    Graphic {

        id: lineGraphic

        geometry: Line {

            id: line

            startXY: Point {

                x: 13379537

                y: 1543463

            }

            endXY: Point {

                x: 13380537

                y: 1548463

            }

            spatialReference: SpatialReference {

                wkid: 102100

            }

        }

        symbol: SimpleLineSymbol {

            color: "red"

            width: 2

            style: Enums.SimpleLineSymbolStyleDash

        }

    }

}

0 Kudos
LucasDanzinger
Esri Frequent Contributor

Rainer-

This looks like it may be a bug. I suggest you contact support to troubleshoot it and get it logged. I was able to get this to work with a Polyline though, so you might just want to use that in the meantime. I used different coordinates that were more obvious to see on the screen, but this should work with what you have too. I put this code below.

For the syntax highlighting, it is a bit hidden, but you need to first select advanced editor, then ">>" > "Syntax Highlighting" > "javascript". Then copy in your code from there. I found that I need to copy from Qt Creator into another text editor first that copies it as plain text, as it looks a bit messed up with the formatting from Qt Creator + Syntax Highlighting here in GeoNet.

GraphicsLayer {
    id: gl
}


onStatusChanged: {
    if (status === Enums.MapStatusReady) {
        var graphic = ArcGISRuntime.createObject("Graphic");
        var asymbol = ArcGISRuntime.createObject("SimpleLineSymbol");
        var polyline_ = ArcGISRuntime.createObject("Polyline");
        polyline_.spatialReference = map.spatialReference;
        polyline_.startPath(5000000,6000000);
        polyline_.lineTo(12000000,6000000);
        graphic.symbol = asymbol;
        graphic.geometry = polyline_;
        gl.addGraphic(graphic);
    }
}

0 Kudos