Hello,
I am trying to make a function where I can locate near by points. The idea is that I click on a point in the map and a hitTest would return the graphic. This graphic would be the center point and I would find all points within a given radius. Ideally I would want to know the point and the distance and in a array.
I am lost at the moment, I am working with multiple Feature Layers. If possible to point me to an example that would be perfect.
Here is a sample of what I am doing at the moment.
""""""""""""""""""""""" This point gives me the graphics objec I clicked on """"""""""""""""""""""""""""""""'
bd4sp.view.hitTest(event)
.then(bd4sp.getGraphics) //gets the graphics
.then(bd4sp.createDistanceLayer); // creates the lines for distance
""""""""""""""""""""""""""""""""""""""
***********************************************************************************************************************************
// This function takes the response and tries
getGraphics: function (response) {
//clearPolyline(); //clear old lines
var graphic = response.results[0].graphic; //the top most graphic from the click location
console.log("Graphic Object", graphic['geometry']);
var close_points = bd4sp.geo_engine.nearestVertices(graphic['geometry'],graphic['geometry'], 300, 20);
console.log("Close Points", close_points);
//Obtain lat and long form graphic information
var p_o_i = bd4sp.point_of_intrest[0].geogrpraphic_proximity; // point of intrests
var lat_long_arry = [];
var polyarry = [];
for (var make in p_o_i) {
for (var i = 0; i < p_o_i[make].length; i++) {
var x = p_o_i[make].x;
var y = p_o_i[make].y;
lat_long_arry.push({x,y});
}
}
polyarry = bd4sp.getAllClosePoints(graphic.geometry['latitude'], graphic.geometry['longitude'], lat_long_arry); //array of graphic lines
console.log("LINES TO DRAW ->", polyarry);
return polyarry;
}
***********************************************************************************************************************************
This
var close_points = bd4sp.geo_engine.nearestVertices(graphic['geometry'],graphic['geometry'], 300, 20);
returns an array but I always get 0 because its the same point, is there a way to have one argument only?
Solved! Go to Solution.
What probably want to do here is:
It's preferable (in my opinion) to do the extent search first because it's cheap compared to the circle search, and the majority of graphics will likely be eliminated. The geometryEngine.intersects method is more expensive when using a circle or polygon, so this should only be tested against graphics you know are inside the circle's extent.
Edit - this is the client-side method. You can also pass in the circle to featureLayer.queryFeatures to do this on the server. If you do this, you'll want to send one featureLayer.queryFeatures request for each featureLayer. You'll wrap these requests in Promise.all(), wait for all of them to return, and then display your results with polylines or however you like. If you use the server, you don't need to worry about the intersects method being expensive so forget the circle.extent stuff for that.
Isn't the first parameter of the nearestVertices method supposed to be the geometry of the points you're trying to locate instead of the point you clicked?
It might be but i am wondering if there is a way to find those points in a radius and get there information, without knowing where it is exactly.
What probably want to do here is:
It's preferable (in my opinion) to do the extent search first because it's cheap compared to the circle search, and the majority of graphics will likely be eliminated. The geometryEngine.intersects method is more expensive when using a circle or polygon, so this should only be tested against graphics you know are inside the circle's extent.
Edit - this is the client-side method. You can also pass in the circle to featureLayer.queryFeatures to do this on the server. If you do this, you'll want to send one featureLayer.queryFeatures request for each featureLayer. You'll wrap these requests in Promise.all(), wait for all of them to return, and then display your results with polylines or however you like. If you use the server, you don't need to worry about the intersects method being expensive so forget the circle.extent stuff for that.
thank you sounds great .
This makes a lot of sense to me.