Select to view content in your preferred language

JS API wrong latitude

619
1
07-14-2017 11:15 PM
StevHempe
Deactivated User

Hello,

I'm using the following code to display a map and to get the longitude and latitude of a point which is clicked on the map. Whenever I use this code on a stand alone, black page, everything works as expected. As soon as I surround the output <div id="map-container"></div> with my additional code, the value for longitude is always wrong. After hours of trying, to re do the code and to solve the issue somehow, I'm running out of my mind. Any idea what is going wrong?

Output of the short php code is 54.563,24.423

thank you.

<script>
function initMap(){
var map;
require([
"esri/Map",
"esri/views/MapView",
"esri/geometry/Point",
"esri/symbols/SimpleMarkerSymbol",
"esri/Graphic",
"esri/layers/GraphicsLayer",
"esri/symbols/PictureMarkerSymbol",
"dojo/domReady!",
"dojo/query",
"dojo/dom-class",
"esri/PopupTemplate"
], function(
Map, MapView, Point, SimpleMarkerSymbol, Graphic, GraphicsLayer, PictureMarkerSymbol, query, domClass, PopupTemplate
) {
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "map-container",
map: map,
zoom: 12, 
center: [<?php projectlocation($projectid); ?>] 
});
view.on("click", function(event) {
// Get the coordinates of the click on the view
var lat = event.mapPoint.latitude;
var lon = event.mapPoint.longitude;
document.getElementById("latFld").value = lat;
document.getElementById("lngFld").value = lon;
// Create a symbol for drawing the point
var markerSymbol = new PictureMarkerSymbol({
url: 'images/marker_red.png'
});
var pointGraphic = new Graphic({
geometry: event.mapPoint,
symbol: markerSymbol
});
// Add the graphics to the view's graphics layer
view.graphics.removeAll();
view.graphics.add(pointGraphic);
});
});
}

Tags (1)
0 Kudos
1 Reply
StevHempe
Deactivated User

I just found out that the issue only appears if I have to scroll the page to see the map. As long as the screen resolution is high enough to operate the map without any scrolling or if the map is on a top position (again accessible without any scrolling), everything works perfect. The more I need to scroll the page, the bigger the deviation is. It the same behavior using Chrome and Firefox.

0 Kudos