Select to view content in your preferred language

No Coordinates

2416
10
Jump to solution
07-14-2017 01:09 AM
AhmadLibda
Occasional Contributor

I learned that The spatial reference for a map is defined either by the extent passed to the map constructor or by the first layer added to the map.

coordinate system - Set custom spatial reference to base map in arcgis javascript api - Geographic I... 

I am new to GIS. So this is my code:

   var govs= new TileLayer({
        url: "http://localhost:6080/arcgis/rest/services/services/MapServer",
        visible: false
    });
    var map = new Map({ });
 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: 1,  // Sets zoom level based on level of detail (LOD)
        center: [86999,99999]  // Sets center point of view using longitude,latitude
    });
    map.layers.add(govs);

I get a "Null" for both mapPoint.latitude and longitude when i print them in a popup using the code:

view.on("click", function (event) {
        event.stopPropagation(); // overwrite default click-for-popup behavior
        // Get the coordinates of the click on the view
        var lat = Math.round(event.mapPoint.latitude *1000 )/1000 ;
        var lon = Math.round(event.mapPoint.longitude * 1000) / 1000;
        view.popup.open({
            // Set the popup's title to the coordinates of the location
            title: "Reverse geocode: [" + lon + ", " + lat + "]",
            location: event.mapPoint // Set the location of the popup to the clicked location
        });
        view.popup.content =  "Hello,, ";
    });

Also, altering "center" in view constructor doesn't seem to affect the starting center point of the map. However, "zoom" works.

I also tried to define "spatial reference" within the view (but no use):

 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: 1,  // Sets zoom level based on level of detail (LOD)
        center: [86999,99999] , // Sets center point of view using longitude,latitude
extent: { // autocasts as new Extent()
            xmin: 75639.85130000021,
            ymin: 70262.05010000058,
            xmax: 108900.84379999992,
            ymax: 111618.54690000042,
            spatialReference: 28191
        } 

   });  

0 Kudos
10 Replies
HemingZhu
Frequent Contributor

You first statement is collect. so if you put your TileLayer in Map constructor, then you will have your mapview's spatialreference same as you tilelayer: 

  var gov= new TileLayer({
        url: "http://localhost:6080/arcgis/rest/services/services/MapServer",
        visible: false
    });
    var map = new Map({

      layers:[gov]

});

Zoom and center is only work when your use esri basemap (102100). Extent will work when you don't use esri basemap.

similarly event.mapPoint.latitude is only work when you mapview spatial reference is 102100 or 3857. but you can always use event.mapPoint.x to get the cordinates in map unit that you are using.