Skip to content

Commit d320349

Browse files
vNovskidavide-negretti
authored andcommitted
[UXP-120] openstreetmap rendering
1 parent c58eca9 commit d320349

22 files changed

Lines changed: 1710 additions & 49 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"ng2-nouislider": "^2.0.0",
144144
"ng2-pdfjs-viewer": "^15.0.0",
145145
"ngx-infinite-scroll": "^15.0.0",
146+
"ngx-openlayers": "0.8.22",
146147
"ngx-pagination": "6.0.3",
147148
"ngx-sortablejs": "^11.1.0",
148149
"ngx-ui-switch": "^14.0.3",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { Injectable } from '@angular/core';
2+
import { TranslateService } from '@ngx-translate/core';
3+
import { Observable } from 'rxjs';
4+
5+
6+
@Injectable()
7+
export class GeoLocationService {
8+
9+
constructor(
10+
protected translateService: TranslateService,
11+
) {
12+
}
13+
14+
public getLocation(geoLocationOptions?: any): Observable<any> {
15+
geoLocationOptions = geoLocationOptions || { timeout: 5000 };
16+
return Observable.create(observer => {
17+
18+
if (window.navigator && window.navigator.geolocation) {
19+
window.navigator.geolocation.getCurrentPosition(
20+
(position) => {
21+
observer.next(position);
22+
observer.complete();
23+
},
24+
(error) => {
25+
switch (error.code) {
26+
case 1:
27+
observer.error(this.translateService.get('errors.location.permissionDenied'));
28+
break;
29+
case 2:
30+
observer.error(this.translateService.get('errors.location.positionUnavailable'));
31+
break;
32+
case 3:
33+
observer.error(this.translateService.get('errors.location.timeout'));
34+
break;
35+
}
36+
},
37+
geoLocationOptions);
38+
} else {
39+
observer.error(this.translateService.get('errors.location.unsupportedBrowser'));
40+
}
41+
});
42+
}
43+
}
44+
45+
export let geolocationServiceInjectables: Array<any> = [
46+
{provide: GeoLocationService, useClass: GeoLocationService }
47+
];

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/map/map.component.html renamed to src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/gmap/gmap.component.html

File renamed without changes.

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/map/map.component.scss renamed to src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/gmap/gmap.component.scss

File renamed without changes.

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/map/map.component.spec.ts renamed to src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/gmap/gmap.component.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { LayoutField } from '../../../../../../../core/layout/models/box.model';
66
import { Item } from '../../../../../../../core/shared/item.model';
77
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
88
import { TranslateLoaderMock } from '../../../../../../../shared/mocks/translate-loader.mock';
9-
import { MapComponent } from './map.component';
9+
import { GmapComponent } from './gmap.component';
1010

