Skip to content

Commit

Permalink
fix(styler): File style load
Browse files Browse the repository at this point in the history
Prioritise style type when loading from file
  • Loading branch information
FilipLeitner authored and jmacura committed Jul 18, 2024
1 parent 987d19a commit e98b28b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions projects/hslayers/services/styler/styler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,13 @@ export class HsStylerService {
/**
* Prepare current layers style for editing by converting
* SLD attribute string to JSON and reading layers title
* @param styleWithPriority Used to prioritize certain style type. For example when
* loading style from a file
*/
async fill(layer: VectorLayer<Feature>): Promise<void> {
async fill(
layer: VectorLayer<Feature>,
styleWithPriority?: 'sld' | 'qml',
): Promise<void> {
const blankStyleObj = {name: 'untitled style', rules: []};
try {
if (!layer) {
Expand All @@ -358,7 +363,10 @@ export class HsStylerService {
this.layerTitle = getTitle(layer);
const {sld, qml} = this.unsavedChange
? this.changesStore.get(getUid(layer))
: {sld: getSld(layer), qml: getQml(layer)};
: {
sld: styleWithPriority === 'qml' ? undefined : getSld(layer),
qml: styleWithPriority === 'sld' ? undefined : getQml(layer),
};
if (sld != undefined) {
this.styleObject = await this.sldToJson(sld);
this.sldVersion = this.guessSldVersion(sld);
Expand Down Expand Up @@ -749,10 +757,10 @@ export class HsStylerService {
const qmlParser = new QGISStyleParser();

await qmlParser.readStyle(styleString);
this.qml = styleString;
this.qml = styleString.replace(/base64:/g, 'data:image/png;base64,');
}
this.resolveSldChange();
this.fill(this.layer);
this.fill(this.layer, styleFmt);
} catch (err) {
this.hsLogService.warn('SLD could not be parsed', err);
}
Expand Down

0 comments on commit e98b28b

Please sign in to comment.