Skip to content

Commit

Permalink
Allow default values for features properties in ngeo.format.FeatureHash
Browse files Browse the repository at this point in the history
  • Loading branch information
fredj committed Jul 27, 2018
1 parent f43908e commit 77aa1a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contribs/gmf/src/services/permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ gmf.module.value('gmfPermalinkOptions',
* @param {angular.Scope} $rootScope Angular rootScope.
* @param {angular.$injector} $injector Main injector.
* @param {ngeo.Debounce} ngeoDebounce ngeo Debounce service.
* @param {angularGettext.Catalog} gettextCatalog Gettext service.
* @param {ngeo.StateManager} ngeoStateManager The ngeo StateManager service.
* @param {ngeo.Location} ngeoLocation ngeo location service.
* @ngInject
* @ngdoc service
* @ngname gmfPermalink
*/
gmf.Permalink = function($timeout, $rootScope, $injector, ngeoDebounce,
gmf.Permalink = function($timeout, $rootScope, $injector, ngeoDebounce, gettextCatalog,
ngeoStateManager, ngeoLocation) {

/**
Expand Down Expand Up @@ -335,6 +336,12 @@ gmf.Permalink = function($timeout, $rootScope, $injector, ngeoDebounce,
'showMeasure': ngeo.FeatureProperties.SHOW_MEASURE,
'strokeColor': ngeo.FeatureProperties.COLOR,
'strokeWidth': ngeo.FeatureProperties.STROKE
},
defaultValues: {
'name': feature => gettextCatalog.getString(feature.getGeometry().getType()),
'fillOpacity': () => 0.5,
'showLabel': () => false,
'showMeasure': () => false
}
});

Expand Down
16 changes: 16 additions & 0 deletions src/ol-ext/format/featurehash.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ ngeo.format.FeatureHash = function(opt_options) {
*/
ngeo.format.FeatureHashLegacyProperties_ = (options.propertiesType !== undefined) && options.propertiesType;

/**
* @type {Object.<string, *>}
* @private
*/
this.defaultValues_ = options.defaultValues !== undefined ? options.defaultValues : {};

};
ol.inherits(ngeo.format.FeatureHash, ol.format.TextFeature);

Expand Down Expand Up @@ -1091,6 +1097,16 @@ ngeo.format.FeatureHash.prototype.readFeaturesFromText = function(text, opt_opti
features.push(feature);
text = text.substring(index + 1);
}

// set default values
features.forEach((feature) => {
for (const key in this.defaultValues_) {
const property = ngeo.format.FeatureHashLegacyProperties_[key];
if (feature.get(property) === undefined) {
feature.set(property, this.defaultValues_[key].call(null, feature));
}
}
});
return features;
};

Expand Down

0 comments on commit 77aa1a2

Please sign in to comment.