Is it possible to get map extent values using ArcGIS JavaScript API 4x?

1431
6
Jump to solution
09-23-2019 02:37 AM
rlttechcbe
New Contributor II

I have been trying to start working on the javascript API.  I need to retrieve the feature layer name if any point features are there within the extent values. The extent values will differ, whenever we are performing zoom in or zoom out process. If not possible, how can we do this in some other way?

Thanks in Advance.

0 Kudos
1 Solution

Accepted Solutions
BenElan
Esri Contributor

The snippet below is from this sample

// Watch view's stationary property for becoming true.
watchUtils.whenTrue(view, "stationary", function() {
// Get the new center of the view only when view is stationary.
if (view.center) {
var info =
"<br> <span> the view center changed. </span> x: " +
view.center.x.toFixed(2) +
" y: " +
view.center.y.toFixed(2);
displayMessage(info);
}

// Get the new extent of the view only when view is stationary.
if (view.extent) {
var info =
"<br> <span> the view extent changed: </span>" +
"<br> xmin:" +
view.extent.xmin.toFixed(2) +
" xmax: " +
view.extent.xmax.toFixed(2) +
"<br> ymin:" +
view.extent.ymin.toFixed(2) +
" ymax: " +
view.extent.ymax.toFixed(2);
displayMessage(info);
}
});

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

In the 4.x api you just watch the views stationary property to be true then get the view.extent property.

BenElan
Esri Contributor

The snippet below is from this sample

// Watch view's stationary property for becoming true.
watchUtils.whenTrue(view, "stationary", function() {
// Get the new center of the view only when view is stationary.
if (view.center) {
var info =
"<br> <span> the view center changed. </span> x: " +
view.center.x.toFixed(2) +
" y: " +
view.center.y.toFixed(2);
displayMessage(info);
}

// Get the new extent of the view only when view is stationary.
if (view.extent) {
var info =
"<br> <span> the view extent changed: </span>" +
"<br> xmin:" +
view.extent.xmin.toFixed(2) +
" xmax: " +
view.extent.xmax.toFixed(2) +
"<br> ymin:" +
view.extent.ymin.toFixed(2) +
" ymax: " +
view.extent.ymax.toFixed(2);
displayMessage(info);
}
});

View solution in original post

rlttechcbe
New Contributor II

Ah! Thanks for the help! I'll check it out soon. 

0 Kudos
rlttechcbe
New Contributor II

Thank you Mr.Ben Elan.. (view.extent) property is working now... Within this map extent can we able to retrieve the count of point features from the feature layer in the version of 4x series? This functionality is working in 3x series here.  But according to the 4x series still I am analyzing about it whether or not it is possible. 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor
BenElan
Esri Contributor

The relevant code being

view.whenLayerView(featureLayer).then(function(layerView) {
layerView.watch("updating", function(value) {
if (!value) {
// wait for the layer view to finish updating

// query all the features available for drawing.
layerView
.queryFeatures({
geometry: view.extent,
returnGeometry: true
})
.then(function(results) {
// Get count of features
console.log(results.features.length)
})
.catch(function(error) {
console.error("query failed: ", error);
});
}
});
});
0 Kudos