Skip to content

Commit

Permalink
Merge pull request #20 from infra-geo-ouverte/master
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
drekss authored Oct 29, 2019
2 parents af80ed7 + f64d73a commit 197663e
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 54 deletions.
3 changes: 0 additions & 3 deletions demo/src/app/geo/query/query.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export class AppQueryComponent {
olproj.transform([-73.5, 47.4], 'EPSG:4326', 'EPSG:3857'),
olproj.transform([-72.4, 48.6], 'EPSG:4326', 'EPSG:3857')
]),
description: 'feature1 - description'
});

const feature2 = new olFeature({
Expand All @@ -144,7 +143,6 @@ export class AppQueryComponent {
geometry: new olPoint(
olproj.transform([-73, 46.6], 'EPSG:4326', 'EPSG:3857')
),
description: 'feature2 - description'
});

const feature3 = new olFeature({
Expand All @@ -157,7 +155,6 @@ export class AppQueryComponent {
olproj.transform([-71.2, 46.6], 'EPSG:4326', 'EPSG:3857')
]
]),
description: 'feature3 - description'
});

dataSource.ol.addFeatures([feature1, feature2, feature3]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ export interface ClusterDataSourceOptions extends FeatureDataSourceOptions {
source?: FeatureDataSource;
ol?: olSourceVector;
pathOffline?: string;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface FeatureDataSourceOptions extends DataSourceOptions {
format?: olFormatFeature;
url?: string;
pathOffline?: string;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;

ol?: olSourceVector;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export interface MVTDataSourceOptions extends DataSourceOptions {
ol?: olSourceVectorTile;
url?: string;
pathOffline?: string;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface WMSDataSourceOptions extends DataSourceOptions {
ol?: olSourceImageWMS;
refreshIntervalSec?: number;
_layerOptionsFromCapabilities?: WMSLayerOptionsFromCapabilities;
excludeAttribute?: Array<string>;
}

export interface WMSDataSourceOptionsParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export class WMSDataSource extends DataSource {
}
}

if (sourceParams && sourceParams.styles) {
sourceParams.STYLES = sourceParams.styles;
delete sourceParams.styles;
}

if (sourceParams && sourceParams.INFO_FORMAT) {
sourceParams.info_format = sourceParams.INFO_FORMAT;
}
Expand Down Expand Up @@ -166,7 +171,7 @@ export class WMSDataSource extends DataSource {

getLegend(style?: string, scale?: number): Legend[] {
let legend = super.getLegend();
if (legend.length > 0 && (!style && !scale)) {
if (legend.length > 0 && (style === undefined && !scale)) {
return legend;
}

Expand Down Expand Up @@ -197,7 +202,7 @@ export class WMSDataSource extends DataSource {
return {
url: `${baseUrl}${separator}${params.join('&')}&LAYER=${layer}`,
title: layers.length > 1 ? layer : undefined,
currentStyle: !style ? undefined : style as string
currentStyle: style === undefined ? undefined : style as string
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export interface XYZDataSourceOptions extends DataSourceOptions {
url?: string;
urls?: string[];
pathOffline?: string;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import {
ChangeDetectorRef
} from '@angular/core';
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
import { NetworkService, ConnectionState } from '@igo2/core';

import { getEntityTitle, getEntityIcon } from '@igo2/common';

import { Feature } from '../shared';
import { SearchSource } from '../../search/shared/sources/source';

@Component({
selector: 'igo-feature-details',
Expand All @@ -17,6 +19,17 @@ import { Feature } from '../shared';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class FeatureDetailsComponent {
private state: ConnectionState;

@Input()
get source(): SearchSource {
return this._source;
}
set source(value: SearchSource ) {
this._source = value;
this.cdRef.detectChanges();
}

@Input()
get feature(): Feature {
return this._feature;
Expand All @@ -25,7 +38,9 @@ export class FeatureDetailsComponent {
this._feature = value;
this.cdRef.detectChanges();
}

private _feature: Feature;
private _source: SearchSource;

/**
* @internal
Expand All @@ -43,8 +58,13 @@ export class FeatureDetailsComponent {

constructor(
private cdRef: ChangeDetectorRef,
private sanitizer: DomSanitizer
) {}
private sanitizer: DomSanitizer,
private networkService: NetworkService
) {
this.networkService.currentState().subscribe((state: ConnectionState) => {
this.state = state;
});
}

htmlSanitizer(value): SafeResourceUrl {
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
Expand All @@ -66,8 +86,8 @@ export class FeatureDetailsComponent {

filterFeatureProperties(feature) {
const allowedFieldsAndAlias = feature.meta ? feature.meta.alias : undefined;

const properties = {};

if (allowedFieldsAndAlias) {
Object.keys(allowedFieldsAndAlias).forEach(field => {
if (feature.properties[field]) {
Expand All @@ -76,7 +96,18 @@ export class FeatureDetailsComponent {
});
return properties;
} else {
return feature.properties;
if (this.state.connection && feature.meta && feature.meta.excludeAttribute) {
const excludeAttribute = feature.meta.excludeAttribute;
excludeAttribute.forEach(attribute => {
delete feature.properties[attribute];
});
} else if (!this.state.connection && feature.meta && feature.meta.excludeAttributeOffline) {
const excludeAttributeOffline = feature.meta.excludeAttributeOffline;
excludeAttributeOffline.forEach(attribute => {
delete feature.properties[attribute];
});
}
return feature.properties;
}
}
}
2 changes: 2 additions & 0 deletions packages/geo/src/lib/feature/shared/feature.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface FeatureMeta {
order?: number;
alias?: {[key: string]: string};
revision?: number;
excludeAttribute?: Array<string>;
excludeAttributeOffline?: Array<string>;
}

export interface FeatureGeometry {
Expand Down
18 changes: 16 additions & 2 deletions packages/geo/src/lib/feature/shared/feature.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as olproj from 'ol/proj';
import * as olstyle from 'ol/style';
import OlFeature from 'ol/Feature';
import OlFormatGeoJSON from 'ol/format/GeoJSON';
import OlLayer from 'ol/layer/Layer';
import { uuid } from '@igo2/utils';

import {
Expand Down Expand Up @@ -78,14 +79,19 @@ export function featureToOl(
* The output object has a reference to the feature id.
* @param olFeature OL Feature
* @param projectionIn OL feature projection
* @param olLayer OL Layer
* @param projectionOut Feature projection
* @returns Feature
*/
export function featureFromOl(
olFeature: OlFeature,
projectionIn: string,
olLayer?: OlLayer,
projectionOut = 'EPSG:4326'
): Feature {
let title;
let exclude;
let excludeOffline;
const olFormat = new OlFormatGeoJSON();

const keys = olFeature.getKeys().filter((key: string) => {
Expand All @@ -101,7 +107,13 @@ export function featureFromOl(
featureProjection: projectionIn
});

const title = olFeature.get('_title');
if (olLayer) {
title = olLayer.get('title');
exclude = olLayer.get('sourceOptions').excludeAttribute;
excludeOffline = olLayer.get('sourceOptions').excludeAttributeOffline;
} else {
title = olFeature.get('_title');
}
const mapTitle = olFeature.get('_mapTitle');
const id = olFeature.getId() ? olFeature.getId() : uuid();

Expand All @@ -113,7 +125,9 @@ export function featureFromOl(
id,
title: title ? title : mapTitle ? mapTitle : id,
mapTitle,
revision: olFeature.getRevision()
revision: olFeature.getRevision(),
excludeAttribute: exclude,
excludeAttributeOffline: excludeOffline
},
properties,
geometry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,24 @@
</mat-icon>
<h4 matLine>{{computeItemTitle(item) | async}}</h4>
</mat-list-item>
<mat-list-item *ngIf="currentStyle">
<mat-select tooltip-position="below" matTooltipShowDelay="500" [matTooltip]="'igo.geo.sourceFields.selectField' | translate"
[(ngModel)]="currentStyle" (selectionChange)="onChangeStyle()">
<mat-option *ngFor="let style of listStyles()" [value]="style.name">{{style.title}}</mat-option>
</mat-select>
</mat-list-item>
<div #legend class="igo-layer-legend" [ngClass]="{'with-title': item.title}">
<div *ngIf="currentStyle !== undefined">
<mat-form-field>
<mat-select tooltip-position="below" matTooltipShowDelay="500"
[matTooltip]="'igo.geo.layer.legend.selectStyle' | translate" [(ngModel)]="currentStyle"
(selectionChange)="onChangeStyle()">
<mat-option *ngFor="let style of styles" [value]="style.name">{{style.title}}</mat-option>
</mat-select>
</mat-form-field>
</div>
<div *ngIf="!(item.collapsed)">
<div *ngIf="item.url">
<img #renderedLegend id="{{item.title}}" (load)="onLoadImage(item.title)"
src="{{(item.url | secureImage) | async}}"
alt="{{'igo.geo.layer.loadingLegendText' | translate}}"
alt="{{'igo.geo.layer.legend.loadingLegendText' | translate}}"
>
<small *ngIf="imagesHeight[item.title]<16">
{{'igo.geo.layer.noLegendScale' | translate}}
{{'igo.geo.layer.legend.noLegendScale' | translate}}
</small>
</div>
<div
Expand All @@ -43,7 +46,7 @@ <h4 matLine>{{computeItemTitle(item) | async}}</h4>

<ng-template #noItems>
<small>
{{'igo.geo.layer.noLegendText' | translate}}
{{'igo.geo.layer.legend.noLegendText' | translate}}
</small>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ img:before {
content: ' ';
display: block;
position: absolute;
height: 16px;
width: 16px;
height: 1em;
width: 1em;
background-image: url('/assets/igo2/geo/images/loading.png');
background-repeat: no-repeat;
background-color: white;
Expand Down
52 changes: 37 additions & 15 deletions packages/geo/src/lib/layer/layer-legend/layer-legend.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Component, Input, OnInit, OnDestroy, ChangeDetectionStrategy, ViewChild

import { Subscription, BehaviorSubject, of, Observable } from 'rxjs';

import { Legend, DataSourceOptions } from '../../datasource/shared/datasources/datasource.interface';
import { Layer } from '../shared/layers';
import { Legend } from '../../datasource/shared/datasources/datasource.interface';
import { Layer, ItemStyleOptions } from '../shared/layers';
import { CapabilitiesService } from '../../datasource/shared/capabilities.service';
import { map } from 'rxjs/operators';
import { LanguageService } from '@igo2/core';

@Component({
selector: 'igo-layer-legend',
Expand All @@ -27,10 +28,15 @@ export class LayerLegendComponent implements OnInit, OnDestroy {
*/
private resolution$$: Subscription;

/**
* The available styles
*/
public styles;

/**
* The style used to make the legend
*/
public currentStyle = '';
public currentStyle;

/**
* The scale used to make the legend
Expand All @@ -52,29 +58,38 @@ export class LayerLegendComponent implements OnInit, OnDestroy {
*/
@Input() layer: Layer;

constructor(private capabilitiesService: CapabilitiesService) {}
constructor(
private capabilitiesService: CapabilitiesService,
private languageService: LanguageService) {}

/**
* On init, subscribe to the map's resolution and update the legend accordingly
*/
ngOnInit() {
let lastlLegend = this.layer.legend;
const listStyles = this.listStyles();

if (!this.layer.legend) {
if (listStyles && listStyles.length > 1) {
this.currentStyle = this.layer.options.legendOptions.stylesAvailable[0].name;
this.styles = this.listStyles();
const sourceOptions = this.layer.options.source.options as any;
if (
sourceOptions &&
sourceOptions.params &&
sourceOptions.params.STYLES) {
// if a styles is provided into the layers wms params
this.currentStyle = this.styles.find(style => style.name === sourceOptions.params.STYLES).name;
} else if (!this.layer.legend) {
// if no legend is manually provided
if (this.styles && this.styles.length > 1) {
this.currentStyle = this.styles[0].name;
}
lastlLegend = this.layer.dataSource.getLegend(this.currentStyle, this.scale);
} else if (listStyles && listStyles.length > 1) {
this.currentStyle = lastlLegend[0].currentStyle;
} else if (this.styles && this.styles.length > 1) {
this.currentStyle = lastlLegend[0].currentStyle;
}

lastlLegend = this.layer.dataSource.getLegend(this.currentStyle, this.scale);
if (this.updateLegendOnResolutionChange === true) {
const resolution$ = this.layer.map.viewController.resolution$;
this.resolution$$ = resolution$.subscribe((resolution: number) => this.onResolutionChange(resolution));
} else if (lastlLegend.length !== 0) {
this.legendItems$.next(lastlLegend);
this.legendItems$.next(lastlLegend);
}
}

Expand Down Expand Up @@ -140,10 +155,17 @@ export class LayerLegendComponent implements OnInit, OnDestroy {
this.legendItems$.next(legendItems);
}

listStyles() {
private listStyles() {
const layerOptions = this.layer.options;
if (layerOptions && layerOptions.legendOptions) {
return layerOptions.legendOptions.stylesAvailable;
const translate = this.languageService.translate;
const title = translate.instant('igo.geo.layer.legend.default');
const stylesAvailable = [{ name: '', title } as ItemStyleOptions]
.concat(layerOptions.legendOptions.stylesAvailable.filter(sA => (
sA.name.normalize('NFD').replace(/[\u0300-\u036f]/gi, '') !== 'default' &&
sA.name.normalize('NFD').replace(/[\u0300-\u036f]/gi, '') !== 'defaut')));
stylesAvailable.map(s => s.title = s.title.charAt(0).toUpperCase() + s.title.slice(1).replace(/_/g, ' '));
return stylesAvailable;
}
return ;
}
Expand Down
Loading

0 comments on commit 197663e

Please sign in to comment.