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 Information Systems S…
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
}
});