Compare commits

...

2 Commits

Author SHA1 Message Date
Willem Dantuma
79f45631a0 Fix Set style Geometry
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
2020-02-13 16:14:18 +01:00
Willem Dantuma
6060a8b86a Use a Style or a Style function as parameter to setStyle action 2020-02-13 16:01:05 +01:00
3 changed files with 15 additions and 10 deletions

View File

@ -207,7 +207,7 @@ export class DoQuery implements Action {
export class SetStyle implements Action { export class SetStyle implements Action {
readonly type = SETSTYLE; readonly type = SETSTYLE;
constructor(public itemType:string,public style:Style) { } constructor(public itemType:string,public style: Style | (Feature)) { }
} }
export type Actions = SetMapState export type Actions = SetMapState

View File

@ -120,8 +120,17 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
key = 'file'; key = 'file';
} }
} }
var styleEntry = this.stylesCache[key]; let evaluatedStyle =null;
return styleEntry; var styleEntry = this.stylesCache[key];
if(typeof styleEntry === 'function') {
evaluatedStyle = styleEntry(feature);
} else {
evaluatedStyle = styleEntry;
}
if(evaluatedStyle.geometry_ == null) {
evaluatedStyle.setGeometry((feature) => this.geometry(feature));
}
return evaluatedStyle;
}); });
} }
@ -155,11 +164,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
let styles = changes["styles"].currentValue; let styles = changes["styles"].currentValue;
for (const key in styles) { for (const key in styles) {
if (styles.hasOwnProperty(key)) { if (styles.hasOwnProperty(key)) {
let style = styles[key]; this.stylesCache[key]=styles[key];
if(style.geometry_ == null) {
style.setGeometry((feature) => this.geometry(feature));
}
this.stylesCache[key]=style;
} }
} }
} }

View File

@ -1,5 +1,5 @@
import {Style} from 'ol'; import {Style,Feature} from 'ol';
export interface IStyles{ export interface IStyles{
[id: string]: Style; [id: string]: Style | (Feature);
}; };