Select to view content in your preferred language

why the coordinates from view.toMap() are incorrect in east hemisphere?

700
1
07-17-2020 12:44 PM
YiqunChen
Emerging Contributor

Hi,

Does anyone know why the coordinates output from view.toMap are incorrect in the east hemisphere? I simplified the code to be the following. You run it and click the map anywhere and you will find that the output coordinates from cursorPoint are sometimes different from the one shown in base map (the correct one).

I actually found that X is correct sometimes if you move the map from left to right or from east to west.

If you click in Asia area and you will see that X is negative (should be positive)! Did anyone notice this before?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>Intro to MapView - Create a 2D map</title>
    <style>
      html,
      body,
      #viewDiv {
        padding0;
        margin0;
        height100%;
        width100%;
      }
    </style>
    <link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.16/"></script>
    <script>
      require(["esri/Map",
        "esri/views/MapView",
        "esri/widgets/CoordinateConversion"], 
      function(Map, 
        MapView, 
        CoordinateConversion) 
        {

        var map = new Map({
          basemap: "streets"
        });

        var view = new MapView({
          container: "viewDiv"// Reference to the scene div created in step 5
          map: map, // Reference to the map object created before the scene
          zoom: 4// Sets zoom level based on level of detail (LOD)
          center: [-11838// Sets center point of view using longitude,latitude
        });

        //*********************************************************************
        //widget of coordinate
        //*********************************************************************
        var ccWidget = new CoordinateConversion(
        {
          view: view
        });
        view.ui.add(ccWidget, "bottom-right");

        view.on("click"function(event)
        {
            var cursorPoint = view.toMap(event)
            alert('x='+cursorPoint.x+'y='+cursorPoint.y) 
        });

      });
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>
Tags (1)
0 Kudos
1 Reply
HarishPalaniappan
Regular Contributor

I believe you are looking at it wrong. they are not X and Y - but latitude, longitude. and it is normal to have negative values to one side of the line like:

Positive latitude is above the equator (N), and negative latitude is below the equator (S). Positive longitude is east of the prime meridian, while negative longitude is west of the prime meridian

More explanation of how the values run on the lattitude or longitude lines is here-> Understanding Latitude and Longitude 

0 Kudos