getFeatures method and featureInfo templates
To avoid surprises for application developers, this change creates a new getFeatures method. So it is clear now beforehand whether features or feature info markup is returned. The result is now also grouped by layer, so application developers always have a link between a layer and the feature info it returns. To make getFeatureInfo return markup for vector layers, this change also adds a featureInfoFunction property to the vector layer, which gives developers full control over how features are rendered to feature info markup.
This commit is contained in:
@@ -28,7 +28,11 @@ var vector = new ol.layer.Vector({
|
||||
})
|
||||
]
|
||||
})
|
||||
]})
|
||||
]}),
|
||||
featureInfoFunction: function(features) {
|
||||
return features.length > 0 ?
|
||||
features[0].getFeatureId() + ': ' + features[0].get('name') : ' ';
|
||||
}
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
@@ -45,12 +49,8 @@ map.on(['click', 'mousemove'], function(evt) {
|
||||
map.getFeatureInfo({
|
||||
pixel: evt.getPixel(),
|
||||
layers: [vector],
|
||||
success: function(features) {
|
||||
var info = [];
|
||||
for (var i = 0, ii = features.length; i < ii; ++i) {
|
||||
info.push(features[i].getFeatureId() + ': ' + features[i].get('name'));
|
||||
}
|
||||
document.getElementById('info').innerHTML = info.join(', ') || ' ';
|
||||
success: function(featureInfo) {
|
||||
document.getElementById('info').innerHTML = featureInfo[0];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user