_extent mean in the example

4022
4
04-01-2015 10:41 AM
Chang-HengYang
New Contributor III

Hi All,

Could you let me know what the "_extent" mean in the sample code under the Property Details, "cache" on the website  ?

Thanks,

Hank

Tags (3)
0 Kudos
4 Replies
JasonZou
Occasional Contributor III

Which type of object are you talking about?

0 Kudos
KenBuja
MVP Esteemed Contributor

It's the code snippet under the cache property of Extent (lines 46 and 63). Hopefully Kelly Hutchins or John Gravois​ could explain.

var map;

require([
  "esri/InfoTemplate",
  "esri/layers/FeatureLayer",
  "esri/map",
  "esri/tasks/query", "dojo/domReady!"
], function (InfoTemplate, FeatureLayer, Map, Query){

  map = new Map("map", {
    basemap: "topo",
    center: [-122.45, 37.75], // longitude, latitude
    zoom: 10
  });

  var infoTemplate = new InfoTemplate("Attributes", "${*}");

  var countiesFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/3",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });
  var highwaysFeatureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/1",
    {
      mode: FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ['*']
    });

  map.on("load", function (){
    map.addLayer(countiesFeatureLayer);
    map.addLayer(highwaysFeatureLayer);

    var query = new Query();
    query.geometry = map.extent;
    query.spatialRelationship = Query.SPATIAL_REL_ENVELOPEINTERSECTS;
    query.returnGeometry = true;
    query.outFields = ["*"];

    countiesFeatureLayer.queryFeatures(query, function (featureSet){
      var polygon = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var polygonExtent = polygon.getExtent();
      console.log("polygonExtent", polygonExtent);
      console.log("polygon.cache._extent", polygon.cache._extent);

      for (var i = 0; i < featureSet.features.length;) {
        var feature = featureSet.features[i];
        console.log("Polygon geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Polygon geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

    highwaysFeatureLayer.queryFeatures(query, function (featureSet){
      var line = featureSet.features[0].geometry;
      // populate the Geometry cache by calling getExtent()
      var lineExtent = line.getExtent();
      console.log("lineExtent", lineExtent);
      console.log("line.cache._extent", line.cache._extent);

      for (var i = 0; i < featureSet.features.length;) {
        var feature = featureSet.features[i];
        console.log("Line geometry cache, %o", feature.geometry.cache);
        feature.geometry.clearCache();
        console.log("Line geometry clear cache, %o", feature.geometry.cache);
        // Break out of the loop after the first result
        break;
      }
    });

  });
});
0 Kudos
JohnGravois
Frequent Contributor

i've never seen this before, but it looks like the code snippet is attempting to convey how to ensure that the cache property is hydrated and how to clear it.

i couldn't give much more insight than that into how exactly it might be used by clientside developers in the context of mutating geometries, perhaps its primary purpose is something internal to the API.

in general, property names that begin with an underscore denote that they are 'private', which doesn't mean much in JavaScript other than the fact that the API maintainers don't doc it and that it is subject to change without notice in the future.

JasonZou
Occasional Contributor III

Ok. The cache property is newly introduced for all geometry objects except points in v3.13. I just played a little bit with it. Its value will be undefined by default, and will keep as is if no change is made to the geometry. When the geometry changes, its cache property will be calculated. It has only two private properties: _extent and _partwise. Not sure exactly why it is introduced. Here is my guess. While the user editing a geometry, the cache object will save the intermediate result so to enable drawing them on the map, and it will enable the application to cancel the edit by clearing the cache. Otherwise, when the edit is done, the new geometry will be the last geometry hosted in the cache object.

Just a wildly guess. Can anyone from ESRI clarify? How can the developers use this new cache property?