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:
ahocevar
2013-05-29 19:51:12 -06:00
parent 34becd6871
commit 77d22c4038
9 changed files with 155 additions and 37 deletions

View File

@@ -1,5 +1,6 @@
goog.provide('ol.layer.Vector');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.events.EventType');
goog.require('goog.object');
@@ -178,6 +179,13 @@ ol.layer.Vector = function(options) {
*/
this.featureCache_ = new ol.layer.FeatureCache();
/**
* @type {function(Array.<ol.Feature>):string}
* @private
*/
this.featureInfoFunction_ = goog.isDef(options.featureInfoFunction) ?
options.featureInfoFunction : ol.layer.Vector.uidFeatureInfoFunction;
/**
* TODO: this means we need to know dimension at construction
* @type {ol.geom.SharedVertices}
@@ -378,6 +386,25 @@ ol.layer.Vector.prototype.parseFeatures = function(data, parser, projection) {
};
/**
* @return {function(Array.<ol.Feature>):string} Feature info function.
*/
ol.layer.Vector.prototype.getFeatureInfoFunction = function() {
return this.featureInfoFunction_;
};
/**
* @param {Array.<ol.Feature>} features Features.
* @return {string} Feature info.
*/
ol.layer.Vector.uidFeatureInfoFunction = function(features) {
var featureIds = goog.array.map(features,
function(feature) { return goog.getUid(feature); });
return featureIds.join(', ');
};
goog.require('ol.filter.Extent');
goog.require('ol.filter.Geometry');
goog.require('ol.filter.Logical');