Select to view content in your preferred language

Create Routing Geometry for point clicked on map.

1155
2
Jump to solution
02-27-2021 04:06 AM
EricAtkinson1
Regular Contributor

Hey all,

Before I start I wanted to thank everyone for their help on a few questions I have posted lately. I really appreciated the help.

My question is creating geometry for a point clicked on the map. I want to solve a route from my current location to a feature or a point click on the map. I can get the current location working to a set point but can't get the point to work. At the moment I have this but coming up with the line not defined.

 

 

stop2Geometry = ArcGISRuntimeEnvironment.createObject("Point", {                                                                                  y: mapView.mouse.mapPoint.position.y,                                                                                  x: mapView.mouse.mapPoint.position.x,                                                                                  spatialReference: SpatialReference.createWgs84()                                                                              });

 

 

 

I'm working on QML Runtime 100.8.

Also I would like this to work onClicked to automatically solve the route.

 

Cheers,

 

Eric 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JaredCaccamo
Esri Contributor

Hello @EricAtkinson1 ,

I am unable to find a mouse property for the MapView type but I think we can do this another way. The map view has an onMouseClicked signal handler for when you click on the map view. Within that you can do the following:

MapView {
  id: mapView

  onMouseClicked: {
    const clickedPoint = mapView.screenToLocation(mouse.x, mouse.y);

    const stopPoint = ArcGISRuntimeEnvironment.createObject("Stop", {geometry: clickedPoint});
  }
}

 

You can also reference our "Route around barriers" sample, https://github.com/Esri/arcgis-runtime-samples-qt/blob/be0fc9486d53d8a87379065bf14095d518ea3ba7/ArcG.... This sample demonstrates a similar workflow where it does solve the route every-time there is a click to add a stop to the map(for two or more stops). It does a few more really cool things like adding in barriers in which it will take those into account and optimize for the best route given those barriers and also can find the best sequence which will reorder stops to optimize the route.

 

I hope you find this helpful!

- Jared

View solution in original post

2 Replies
JaredCaccamo
Esri Contributor

Hello @EricAtkinson1 ,

I am unable to find a mouse property for the MapView type but I think we can do this another way. The map view has an onMouseClicked signal handler for when you click on the map view. Within that you can do the following:

MapView {
  id: mapView

  onMouseClicked: {
    const clickedPoint = mapView.screenToLocation(mouse.x, mouse.y);

    const stopPoint = ArcGISRuntimeEnvironment.createObject("Stop", {geometry: clickedPoint});
  }
}

 

You can also reference our "Route around barriers" sample, https://github.com/Esri/arcgis-runtime-samples-qt/blob/be0fc9486d53d8a87379065bf14095d518ea3ba7/ArcG.... This sample demonstrates a similar workflow where it does solve the route every-time there is a click to add a stop to the map(for two or more stops). It does a few more really cool things like adding in barriers in which it will take those into account and optimize for the best route given those barriers and also can find the best sequence which will reorder stops to optimize the route.

 

I hope you find this helpful!

- Jared

EricAtkinson1
Regular Contributor

Thanks Jared that worked a treat!