ArcGIS JavaScript v3.17 - Spatial query to find out how many line features intersect polygon feature - arcgis-js-api

I am working on a tool using ArcGIS JavaScript v3.17 to perform a spatial query to find out how many line features intersect a polygon layer. The process works for 1 polygon layers but does not work for the other 3 polygon layers (results in an error). The error I get is: "SyntaxError: Unexpected token <" when the query is ran, which doesn't tell me much about what is wrong. See sample code below. Has anyone else seen this before? Any suggestions or help would be greatly appreciated.
function submit() {
$('#submit').on('click', function () {
query;
});
}
function query() {
var polys = map.getLayer('lyr1');
var lines = map.getLayer('lyr2');
var queryTask = new QueryTask(lines.url);
var query = new Query();
query.geometry = polys.graphics[0].geometry;
query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
query.outFields = ['*'];
queryTask.on("complete", queryTaskExecuteCompleteHandler);
queryTask.on("error", queryTaskErrorHandler);
queryTask.execute(query);
}
function queryTaskExecuteCompleteHandler(queryResults) {
console.log("complete", queryResults.featureSet.features.length);
}
function queryTaskErrorHandler(queryError){
console.log("error", queryError.error);
}

I have solved my issue by going a different route and am now using the geometryEngine intersects process to find out if a line intersects a polygon. This involves a for loop that goes over a list of each line graphic > runs the intersects process comparing the polygon feature to the line graphic geometry > if true, the id gets pushed to an array > will use that array to get a total and also a definition expression on the line features.

Related

How to read values from a view to insert in ratingValue and ratingCount in my web in order to be recognized by Google Structured data testing tool?

I was using an external service to get Aggregate Rating in my recipes blog, but dis service disappeared so I decided to build one myself. First of all, this is my first experience with cloud data and JavaScript programming so please, be paciente with me :-).
I'm doing my experiments in this duplicate of my blog: https://jleavalc.blogspot.com/
by now it works as I planned, letting one to vote and storing results in a oracle table, making it possible to retrieve results from a view of this table to get ratingCount and ratingValue values, as anyone can see in that link...
But at the end, despite you can see the stars, despite you can vote and get result stored, showing voting results, Structured data testing tool don't see tag values, so all work is useless.
I think I'm getting close to the problem, but not getting close to the solution. I have the impression that the cause of my problems is the asynchrony of the execution of the script that brings the data from the table, while the function is executed, the browser continues to render the page and it doesn't arrive in time to write those values ​​before the google tool can read them, so they appear empty to it.
I have tried everything including labels and variables in GTM with the same result. The latest version of the code, from this morning is installed right before the "/head" tag and it looks like this:
<script style='text/javascript'>
var myPostId = "<data:widgets.Blog.first.posts.first.id/>";
// <![CDATA[
var micuenta = 0;
var nota = 0;
getText("https://ge4e65cc87f573d-XXXXXXXXXXXX.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/notas/?q={\"receta\":{\"$eq\":\"" + myPostId + "\"}}");
async function getText(file) {
let x = await fetch(file);
let y = await x.text();
let datos = JSON.parse(y);
nota = datos.items[0].media;
micuenta = datos.items[0].votos;
};
// This version gives the same result and is interchangeable with the previous one. I keep it commented so as not to forget it:
// var settings = {
// "url": "https://ge4e65cc87f573d-db20220526112405.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/notas/?q={\"receta\":{\"$eq\":\"" + myPostId + "\"}}",
// "method": "GET",
// "timeout": 0,
// "async": false,
// };
// $.ajax(settings).done(function (response) {
// if (response.items.length != 0) {
// micuenta = response.items[0].votos;
// nota = response.items[0].media;
// }
// });
</script>
The key is, I think, getting this call to execute before Google's tool finishes rendering the Blogger post page.
The URL that I invoke to get the data calls an oracle view that returns a single row with the corresponding data from the recipe, placing this call:
recipe
In the browser the result is the following:
{"items":[{"receta":"5086941171011962392","media":4.5,"votos":12}],"hasMore":false,"limit":25,"offset":0,"count":1,"links":[{"rel":"self","href":"https://ge4e65cc87f573d-db20220526112405.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/notas/?q=%7B%22receta%22:%7B%22%24eq%22:%225086941171011962392%22%7D%7D"},{"rel":"edit","href":"https://ge4e65cc87f573d-db20220526112405.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/notas/?q=%7B%22receta%22:%7B%22%24eq%22:%225086941171011962392%22%7D%7D"},{"rel":"describedby","href":"https://ge4e65cc87f573d-db20220526112405.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/metadata-catalog/notas/"},{"rel":"first","href":"https://ge4e65cc87f573d-db20220526112405.adb.eu-amsterdam-1.oraclecloudapps.com/ords/admin/notas/?q=%7B%22receta%22:%7B%22%24eq%22:%225086941171011962392%22%7D%7D"}]}
And I just need to take the median and votes values ​​to create the RatingCount and RatingValue labels
Can anyone offer me an idea that solves this little problem? :-)

