转换前:
转换后:
示例代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>webMercatorUtils</title>
<link rel="stylesheet" type="text/css"
href="https://js.arcgis.com/3.23/esri/css/esri.css"/>
<script src="https://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="https://js.arcgis.com/3.23/init.js"></script>
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script>
var map;
require(["esri/map","dojo/on",
"esri/geometry/webMercatorUtils", "dojo/domReady!"],
function (Map, on, webMercatorUtils) {
map = new Map("map", {
zoom: 10,
maxZoom: 18,
// minZoom: 8,
center: [120.243, 30.256],
// center: [120.313, 36.206],
logo: false
});
var geoqtiledUrl = "http://map.geoq.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer";
var geoqTiledLayer = new esri.layers.ArcGISTiledMapServiceLayer(geoqtiledUrl);
map.addLayer(geoqTiledLayer);
on(map, "click", function (event) {
var value = webMercatorUtils.webMercatorToGeographic(event.mapPoint);
console.log(value);
})
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
参考api文档:
https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.webmercatorutils-amd.html
另外:openlayers提供的坐标转换供参考
http://anzhihun.coding.me/ol3-primer/ch05/05-09.html
转换代码:
function mercatorTolonlat(mercator){
var lonlat={x:0,y:0};
var x = mercator.x/20037508.34*180;
var y = mercator.y/20037508.34*180;
y= 180/Math.PI*(2*Math.atan(Math.exp(y*Math.PI/180))-Math.PI/2);
lonlat.x = x;
lonlat.y = y;
return lonlat;
}