|
|
@@ -4,8 +4,10 @@ import {Geometry} from 'ol/geom';
|
|
|
import {Injectable} from '@angular/core';
|
|
|
import {Vector as VectorLayer} from 'ol/layer';
|
|
|
import {Vector as VectorSource} from 'ol/source';
|
|
|
+import SLDParser from 'geostyler-sld-parser';
|
|
|
+import { StyleFunction } from 'ol/style/Style';
|
|
|
|
|
|
-import {HsAddDataService} from 'hslayers-ng';
|
|
|
+import { HsAddDataService, HsLayerManagerService, HsStylerService, HsLayerExt } from 'hslayers-ng';
|
|
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
|
export class ZonesService {
|
|
|
@@ -93,8 +95,13 @@ export class ZonesService {
|
|
|
this.QUANTILE_COLORS_9,
|
|
|
this.QUANTILE_COLORS_10,
|
|
|
] as const;
|
|
|
+ sldParser: SLDParser;
|
|
|
+
|
|
|
+ constructor(
|
|
|
+ private hsLayerManagerService: HsLayerManagerService,
|
|
|
+ private hsAddDataService: HsAddDataService,
|
|
|
+ private hsStylerService: HsStylerService) {
|
|
|
|
|
|
- constructor(private hsAddDataService: HsAddDataService) {
|
|
|
this.zonesStyle = (feature) =>
|
|
|
new Style({
|
|
|
fill: new Fill({
|
|
|
@@ -102,33 +109,72 @@ export class ZonesService {
|
|
|
}),
|
|
|
stroke: new Stroke(),
|
|
|
});
|
|
|
+
|
|
|
+ this.sldParser = new SLDParser();
|
|
|
}
|
|
|
|
|
|
- updateZones(zones, {quantileCount}): void {
|
|
|
- if (!this.zonesLayer) {
|
|
|
- this.zonesSource = new VectorSource();
|
|
|
- this.zonesLayer = new VectorLayer({
|
|
|
- properties: {
|
|
|
- title: 'Zones',
|
|
|
- path: 'Results',
|
|
|
- popUp: {
|
|
|
- attributes: ['quantile'],
|
|
|
- },
|
|
|
- },
|
|
|
- style: this.zonesStyle,
|
|
|
- source: this.zonesSource,
|
|
|
- });
|
|
|
- this.hsAddDataService.addLayer(this.zonesLayer);
|
|
|
+ async updateZones(zones, {quantileCount}): Promise<void> {
|
|
|
+ if (this.zonesLayer) {
|
|
|
+ this.hsLayerManagerService.map.removeLayer(this.zonesLayer);
|
|
|
}
|
|
|
+
|
|
|
+ this.zonesSource = new VectorSource();
|
|
|
+ this.zonesLayer = new VectorLayer({
|
|
|
+ properties: {
|
|
|
+ title: 'Zones',
|
|
|
+ path: 'Results',
|
|
|
+ popUp: {
|
|
|
+ attributes: ['quantile'],
|
|
|
+ },
|
|
|
+ },
|
|
|
+ //style: this.zonesStyle,
|
|
|
+ source: this.zonesSource,
|
|
|
+ });
|
|
|
+ this.hsAddDataService.addLayer(this.zonesLayer);
|
|
|
+
|
|
|
this.zonesSource.clear();
|
|
|
this.updateZonesStyle(quantileCount);
|
|
|
- this.zonesLayer.setStyle(this.zonesStyle);
|
|
|
+
|
|
|
+ let zonesStyleObj = { name: 'Zones', rules: [] };
|
|
|
+ zonesStyleObj.rules = this.getSymbolizerRules(quantileCount);
|
|
|
+ const { output: sld } = await this.sldParser.writeStyle(zonesStyleObj);
|
|
|
+
|
|
|
+ this.zonesLayer.set("sld", sld);
|
|
|
+ //let style: Style | Style[] | StyleFunction = await this.hsStylerService.geoStylerStyleToOlStyle(zonesStyleObj);
|
|
|
+ //this.zonesLayer.setStyle(style);
|
|
|
this.zonesSource.addFeatures(
|
|
|
new GeoJSON().readFeatures(zones, {
|
|
|
dataProjection: 'EPSG:4326',
|
|
|
featureProjection: 'EPSG:5514',
|
|
|
})
|
|
|
);
|
|
|
+ this.hsStylerService.save();
|
|
|
+ this.updateZonesStyle(quantileCount);
|
|
|
+ }
|
|
|
+
|
|
|
+ private getSymbolizerRules(classes: number): Array<any> {
|
|
|
+ const colorRamp = this.QUANTILE_COLORS_MATRIX[classes - 2];
|
|
|
+ let rules = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < colorRamp.length; i++) {
|
|
|
+ let ruleIdx = (i + 1).toString();
|
|
|
+
|
|
|
+ rules[i] = {
|
|
|
+ name: ruleIdx,
|
|
|
+ filter: ["==", "quantile", ruleIdx],
|
|
|
+ symbolizers: [
|
|
|
+ {
|
|
|
+ kind: "Fill",
|
|
|
+ color: colorRamp[i],
|
|
|
+ opacity: 0.5,
|
|
|
+ outlineColor: "#505050",
|
|
|
+ outlineWidth: 1
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return rules;
|
|
|
}
|
|
|
|
|
|
private updateZonesStyle(classes: number) {
|