理解ESRI API时出现问题

Trouble Understanding the ESRI API

本文关键字:问题 ESRI API 理解      更新时间:2023-09-26

我是ESRI Javascript API的新手。我不明白在有新图形的线上需要做什么。

var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate); 

这是我连接在一起的许多示例代码中的最后一个。有人能提出一个解决方案吗。谢谢你的帮助。下面是整个功能。如果你需要完整的剧本,请告诉我。

function onGeocodesuccess(results)
{
console.log(results);
    var geoPoint = new esri.geometry.Point(results.utm_x, results.utm_y, map.spatialReference);
    var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 15, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255]), 2), new dojo.Color([0,0,255]));
    var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
    var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate);
    map.graphics.add(graphic);
    map.infoWindow.setTitle(graphic.getTitle());
    map.infoWindow.setContent(graphic.getContent());
    var screenPnt = map.toScreen(geoPoint);
    map.infoWindow.show(screenPnt,map.getInfoWindowAnchor(screenPnt));

}

"attr"变量不需要任何东西,因为它是可选的。在上面的例子中,我会删除"attr",因为它没有在函数中定义或需要。

var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate);

ESRI有图形类的下降文档。

attr是一个具有字段键、字段名和字段值的对象,它通常由服务器返回的特性填充。当你创建一个新的图形时,这是一个可选参数,如前所述,你可以在创建新图形时去掉这个参数,在你的情况下,这将是:

function onGeocodesuccess(results) {
console.log(results);
var geoPoint = new esri.geometry.Point(results.utm_x, results.utm_y, map.spatialReference);
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 15, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,255]), 2), new dojo.Color([0,0,255]));
var infoTemplate = new esri.InfoTemplate("Attributes", "${*}");
var graphic = new esri.Graphic(geoPoint, symbol);
map.graphics.add(graphic);
map.infoWindow.setTitle(graphic.getTitle());
map.infoWindow.setContent(graphic.getContent());
var screenPnt = map.toScreen(geoPoint);
map.infoWindow.show(screenPnt,map.getInfoWindowAnchor(screenPnt));
}