Skip to content

Commit 4551401

Browse files
committed
feat: belowLayerId support for addLayer
1 parent e593480 commit 4551401

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/mapbox.android.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -2440,12 +2440,11 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24402440
* @link https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
24412441
*/
24422442

2443-
public async addLayer(style, nativeMap?): Promise<void> {
2443+
public async addLayer(style, belowLayerId?: string, nativeMap?): Promise<void> {
24442444
const theMap = nativeMap || this._mapboxMapInstance;
24452445
if (!theMap) {
24462446
return Promise.reject('No map has been loaded');
24472447
}
2448-
24492448
let source = null;
24502449
if (typeof style.source != 'string') {
24512450
await this.addSource(style.id + '_source', style.source);
@@ -2455,6 +2454,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24552454
}
24562455

24572456
const layer = await LayerFactory.createLayer(style, source);
2457+
if (belowLayerId) {
2458+
this._mapboxMapInstance.getStyle().addLayerBelow(layer.getNativeInstance(), belowLayerId);
2459+
return;
2460+
}
24582461
this._mapboxMapInstance.getStyle().addLayer(layer.getNativeInstance());
24592462
}
24602463

src/mapbox.common.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,9 @@ export interface MapboxApi {
612612

613613
removeSource(id: string, nativeMap?: any): Promise<any>;
614614

615-
addLayer(style, nativeMapView?: any): Promise<any>;
615+
addLayer(style, belowLayerId?: string, nativeMapView?: any): Promise<any>;
616616

617-
addLayer(options: AddLayerOptions): Promise<any>;
617+
addLayer(options: AddLayerOptions, belowLayerId?: string): Promise<any>;
618618

619619
removeLayer(id: string, nativeMapView?: any): Promise<any>;
620620

@@ -750,9 +750,9 @@ export interface MapboxViewApi {
750750
removeMarkers(options?: any): Promise<any>;
751751

752752
queryRenderedFeatures(options: QueryRenderedFeaturesOptions): Promise<Feature[]>;
753-
753+
754754
querySourceFeatures(sourceId: string, options?: QuerySourceFeaturesOptions): Promise<Feature[]>;
755-
755+
756756
setOnMapClickListener(listener: (data: LatLng) => boolean): Promise<any>;
757757

758758
setOnMapLongClickListener(listener: (data: LatLng) => boolean): Promise<any>;
@@ -803,7 +803,7 @@ export interface MapboxViewApi {
803803

804804
removeSource(id: string, nativeMap?: any): Promise<any>;
805805

806-
addLayer(style): Promise<any>;
806+
addLayer(style, belowLayerId?: string): Promise<any>;
807807

808808
removeLayer(id: string): Promise<any>;
809809

@@ -961,8 +961,8 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
961961
removeSource(id: string): Promise<any> {
962962
return this.mapbox.removeSource(id, this.getNativeMapView());
963963
}
964-
addLayer(style): Promise<any> {
965-
return this.mapbox.addLayer(style, this.getNativeMapView());
964+
addLayer(style, belowLayerId?: string): Promise<any> {
965+
return this.mapbox.addLayer(style, belowLayerId, this.getNativeMapView());
966966
}
967967
removeLayer(id: string): Promise<any> {
968968
return this.mapbox.removeLayer(id, this.getNativeMapView());

src/mapbox.ios.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
22532253
*
22542254
* @link https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
22552255
*/
2256-
public async addLayer(style, nativeMapView?): Promise<void> {
2256+
public async addLayer(style, belowLayerId?: string, nativeMapView?): Promise<void> {
22572257
const theMap: MGLMapView = nativeMapView || this._mapboxViewInstance;
22582258

22592259
let source = null;
@@ -2265,6 +2265,13 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
22652265
}
22662266

22672267
const layer = await LayerFactory.createLayer(style, source);
2268+
if (belowLayerId) {
2269+
const belowlayer = theMap.style.layerWithIdentifier(belowLayerId);
2270+
if (belowlayer) {
2271+
theMap.style.insertLayerBelowLayer(layer.getNativeInstance(), belowlayer);
2272+
return;
2273+
}
2274+
}
22682275
theMap.style.addLayer(layer.getNativeInstance());
22692276
}
22702277

0 commit comments

Comments
 (0)