Select to view content in your preferred language

Can't setting SpatialReference and get Latitude/Longitude QML

814
2
Jump to solution
04-27-2021 07:15 PM
KanjaSousuke
New Contributor

I use Esri.ArcGISRuntime 100.9 and Qt5.15.0.

I want to get Latitude and Longitude, but can't get.

My code is

 

ApplicationWindow {
    id: appWindow
    width: 800
    height: 600
    title: "MapTest2"

    property int count: 0

    // add a mapView component
    MapView {
        id: mapView
        anchors.fill: parent
        // set focus to enable keyboard navigation
        focus: true

        // add a map to the mapview
        Map {
            // add the BasemapTopographic basemap to the map
            BasemapTopographic {}
        }

        MultipointBuilder{
            id: clickPoint
            spatialReference: SpatialReference {
                    wkid: 6668
                }
        }

        onMouseClicked: {
            console.log(mouse.mapPoint.x)
            console.log(clickPoint.points.addPoint(screenToLocation(mouse.x,mouse.y)))
            console.log(clickPoint.points.point(count).x)
            count++
        }
    }
}

 

 

This code display the following statement in the console.

qml: 11170910.901105005
qml: -1
qrc:/qml/main.qml:50: TypeError: Cannot read property 'x' of null

I think this problem is [SpatialReference].

Because, when I did the following and got no errors or anything.

 

        MultipointBuilder{
            id: clickPoint
            spatialReference: mapView.spatialReference
        }

 

But, this code can't get Latitude/Longitude in wkid:6668

Is there any way we can solve this problem?

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

I believe the issue might be that your points/coordinates coming from the mapview click event is coming in 3857 (web mercator), and then you are trying to add these points to a builder that is using 6668.

 

My suggestion is to use GeometryEngine.project to take the 3857-based points and project them into 6668 before you call addPoint on the builder. That way, you are adding the points to the builder in the correct spatial reference

 

https://developers.arcgis.com/qt/qml/api-reference/qml-esri-arcgisruntime-geometryengine.html#projec...

View solution in original post

0 Kudos
2 Replies
LucasDanzinger
Esri Frequent Contributor

I believe the issue might be that your points/coordinates coming from the mapview click event is coming in 3857 (web mercator), and then you are trying to add these points to a builder that is using 6668.

 

My suggestion is to use GeometryEngine.project to take the 3857-based points and project them into 6668 before you call addPoint on the builder. That way, you are adding the points to the builder in the correct spatial reference

 

https://developers.arcgis.com/qt/qml/api-reference/qml-esri-arcgisruntime-geometryengine.html#projec...

0 Kudos
KanjaSousuke
New Contributor

Thanks!

I can get.

0 Kudos