Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feat/maplibre migration #849

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open

Conversation

MAudelGisaia
Copy link
Contributor

@MAudelGisaia MAudelGisaia commented Aug 4, 2024

Hello,
before switching to maplibre I tried a refacto which includes:

  • externalization of map logic in a ts ArlasMapgl class
  • behavior abstraction in AbstractArlasMapGl.

The aim is to:

  • no longer coupling the core library with a particular framwork,
  • lighten the mapgl component.
  • reduce the coupling of other parts of the application with a particular map provider.

I don't know whether what I've started is correct in your eyes. That's why this PR is in wip and open to changes/improvements.

If you think it's going in the wrong direction, it's okay to review the whole thing. This refacto should be seen as a working basis.

Some parts still need to be tested to ensure that everything works as planned.

public abstract getLayers(): void;
public abstract enableDragPan(): void;
public abstract getCenter(): void;
public abstract flyTo(center, zoom: number): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing type for center

* - wrap of provider methode could be implemented in another class in middle of
* abstract class.
*/
export class ArlasMapGl extends AbstractArlasMapGL {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capitalisation of GL should be the same for both (Gl vs GL). Since this map is typed according to mapbox, I think it should be specified in its name to avoid any confusion

// Disable map pitch and rotation with keyboard
this._mapProvider.keyboard.disableRotation();

// disable box zoom;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable -> Disable

@QuCMGisaia
Copy link
Contributor

I don't know if it is a work in progress or if it is the solution you settled on, but I feel like ArlasMapGl is currently typed for mapbox, and can't be used generically. Other than that, it seems very promising !!

@MAudelGisaia MAudelGisaia force-pushed the feat/maplibre-migration branch 7 times, most recently from 5d228ea to 272bf91 Compare September 10, 2024 15:03
import centroid from '@turf/centroid';
import limitVertexDirectSelectMode from './model/LimitVertexDirectSelectMode';
import validGeomDrawPolygonMode from './model/ValidGeomDrawPolygonMode';
import * as mapboxgl from 'mapbox-gl';
import { AnyLayer, TransformRequestFunction } from 'mapbox-gl';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still have some mapboxgl typing here

@@ -584,75 +505,22 @@ export class MapglComponent implements OnInit, AfterViewInit, OnChanges, OnDestr

/** puts the visualisation set list in the new order after dropping */
public drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.visualisationSetsConfig, event.previousIndex, event.currentIndex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we keep the visualisationSetsConfig, the moveItemInArray can be kept and then you use this.map.reorderLayers to avoid defining another method (drop)

@@ -584,75 +505,22 @@ export class MapglComponent implements OnInit, AfterViewInit, OnChanges, OnDestr

/** puts the visualisation set list in the new order after dropping */
public drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.visualisationSetsConfig, event.previousIndex, event.currentIndex);
this.reorderLayers();
this.map.drop(event);
}

/** puts the layers list in the new order after dropping */
public dropLayer(event: CdkDragDrop<string[]>, visuName: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

moveItemInArray(layers, event.previousIndex, event.currentIndex);
this.visualisationSetsConfig.find(v => v.name === visuName).layers = layers;
this.reorderLayers();
this.map.dropLayer(event, visuName);
}

/** Sets the layers order according to the order of `visualisationSetsConfig` list*/
public reorderLayers() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the method should be kept as it was, and only the map level interactions should be moved to the ArlasMapGl, like getLayer, moveLayer. otherwise we would end up coding the same ArlasMap logic in multiple files, instead of just coding the elementary bricks that allow for more complex actions, like reordering the layers

@@ -734,270 +602,230 @@ export class MapglComponent implements OnInit, AfterViewInit, OnChanges, OnDestr
}
}

public defaultOnZoom(e) {
if (e.features[0].properties.cluster_id !== undefined) {
// TODO: should check the this.index is set with good value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, when i looked into refactoring the component, it was not clear where index was set and what it does

}
}

public addLayerInWritePlaceIfNotExist(layerId: string): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write -> Right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be addLayerAboveBaseLayers or something like that