11-
describe('MapComponent', () => {
12-
let component: MapComponent;
13-
let fixture: ComponentFixture<MapComponent>;
11+
describe('GmapComponent', () => {
12+
let component: GmapComponent;
13+
let fixture: ComponentFixture<GmapComponent>;
1414

1515
const metadataValue = Object.assign(new MetadataValue(), {
1616
'value': '@42.1334,56.7654',
@@ -33,7 +33,7 @@ describe('MapComponent', () => {
3333
const mockField: LayoutField = {
3434
'metadata': 'organization.address.addressLocality',
3535
'label': 'Preferred name',
36-
'rendering': 'MAP',
36+
'rendering': 'GMAP',
3737
'fieldType': 'METADATA',
3838
'style': null,
3939
'styleLabel': 'test-style-label',
@@ -56,13 +56,13 @@ describe('MapComponent', () => {
5656
{ provide: 'metadataValueProvider', useValue: metadataValue },
5757
{ provide: 'renderingSubTypeProvider', useValue: '' },
5858
],
59-
declarations: [ MapComponent ]
59+
declarations: [ GmapComponent ]
6060
})
6161
.compileComponents();
6262
});
6363

6464
beforeEach(() => {
65-
fixture = TestBed.createComponent(MapComponent);
65+
fixture = TestBed.createComponent(GmapComponent);
6666
component = fixture.componentInstance;
6767
fixture.detectChanges();
6868
});

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/map/map.component.ts renamed to src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/gmap/gmap.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { FieldRenderingType, MetadataBoxFieldRendering, } from '../metadata-box.
44
import { RenderingTypeValueModelComponent } from '../rendering-type-value.model';
55

66
@Component({
7-
selector: 'ds-map',
8-
templateUrl: './map.component.html',
9-
styleUrls: ['./map.component.scss'],
7+
selector: 'ds-gmap',
8+
templateUrl: './gmap.component.html',
9+
styleUrls: ['./gmap.component.scss'],
1010
})
11-
@MetadataBoxFieldRendering(FieldRenderingType.MAP)
12-
export class MapComponent extends RenderingTypeValueModelComponent implements OnInit {
11+
@MetadataBoxFieldRendering(FieldRenderingType.GMAP)
12+
export class GmapComponent extends RenderingTypeValueModelComponent implements OnInit {
1313
coordinates: string;
1414
ngOnInit(): void {
1515
this.coordinates = this.metadataValue.value;

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadata-box.decorator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export enum FieldRenderingType {
1717
TAG = 'TAG',
1818
VALUEPAIR = 'VALUEPAIR',
1919
HTML = 'HTML',
20-
MAP = 'MAP',
20+
GMAP = 'GMAP',
21+
OSMAP = 'OSMAP',
2122
BROWSE = 'BROWSE',
2223
TAGBROWSE = 'TAG-BROWSE',
2324
MARKDOWN = 'MARKDOWN',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div *ngIf="coordinates.length">
2+
<ds-open-street-maps
3+
[latitude]="latitude"
4+
[longitude]="longitude"
5+
[latitudePointer]="latitude"
6+
[longitudePointer]="longitude"
7+
[showDebugInfo]="false"
8+
[showControlsZoom]="true"
9+
[showControlsCurrentLocation]="true"
10+
></ds-open-street-maps>
11+
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/osmap/osmap.component.scss

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
4+
import { LayoutField } from '../../../../../../../core/layout/models/box.model';
5+
import { Item } from '../../../../../../../core/shared/item.model';
6+
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
7+
import { TranslateLoaderMock } from '../../../../../../../shared/mocks/translate-loader.mock';
8+
import { OsmapComponent } from './osmap.component';
9+
10+
describe('OsmapComponent', () => {
11+
let component: OsmapComponent;
12+
let fixture: ComponentFixture<OsmapComponent>;
13+
14+
const metadataValue = Object.assign(new MetadataValue(), {
15+
'value': '@42.1334,56.7654',
16+
'language': null,
17+
'authority': null,
18+
'confidence': -1,
19+
'place': 0
20+
});
21+
22+
const testItem = Object.assign(new Item(),
23+
{
24+
type: 'item',
25+
metadata: {
26+
'organization.address.addressLocality': [metadataValue]
27+
},
28+
uuid: 'test-item-uuid',
29+
}
30+
);
31+
32+
const mockField: LayoutField = {
33+
'metadata': 'organization.address.addressLocality',
34+
'label': 'Preferred name',
35+
'rendering': 'OSMAP',
36+
'fieldType': 'METADATA',
37+
'style': null,
38+
'styleLabel': 'test-style-label',
39+
'styleValue': 'test-style-value',
40+
'labelAsHeading': false,
41+
'valuesInline': true
42+
};
43+
44+
beforeEach(async () => {
45+
await TestBed.configureTestingModule({
46+
imports: [TranslateModule.forRoot({
47+
loader: {
48+
provide: TranslateLoader,
49+
useClass: TranslateLoaderMock
50+
}
51+
}), BrowserAnimationsModule],
52+
providers: [
53+
{ provide: 'fieldProvider', useValue: mockField },
54+
{ provide: 'itemProvider', useValue: testItem },
55+
{ provide: 'metadataValueProvider', useValue: metadataValue },
56+
{ provide: 'renderingSubTypeProvider', useValue: '' },
57+
],
58+
declarations: [ OsmapComponent ]
59+
})
60+
.compileComponents();
61+
});
62+
63+
beforeEach(() => {
64+
fixture = TestBed.createComponent(OsmapComponent);
65+
component = fixture.componentInstance;
66+
fixture.detectChanges();
67+
});
68+
69+
it('should create', () => {
70+
expect(component).toBeTruthy();
71+
});
72+
73+
// it('should rendered google map.',() => {
74+
// component.coordinates = '@42.1334,56.7654';
75+
// fixture.detectChanges();
76+
// const container = fixture.debugElement.query(By.css('#googlemap'));
77+
// expect(container).toBeTruthy();
78+
// });
79+
80+
// it('should not rendered google map.',() => {
81+
// component.coordinates = undefined;
82+
// fixture.detectChanges();
83+
// const container = fixture.debugElement.query(By.css('#googlemap'));
84+
// expect(container).toBeFalsy();
85+
// });
86+
87+
});

0 commit comments

Comments
 (0)