我想在地图上画一个伦敦的十字架。 如果我在地理或web mercator中指定点的坐标,则代码可以工作。 但是,如果我在ED50 / UTM区域31N中指定坐标,则它不起作用。 根据文档,Point构造函数将空间参考作为最后一个参数。我认为这意味着该点将被转换为地图的坐标系(web mercator)?然而,这一点现在出现在法国中部的某个地方。不确定这里发生了什么?
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<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>London Map</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.17/esri/css/esri.css">
<style>
html, body, #map {
height: 100%;
margin: 0;
padding: 0;
}
</style>
<script src="https://js.arcgis.com/3.17/"></script>
<script>
var map;
require(["esri/map", "esri/geometry/Point", "esri/SpatialReference", "esri/graphic", "dojo/domReady!"], function (Map, Point, SpatialReference, Graphic) {
map = new Map("map", {
basemap: "topo", //For full list of pre-defined basemaps, navigate to http://arcg.is/1JVo6Wd
center: [0.1, 51.5], // longitude, latitude
zoom: 8
});
map.on("load", function () {
//var P = new Point({ "x": 0.1, "y": 51.5, "spatialReference": { "wkid": 4326 } }); // geographic: works!
//var P = new Point({ "x": -10978, "y": 6708911, "spatialReference": { "wkid": 102100 } }); // web mercator: works!
//var P = new Point({ "x": 284879, "y": 5711864, "spatialReference": { "wkid": 23031 } }); // somewhere in the middle of France !!??
var P = new Point([284879, 5711864], new SpatialReference({ wkid: 23031 })); // somewhere in the middle of France !!??
var pointSymbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_X, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), 2), new dojo.Color([0, 255, 0, 0.25]));
var mapPointGraphic = new Graphic(P, pointSymbol);
map.graphics.add(mapPointGraphic);
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
答案 0 :(得分:1)
ESRI JavaScript API,除了WebMercator(102100,102113,3875)和WGS84(4326)之外没有任何客户端投影API。对于这些,它使用esri/geometry/webMercatorUtils
模块来转换空间参考。对于所有其他投影系统,您需要使用GeometryService
进行投影。下面是相同的示例代码。
require(["dojo/_base/array", "esri/tasks/GeometryService", "esri/tasks/ProjectParameters", "esri/SpatialReference"], function(GeometryService, ProjectParameters, array) {
var gsvc = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
var P = new Point([284879, 5711864], new SpatialReference({ wkid: 23031 }));
var outSR = new SpatialReference({wkid:102110});
var params = new ProjectParameters();
params.geometries = [P];
params.outSR = outSR;
params.transformation = transformation;
gsvc.project(params, function(projectedGeometries){
P = projectedGeometries[0];
});
});