Allowing WrapAround180 allows map extents to go beyond the true Web Mercator extent. Once this happens I am not able to use map.extent.intersects(point). My work around was to

  1. Normalize extents in lat/long
  2. Convert point to lat/long
  3. Split extents to two parts if crossing date line.
  4. Test intersection with extent(s)

Is there an easier way?

Here's my code:

var extent = map.extent; var pointToTest = someGraphic;

     var normMin = wmUtils.xyToLngLat(extent.xmin, extent.ymin); 

     var normMax = wmUtils.xyToLngLat(extent.xmax, extent.ymax);

     //test if minx is greated than maxx
     if (normMin[0]> normMax[0]) {

      var pointMin1 = new Point([normMin[0],normMin[1]],new SR({ wkid:4326 }));
      var pointMin2 = new Point([180,normMax[1]],new SR({ wkid:4326 }));
      var wmMin1 = wmUtils.geographicToWebMercator(pointMin1);
      var wmMin2 = wmUtils.geographicToWebMercator(pointMin2);

      var pointMax1 = new Point([-180,normMin[1]],new SR({ wkid:4326 }));
      var pointMax2 = new Point([normMax[0],normMax[1]],new SR({ wkid:4326 }));
      var wmMax1= wmUtils.geographicToWebMercator(pointMax1);
      var wmMax2= wmUtils.geographicToWebMercator(pointMax2);

      var normExtent1 = new Extent(wmMin1.x,wmMin1.y,wmMin2.x,wmMin2.y, new SR({ wkid:102100 }));
      var normExtent2 = new Extent(wmMax1.x,wmMax1.y,wmMax2.x,wmMax2.y, new SR({ wkid:102100 }));

    } else {

     var pointMin = new Point(normMin,new SR({ wkid:4326 }));
     var wmMin = wmUtils.geographicToWebMercator(pointMin);
     var pointMax = new Point(normMax,new SR({ wkid:4326 }));
     var wmMax = wmUtils.geographicToWebMercator(pointMax);
     var normalizedExtent = new Extent(wmMin.x,wmMin.y,wmMax.x,wmMax.y, new SR({ wkid:102100 }));


   if (normMin[0]> normMax[0]) {
        if ((!normExtent1.intersects(pointToTest.geometry) && !normExtent2.intersects(pointToTest.geometry))) return;
      } else {            
        if (!normalizedExtent.intersects(pointToTest.geometry)) return;
  • Can you post the code you're using to do this? I'm curious to see exactly what you're doing. – Derek Swingley Oct 7 '13 at 22:38
  • Updated with code – Aamir Suleman Oct 29 '13 at 18:51

There is an internal method on Extents, _normalize, that will do this for you. For instance, when you've wrapped the map around a couple of times, and you have a point:

var p = new Point(-100, 40);

This will return false:

map.extent.intersects(p); // false

While this will work:

map.extent._normalize().intersects(p); // true
| improve this answer | |
  • That's great. Will that work when the dateline is visible? – Aamir Suleman Oct 29 '13 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.