Skip to content

Commit

Permalink
Merge pull request #4071 from camptocamp/merge23b
Browse files Browse the repository at this point in the history
 Merge remote-tracking branch 'origin/2.2' into 2.3
  • Loading branch information
sbrunner committed Jul 30, 2018
2 parents 086773b + 8c9e5ed commit 5057f98
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contribs/gmf/src/layertree/TreeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ exports.prototype.notifyCantAddGroups_ = function(groups) {
const names = [];
const gettextCatalog = this.gettextCatalog_;
groups.forEach((group) => {
names.push(group.name);
names.push(gettextCatalog.getString(group.name));
});
const msg = (names.length < 2) ?
gettextCatalog.getString('group is already loaded.') :
Expand Down
9 changes: 8 additions & 1 deletion contribs/gmf/src/permalink/Permalink.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ import olLayerGroup from 'ol/layer/Group.js';
* @param {angular.Scope} $rootScope Angular rootScope.
* @param {angular.$injector} $injector Main injector.
* @param {ngeox.miscDebounce} ngeoDebounce ngeo Debounce factory.
* @param {angularGettext.Catalog} gettextCatalog Gettext service.
* @param {ngeo.misc.EventHelper} ngeoEventHelper Ngeo event helper service
* @param {ngeo.statemanager.Service} ngeoStateManager The ngeo statemanager service.
* @param {ngeo.statemanager.Location} ngeoLocation ngeo location service.
* @ngInject
* @ngdoc service
* @ngname gmfPermalink
*/
const exports = function($q, $timeout, $rootScope, $injector, ngeoDebounce, ngeoEventHelper,
const exports = function($q, $timeout, $rootScope, $injector, ngeoDebounce, gettextCatalog, ngeoEventHelper,
ngeoStateManager, ngeoLocation) {

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

Expand Down
20 changes: 13 additions & 7 deletions contribs/gmf/src/search/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,19 @@ exports.SearchController_ = class {
if (fillStyle) {
fillStyle.setColor(fillColor);
}
const image = style.getImage();
if (image) {
style.setImage(new olStyleCircle({
fill: new olStyleFill({color: fillColor}),
radius: 5,
stroke: new olStyleStroke({color: strokeColor})
}));
// the image style can't be changed in place, the colors are updated on a clone.
let imageStyle = style.getImage();
if (imageStyle) {
imageStyle = imageStyle.clone();
const imageStrokeStyle = imageStyle.getStroke();
if (imageStrokeStyle) {
imageStrokeStyle.setColor(strokeColor);
}
const imageFillStyle = imageStyle.getFill();
if (imageFillStyle) {
imageFillStyle.setColor(fillColor);
}
style.setImage(imageStyle);
}
}
return style;
Expand Down
6 changes: 6 additions & 0 deletions options/ngeox.js
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ ngeox.format = {};
/**
* @typedef {{
* accuracy: (number|undefined),
* defaultValues: (Object.<string, function(ol.Feature)>|undefined),
* encodeStyles: (boolean|undefined),
* properties: (function(ol.Feature): Object.<string, (string|undefined)>|undefined),
* setStyle: (boolean|undefined)
Expand All @@ -1535,6 +1536,11 @@ ngeox.format.FeatureHashOptions;
*/
ngeox.format.FeatureHashOptions.prototype.accuracy;

/**
* @type {Object.<string, function(ol.Feature)>|undefined}
*/
ngeox.format.FeatureHashOptions.prototype.defaultValues;


/**
* Encode styles. Optional. Default is `true`.
Expand Down
24 changes: 20 additions & 4 deletions src/format/FeatureHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ const exports = function(opt_options) {
*/
exports.LegacyProperties_ = (options.propertiesType !== undefined) && options.propertiesType;

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

};

olBase.inherits(exports, olFormatTextFeature);
Expand Down Expand Up @@ -1061,6 +1067,8 @@ exports.prototype.readFeatureFromText = function(text, opt_options) {
*/
exports.prototype.readFeaturesFromText = function(text, opt_options) {
googAsserts.assert(text[0] === 'F');
this.prevX_ = 0;
this.prevY_ = 0;
/** @type {Array.<ol.Feature>} */
const features = [];
text = text.substring(1);
Expand All @@ -1072,6 +1080,16 @@ exports.prototype.readFeaturesFromText = function(text, opt_options) {
features.push(feature);
text = text.substring(index + 1);
}

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

Expand All @@ -1087,8 +1105,6 @@ exports.prototype.readFeaturesFromText = function(text, opt_options) {
exports.prototype.readGeometryFromText = function(text, opt_options) {
const geometryReader = exports.GEOMETRY_READERS_[text[0]];
googAsserts.assert(geometryReader !== undefined);
this.prevX_ = 0;
this.prevY_ = 0;
return geometryReader.call(this, text);
};

Expand Down Expand Up @@ -1176,6 +1192,8 @@ exports.prototype.writeFeatureText = function(feature, opt_options) {
* @override
*/
exports.prototype.writeFeaturesText = function(features, opt_options) {
this.prevX_ = 0;
this.prevY_ = 0;
const textArray = [];
if (features.length > 0) {
textArray.push('F');
Expand All @@ -1201,8 +1219,6 @@ exports.prototype.writeGeometryText = function(geometry, opt_options) {
googAsserts.assert(geometryWriter !== undefined);
const transformedGeometry = /** @type {ol.geom.Geometry} */
(olFormatFeature.transformWithOptions(geometry, true, opt_options));
this.prevX_ = 0;
this.prevY_ = 0;
return geometryWriter.call(this, transformedGeometry);
};

Expand Down
4 changes: 2 additions & 2 deletions test/spec/ol-ext/format/featurehash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('ngeo.format.FeatureHash', () => {
describe('features decoding', () => {

it('correctly decodes features', () => {
const features = fhFormat.readFeatures('Fp(__)l(..__)');
const features = fhFormat.readFeatures('Fp(__)l(--__)');
expect(features.length).toBe(2);
let feature, geometry, coordinates;
feature = features[0];
Expand Down Expand Up @@ -445,7 +445,7 @@ describe('ngeo.format.FeatureHash', () => {
});
const features = [pointFeature, lineStringFeature];
const result = fhFormat.writeFeatures(features);
expect(result).toBe('Fp(__~foo*foo\'bar*bar)l(..__~foo*foo\'bar*bar)');
expect(result).toBe('Fp(__~foo*foo\'bar*bar)l(--__~foo*foo\'bar*bar)');
});
});

Expand Down

0 comments on commit 5057f98

Please sign in to comment.