I am designing a function in JS for scrolling dynamic page how can I pass document as an argument?

I am designing a JS function to achieve scrolling of dynamic page so I created a function in Scroll.feature as
#ignore
* def ScrollFunction()=
"""
function(document){
var height = document.body.scrollHeight
while(true){
window.scrollTo(0, document.body.scrollHeight)
var newHeight = document.body.scrollHeight
if (newHeight === height) {
break;
}
height = newHeight ;
}
}
"""
And From another feature file, I will call this function for scrolling, but how will I pass the document parameter to this function?
Sorry, you need to spend some time reading and understanding this: https://github.com/intuit/karate/tree/master/karate-core#karate-vs-the-browser
Even your understanding of Karate functions needs clarity: https://github.com/intuit/karate#multiple-functions-in-one-file
Now, document should always work as long as a driver has been initialized.
One hint is you can break up into pieces like this:
* def getHeight = function(){ return script("document.body.scrollHeight") }
And then you can use getHeight() in some other function. Also refer https://github.com/intuit/karate/tree/master/karate-core#function-composition
So please open a new question once you have tried again.

Strava API - accurate longitude and latitude

Does anyone know a way to get the exact longitude and latitude for an activity from the strava api using a get request?
I'm trying to integrate the strava api with google maps and I'm trying to build an array with the appropriate long/lat locations, but the https://www.strava.com/api/v3/athlete/activities?per_page=100... request is only returning longitude and latitudes rounded off like: start_longitude: 2.6.
I've found a "hacky" way of retrieving the start coordinates by looping through results and then sending off another request within the loop, although this is sending WAY too many requests. - below is a snippet of my request:
// start request
$.get( "https://www.strava.com/api/v3/athlete/activities?per_page=100&access_token=ACCESSTOKEN", function (results) {
// loop through request
for (i = 0; i < results.length; i++) {
if(results[i].type === 'Run') {
// add an element to the array for each result
stravaComplete.push(true);
$.get( "https://www.strava.com/api/v3/activities/"+ results[i].id +"?per_page=5&access_token=ACCESSTOKEN", function (runs) {
if(typeof runs.segment_efforts[0] != "undefined"){
var runLatitude = runs.segment_efforts[0].segment.start_latitude;
var runLongitude = runs.segment_efforts[0].segment.start_longitude;
stravaActivityList.push({"lat": runLatitude, "lng": runLongitude});
}
// remove the element from the array
stravaComplete.pop();
// if all the elements have been removed from the array it means the request is complete
if(stravaComplete.length == 0) {
// reinitialize map
initMap(stravaActivityList);
}
});
}
}
});
Any guidance would be great. Thanks.
It's not clear if you need coordinates of start points only, or for the whole activity and what accuracy is required.
Response to query https://www.strava.com/api/v3/athlete/activities includes a field map => summary_polyline from which you should be able to extract coordinates of the whole (although simplified) activity. You can also use this polyline to display it in google maps.
If you, however, need even better accuracy you need to retrieve every activity and use map => summary_polyline or map => polyline fields.
To get full data streams should be used
Use summary_polyline[0] and summary_polyline[-1] (Ruby) instead of rounded values. See this code from Slava for an example.

