JordanBaumgardner_GIS

Extent and map rotation

Discussion created by JordanBaumgardner_GIS on Feb 8, 2018

I learned something late last night that I thought some might find helpful. My client really liked the Attribute Table view widget I created for them, they just wanted one more thing. Filter by Extent. No problem I said at 4:00 pm, done that several times, 30 min tops. I code it up and all looks good until I notice that things on the screen are not on my list and things that are not on my screen are. 2 hours later I think to place a graphic on the screen where the bounding box is. And it was not at all where I thought it should be.

 

The images below are two polygons, the first is the bounding box of the Views.Extent, the second is a bounding box created by using the ScreenToMap util. The first image is with roation=0, the second is with roation=120.

 

Rotation = 0

 

 

Rotation = 120

 

My Solution:

if (m.isFilterByExtentOn) {
   let xmin = 0;
   let ymin = 0;
   let xmax = $('#viewDiv').width();
   let ymax = $('#viewDiv').height() ;
   let pt1 = mainMapView.toMap(xmin,ymin);
   let pt2 = mainMapView.toMap(xmax,ymin);
   let pt3 = mainMapView.toMap(xmax,ymax);
   let pt4 = mainMapView.toMap(xmin,ymax);

   let geom = new EsriPolygon({
      hasZ: false,
      hasM: false,
      spatialReference: pt1.spatialReference,
      rings: [[[pt1.x, pt1.y], [pt2.x, pt2.y], [pt3.x, pt3.y], [pt4.x, pt4.y], [pt1.x, pt1.y]]]
   });

   query.geometry = geom;
   query.geometryType = "polygon";
   query.spatialRelationship = 'intersects';
}

Outcomes