gpt4 book ai didi

javascript - 如何使用 ArcGIS JavaScript API 直接绘制点和文本

转载 作者:行者123 更新时间:2023-11-29 16:18:34 25 4
gpt4 key购买 nike

我是 ArcGIS 新手。

我想直接在 map 上画一些点和一些文字。

类似下面的内容。但它只显示 map ,什么也没画。

谁能帮我解决这个问题?

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Draw point and text</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.1/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis?v=3.1"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.layers.agsdynamic");
var map;
var layer;
var mapUrl;
var defaultSymbol;
function Init()
{
map = new esri.Map("mapDiv");
mapUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer";
//mapUrl = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer";
layer = new esri.layers.ArcGISDynamicMapServiceLayer(mapUrl);
map.addLayer(layer);
defaultSymbol = new esri.symbol.SimpleMarkerSymbol(); // point
defaultSymbol.setColor(new dojo.Color([255, 0, 0]));

addPoint(10, 10);
addText(10, 20, "Text");
}
function addPoint(x, y)
{
var pt = new esri.geometry.Point(x, y, map.spatialReference);
var graphic = new esri.Graphic(pt, defaultSymbol);
map.graphics.add(graphic);
}
function addText(x, y, text)
{
var pt = new esri.geometry.Point(x, y, map.spatialReference);

//Create font
var font = new esri.symbol.Font();
font.setSize(18);
font.setWeight(esri.symbol.Font[WEIGHT_NORMAL]);

//Create the TextSymbol
var textSymbol = new esri.symbol.TextSymbol();
textSymbol.setText(text);
textSymbol.setColor(new dojo.Color([0, 255, 0]));
textSymbol.setFont(font);
textSymbol.setKerning(true);
var graphic = new esri.Graphic(pt, textSymbol);
map.graphics.add(graphic);
}

dojo.addOnLoad(Init);
</script>
</head>
<body class="tundra">
<div id="mapDiv" style="width:900px; height:600px; border:1px solid #000;"></div>
</body>
</html>

最佳答案

使用Tiled Map作为 basemap ,然后添加Dynamic Map图层,修改addPoint函数:注意:wkid 取决于您的 map 空间。

function addPoint(x, y)
{
var point = new esri.geometry.Point(x, y, new esri.SpatialReference({ wkid: 102113 }));
var mp = esri.geometry.geographicToWebMercator(point);
point = new esri.geometry.Point({ "x": mp.x, "y": mp.y, "spatialReference": { "wkid": 102113} });
var graphic = new esri.Graphic(point, defaultSymbol);
map.graphics.add(graphic);
}

关于javascript - 如何使用 ArcGIS JavaScript API 直接绘制点和文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12972749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com