public getMapExtend(): MapExtend {
const bounds = this.getMapProvider().getBounds();
return { bounds: bounds.toArray(), center: bounds.getCenter().toArray(), zoom: this.getMapProvider().getZoom() };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

event: string; fn: (e?) => void;
}){
this.getMapProvider().addControl(control, position);
if(control instanceof ControlButton && eventOverride){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in ArlasMapGL you have access to the _mapProvider, it would be best to use that instead of using the access method

* the change is transparent.
*/

export interface MapOverride {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typing could be more informative in this interface

@@ -91,8 +92,8 @@ export class MapglBasemapComponent implements OnInit {
*/
public setStyle(s: mapboxgl.Style, newBasemap: BasemapStyle) {
const selectedBasemapLayersSet = new Set<string>();
const layers: Array<mapboxgl.Layer> = (<mapboxgl.Map>this.map).getStyle().layers;
const sources = (<mapboxgl.Map>this.map).getStyle().sources;
const layers: Array<mapboxgl.Layer> = this.map.getStyle().layers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapboxgl is not removed for layers ?

@@ -42,7 +43,7 @@ export class MapboxBasemapService {
this.basemaps = basemaps;
}

public addProtomapBasemap(map: mapboxgl.Map) {
public addProtomapBasemap(map: ArlasMapGL) {
const selectedBasemap = this.basemaps.getSelected();
if (selectedBasemap.type === 'protomap') {
const styleFile = selectedBasemap.styleFile as mapboxgl.Style;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapboxgl is not removed for layers ?

@@ -68,7 +69,7 @@ export class MapboxBasemapService {
this.protomapBasemapAddedSource.next(true);
}

public removeProtomapBasemap(map: mapboxgl.Map) {
public removeProtomapBasemap(map: ArlasMapGL) {
const selectedBasemap = this.basemaps.getSelected();
if (selectedBasemap.type === 'protomap') {
(selectedBasemap.styleFile as mapboxgl.Style).layers.forEach(l => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapboxgl is not removed for Style ?

@@ -42,7 +43,7 @@ export class MapboxBasemapService {
this.basemaps = basemaps;
}

public addProtomapBasemap(map: mapboxgl.Map) {
public addProtomapBasemap(map: ArlasMapGL) {
const selectedBasemap = this.basemaps.getSelected();
if (selectedBasemap.type === 'protomap') {
const styleFile = selectedBasemap.styleFile as mapboxgl.Style;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapboxgl is not removed for styles ?

@@ -68,7 +69,7 @@ export class MapboxBasemapService {
this.protomapBasemapAddedSource.next(true);
}

public removeProtomapBasemap(map: mapboxgl.Map) {
public removeProtomapBasemap(map: ArlasMapGL) {
const selectedBasemap = this.basemaps.getSelected();
if (selectedBasemap.type === 'protomap') {
(selectedBasemap.styleFile as mapboxgl.Style).layers.forEach(l => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapboxgl is not removed for styles ?

private north: number;
private east: number;
private west: number;
private south: number;
private isDrawingBbox = false;
private canvas: HTMLElement;
private box: HTMLElement;
// points which xy coordinates are in screen referential
private start: mapboxgl.Point;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still have some mapboxgl typing here

@@ -461,8 +426,9 @@ export class MapglComponent implements OnInit, AfterViewInit, OnChanges, OnDestr
private drawBboxSubscription: Subscription;

public constructor(private http: HttpClient, private drawService: MapboxAoiDrawService,
private basemapService: MapboxBasemapService,
private _snackBar: MatSnackBar, private translate: TranslateService) {
private basemapService: MapboxBasemapService,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basemap service injected here is mapboxgl typed

'DRAW_LINE_STRING' | 'DRAW_POLYGON' | 'DRAW_POINT' | 'DRAW_RADIUS_CIRCLE' |
'DRAW_STRIP' | 'DIRECT_STRIP';

export class ArlasDraw extends AbstractDraw {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be named ArlasMapboxGLDraw ?

@MohamedHamouGisaia
Copy link
Member

  • Rename ArlasMapGl, ArlasDraw and any other class that is an implementation of mapboxgl to
  • BasemapService abstrait + 2 implémentations
  • On utilise une class abstraite avec 2 services en implémentation, provide la classe abstraite + use class (l'implémentation)
  • Les fonctions qui ne dépendent pas de maplibre/mapbox peuvent soit être utilisé dans le composant ou le service abstrait
  • Generic type / Interface générique ?
  • Implémentation maplibre à faire.
  • On laisse deux implémentations mapbox (1.3) et maplibre à stabiliser
  • On passe en libs en suivant

@MAudelGisaia MAudelGisaia force-pushed the feat/maplibre-migration branch from 0b4c783 to 0ab5adc Compare October 18, 2024 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants