我是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));
}发布于 2014-02-20 07:09:27
"attr“变量不需要任何东西,因为它是可选的。在上面的示例中,我将删除"attr“,因为它没有在函数中定义或未被需要。
var graphic = new esri.Graphic(geoPoint, symbol, attr, infoTemplate);ESRI有Graphic Class的下降文档。
发布于 2015-04-23 12:31:07
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));
}https://stackoverflow.com/questions/11812757
复制相似问题