Map does not zoom when feature is selected on Feature Table

According to the API Feature Table API both the syncSelection and the zoomToSelection properties are true by default so I thought that meant when I selected a row the map would zoom in on the selected feature but that doesn't appear to be true. In the sample at Feature Table Sample the map centers on the selected feature but the zoom level does not change. Is there a way to make the map zoom in on the selected feature?
You can make it zoom using dojo's aspect. It will make all calls to map.centerAt in your application do the zoom too, but is maybe your best option in this case, assuming the application is simple. Something like this:
aspect.after(map, "centerAt", function(target, m) {
map.centerAndZoom(m[0], 16);
return target;
}.bind(this));
Don't forget to include dojo/aspect in your AMD includes.
I'm sure Gavin's answer works but I wound up using the code in the ZoomToSelectedFeature's menu option in Feature Table Sample as follows. (The ROUTE_ID was an attribute of the selected feature).
myFeatureTable.on("row-select", function(evt){
zoomToRoute(evt[0].data.ROUTE_ID);
});
function zoomToRoute(routeId){
var query = new Query();
query.returnGeometry = true;
query.outFields = [ "*" ];
query.where = "ROUTE_ID = '" + routeId + "'" ;
routeFeature.selectFeatures(query, FeatureLayer.SELECTION_NEW, function(features){
var extent = graphicsUtils.graphicsExtent(features).expand(1.25);
map.setExtent(extent);
});
}

AngularJS: Take a single item from an array and add to scope

I have a ctrl that pulls a json array from an API. In my code I have an ng-repeat that loops through results.
This is for a PhoneGap mobile app and I'd like to take a single element from the array so that I can use it for the page title.
So... I'm wanting to use 'tool_type' outside of my ng-repeat.
Thanks in advance - I'm just not sure where to start on this one.
Example json data
[{ "entry_id":"241",
"title":"70041",
"url_title":"event-70041",
"status":"open",
"images_url":"http://DOMAIN.com/uploads/event_images/241/70041__small.jpg",
"application_details":"Cobalt tool bits are designed for machining work hardening alloys and other tough materials. They have increased water resistance and tool life. This improves performance and retention of the cutting edge.",
"product_sku":"70041",
"tool_type": "Toolbits",
"sort_group": "HSCo Toolbits",
"material":"HSCo8",
"pack_details":"Need Checking",
"discount_category":"102",
"finish":"P0 Bright Finish",
"series_description":"HSS CO FLAT TOOLBIT DIN4964"},
..... MORE .....
Ctrl to call API
// Factory to get products by category
app.factory("api_get_channel_entries_products", function ($resource) {
var catID = $.url().attr('relative').replace(/\D/g,'');
return $resource(
"http://DOMAIN.com/feeds/app_productlist/:cat_id",
{
cat_id: catID
}
);
});
// Get the list from the factory and put data into $scope.categories so it can be repeated
function productList ($scope, api_get_channel_entries_products, $compile) {
$scope.products_list = [];
// Get the current URL and then regex out everything except numbers - ie the entry id
$.url().attr('anchor').replace(/\D/g,'');
$scope.products_list = api_get_channel_entries_products.query();
}
Angular works as following:
Forgiving: expression evaluation is forgiving to undefined and null, unlike in JavaScript, >where trying to evaluate undefined properties can generate ReferenceError or TypeError.
http://code.angularjs.org/1.2.9/docs/guide/expression
so you only need to write:
<title>{{products_list[0].tool_type}}</title>
if there is a zero element the title will be the tool_type, if not, there is no title.
Assuming you want to select a random object from the list to use something like this should work:
$scope.product-tool_type = products_list[Math.floor(Math.random()*products_list.length)].tool_type
Then to display the result just use
<h1>{{product-tool_type}}</h1>
Or alternatively:
<h1>{{products_list[Math.floor(Math.random()*products_list.length)].tool_type}}</h1>