Hi.
I use Runtime version 100.8 and Qt 5.15.0 .
I want to get Lat/Long from MultiPointBuilder.
property int count: 0
Connections{
target: mainMap
function onMouseClicked(mouseEvent) {
clickPointBuilder.points.addPoint(screenToLocation(mouseEvent.x,mouseEvent.y))
console.log(clickPointBuilder.points.point(count).x)
count++
}
}
This code get error [TypeError: Cannot read property 'x' of null].
Why get error?
Solved! Go to Solution.
It's important that the spatial reference of your Map and your MultipointBuilder are the same. I advise trying to set the spatialReference on your map itself (id : mapType in the above example,) to 6668 as well, in the same manner that you've been doing on the MultipointBuilder
Hi there.
I think what's happening here is that the addPoint method is failing to add your point. You can check that this is indeed the case by checking the return value, which is -1 if the method fails.
There are several reasons why the addPoint method can fail, (and unfortunately, it's not always that easy to distinguish between them.) It's hard to be certain without the entirety of the code, but I suspect what's happening here is a spatial reference issue. Does your pointBuilder have a spatialReference assigned? It needs to be the same one as the map you're using.
If not, try adding one where you create it, like this :
MultipointBuilder{
id: clickPointBuilder
spatialReference: map.spatialReference
}
It can get.
But My pointBuilder had a spatialReference already.
I want to use wkid:6668, So I had set it up in pointBuilder, but it didn't work.
MapView {
id: mainMap
property alias mainMap: mainMap
property alias mapType: mapType
property alias clickPointBuilder: clickPointBuilder
Map {
id: mapType
BasemapTopographic {}
}
MultipointBuilder {
id: clickPointBuilder
//Get Error
// spatialReference: SpatialReference {
// wkid: 6668
// }
//No Error
spatialReference: mainMap.spatialReference
}
}
It's important that the spatial reference of your Map and your MultipointBuilder are the same. I advise trying to set the spatialReference on your map itself (id : mapType in the above example,) to 6668 as well, in the same manner that you've been doing on the MultipointBuilder