我正在使用gwt-openlayers-1.0
,目前正在学习此示例(动画集群策略)。
在我的项目中,每个对象VectoreFeature
都有一个数字标签,我想显示每个聚类点上基础点的标签值的总和。有没有办法做到这一点?
upd:
根据JS中的这篇文章(“最重要的”策略部分),它看起来像这样:
// for each feature:
feature.attributes = { result_count: 10 };
...
var style = new OpenLayers.Style({
...
} , context: {
label: function(feature) {
if (feature.cluster) {
var result_count = 0;
for (var i = 0; i < feature.cluster.length; i++) {
result_count += feature.cluster[i].attributes.result_count;
}
features.attributes.label = result_count.toString();
} else {
features.attributes.label = features.attributes.result_count.toString();
}
}
}
但是我找不到在gwt-openlayers中实现此方法的方法:
org.gwtopenmaps.openlayers.client.Style style = new org.gwtopenmaps.openlayers.client.Style();
style.setLabel( ??? );
在将策略分配给VectorLayer的方法中:
{
org.gwtopenmaps.openlayers.client.Style style = new org.gwtopenmaps.openlayers.client.Style();
style.setJSObject(getOpenLayersStyle());
}
魔术在哪里完成:
private native JSObject getOpenLayersStyle() /*-{
var style = new $wnd.OpenLayers.Style({
fontColor: "#FFFFFF",
fontSize: "12px",
label: "${countLabel}"
}, { context: {
countLabel: function(feature) {
var countLabel;
if (feature.cluster) {
var result_count = 0;
for (var i = 0; i < feature.cluster.length; i++) {
result_count += feature.cluster[i].attributes.result_count;
}
countLabel = result_count.toString();
} else {
countLabel = feature.attributes.result_count.toString();
}
feature.attributes.label = countLabel;
return countLabel;
}
}
});
return style;
}-*/;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句