在使用iclient for openlayers过程中报错,相关代码如下:
map.once('postrender', function () {
var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
getFeatureParam = new ol.supermap.FilterParameter({
attributeFilter: attributeFilterStr
});
getFeatureBySQLParams = new ol.supermap.GetFeaturesBySQLParameters({
queryParameter: getFeatureParam,
toIndex: 500,
datasetNames: [pt_dsname]
});
getFeatureBySQLService = new ol.supermap.FeatureService(pt_url).getFeaturesBySQL(
getFeatureBySQLParams,
processCompleted,
ol.supermap.DataFormat.ISERVER
);
});
function processCompleted(getFeaturesEventArgs) {
var result = getFeaturesEventArgs.result;
// 用户数据库中查到的报警状态更新对应的属性值
result.features.forEach(function(f){
f.fieldValues[4] = pt_alarm_dic[f.fieldValues[3]];
})
addPointUniqueThemeLayer(result.features);
addLabelTheme(result.features);
}
function addPointUniqueThemeLayer(features){
themeSource = new ol.source.Unique("ThemeLayer", {
map: map,
themeField: "ALARM",
styleGroups: [
{
value: 0,
style: {
fillColor: "#00B050"
}
},
{
value: 1,
style: {
fillColor: "#FFF200"
}
},
{
value: 2,
style: {
fillColor: "#F1BD1D"
}
},
{
value: 3,
style: {
fillColor: "#FF0000"
}
}
]
});
themeSource.addFeatures(features);
themeLayer = new ol.layer.Image({
source: themeSource
});
map.addLayer(themeLayer);
}
function addLabelTheme(features)
{
themeSource = new ol.source.Label("labelThemeLayer", {
map: map,
style: new ol.supermap.ThemeStyle({
labelRect: true,
fontColor: "#000000",
fontWeight: "bolder",
fontSize: "18px",
fill: true,
fillColor: "#FFFFFF",
fillOpacity: 1,
stroke: false,
strokeColor: "#8B7B8B"
}),
themeField: "PTNO"
});
themeSource.addFeatures(features); //features已经正常获取,这一句报错
themeLayer = new ol.layer.Image({
source: themeSource
});
map.addLayer(themeLayer);
}
报错信息如下:
iclient-ol-es6.min.js:1663 Uncaught TypeError: t.getCentroid is not a function
at Sd.getLabelPxLocation (iclient-ol-es6.min.js:1663:4702)
at Sd.getDrawnLabels (iclient-ol-es6.min.js:1663:1757)
at Sd.redrawThematicFeatures (iclient-ol-es6.min.js:1663:1274)
at Sd.r (iclient-ol-es6.min.js:1627:330)
at n.getImageInternal (ImageCanvas.js:128:48)
at n.getImage (Image.js:186:19)
at n.prepareFrame (ImageLayer.js:89:35)
at n.render (Layer.js:280:23)
at n.renderFrame (Composite.js:125:29)
at n.Wi (PluggableMap.js:1550:7)