我是ESRI ArcGIS API for Java的新手,我试图以编程方式生成要素层,然后向其添加标签层。要素层似乎正常工作,但标签层未提供任何输出(也没有错误)。有人可以告诉我我在做什么错吗?
jsfiddle:http://jsfiddle.net/9X46z/
相关的javascript:
var layerDefinition = {
"geometryType": "esriGeometryPoint",
"fields": [
{
"name": "__OBJECTID",
"alias": "__OBJECTID",
"type": "esriFieldTypeOID",
}, {
"name": "testfield",
"alias": "testfield",
"type": "esriFieldTypeString"
}
]
}
var featureCollection = {
layerDefinition: layerDefinition,
featureSet: null
};
var fl = new FeatureLayer(featureCollection, {
id: "featurelayer",
outFields: ["testfield"]
})
var m = new esri.Graphic(new esri.geometry.Point(-77, 40), pushpin);
m.attributes = {
"testfield": "test value"
};
fl.add(m);
map.addLayer(fl);
// create a text symbol to define the style of labels
var testLabel = new TextSymbol().setColor(new Color("#666666"));
testLabel.font.setSize("14pt");
testLabel.font.setFamily("arial");
testLabelRenderer = new SimpleRenderer(testLabel);
var labels = new LabelLayer({
id: "labels"
});
labels.addFeatureLayer(fl, testLabelRenderer, "{testfield}");
// add the label layer to the map
map.addLayer(labels);
最佳答案
这是一个更改后的更新版本:http://jsfiddle.net/2WccC/1/
var m = new esri.Graphic(new esri.geometry.Point(-77, 40), pushpin);
至
var m = new esri.Graphic(esri.geometry.geographicToWebMercator(new esri.geometry.Point(-77, 40)), pushpin);