Skip to content

Commit e43f52a

Browse files
committed
feat(map-ol): allow to pass olViewOptions to create map
1 parent d5abbc1 commit e43f52a

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* **@dlr-eoc/map-ol:**
88
- Use `projjson` or `proj4js` to create projection if defined on `IProjDef`.
99
- Use all `IListMatrixSet` options in `getTileGrid` to create `WMTSTileGrid`.
10+
- Allow to pass `olViewOptions` to map-ol component.
1011

1112
* **@dlr-eoc/services-layers:**
1213
- More options to create `WMTSTileGrid` on `IListMatrixSet`. The new optional options are `extent?: TGeoExtent`, `origin?: number[]`, `origins?: [number, number][]`, `tileSizes?: number[]` and `sizes?: [number, number][];`.

projects/map-ol/src/lib/map-ol.component.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import olVectorLayer from 'ol/layer/Vector';
4040
import { applyStyle } from 'ol-mapbox-style';
4141
import { collectionItemSetIndex, layerOrGroupSetOpacity, layerOrGroupSetVisible, layerOrGroupSetZIndex } from '@dlr-eoc/utils-maps';
4242
import { defaults as defaultInteractions } from 'ol/interaction/defaults';
43+
import { ViewOptions as olViewOptions } from 'ol/View';
4344

4445
import VectorSource from 'ol/source/Vector';
4546

@@ -79,6 +80,7 @@ export class MapOlComponent implements OnInit, AfterViewInit, AfterViewChecked,
7980
@Input('layersSvc') layersSvc: LayersService;
8081
@Input('mapState') mapStateSvc: MapStateService;
8182
@Input('controls') controls: IMapControls;
83+
@Input('viewOptions') viewOptions: olViewOptions;
8284

8385
map: Map;
8486
subs: Subscription[] = [];
@@ -96,7 +98,7 @@ export class MapOlComponent implements OnInit, AfterViewInit, AfterViewChecked,
9698
ngOnInit() {
9799
/** Subscribe to mapStateSvc before map is created */
98100
this.subscribeToMapState();
99-
this.initMap();
101+
this.initMap(this.viewOptions);
100102
/** subscribe to layers oninit so they get pulled after view init */
101103
this.subscribeToLayers();
102104
// TODO: refactor to signals
@@ -585,8 +587,8 @@ export class MapOlComponent implements OnInit, AfterViewInit, AfterViewChecked,
585587
}
586588

587589

588-
private initMap() {
589-
const olMapView = this.mapSvc.createMap();
590+
private initMap(viewOptions?: olViewOptions) {
591+
const olMapView = this.mapSvc.createMap(undefined, viewOptions);
590592
this.map = olMapView.map; //
591593
const oldInteractions = this.map.getInteractions();
592594
const interactions = defaultInteractions();

projects/map-ol/src/lib/map-ol.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class MapOlService {
154154
* if this is used in an angular component then set the target after the view is created
155155
* e.g. this.map.setTarget(this.mapDivView.nativeElement) in ngAfterViewInit()
156156
*/
157-
public createMap(target?: HTMLElement) {
157+
public createMap(target?: HTMLElement, options?: olViewOptions) {
158158
const zoom = 0;
159159
const center = {
160160
lat: 0,
@@ -256,6 +256,10 @@ export class MapOlService {
256256
if (this.view['zoomFactor']) {
257257
this.viewOptions.zoomFactor = this.view['zoomFactor'];
258258
}
259+
260+
if (options) {
261+
this.viewOptions = Object.assign(this.viewOptions, options);
262+
}
259263
const tempview = new olView(this.viewOptions);
260264

261265
/** define map in constructor so it is created before to use it in projects onInit Method */

0 commit comments

Comments
 (0)