Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/ui-mapbox/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ export interface MapboxApi {

removeImage(imageId: string, nativeMap?: any): Promise<void>;
project(data: LatLng): { x: number; y: number };

projectBack(point: { x: number, y: number }): LatLng;
}

// ------------------------------------------------------------
Expand Down Expand Up @@ -870,6 +872,13 @@ export interface MapboxViewApi {
onLowMemory(): Promise<any>;

onDestroy(): Promise<any>;

project(data: LatLng): {
x: number;
y: number;
};

projectBack(screenCoordinate: { x: number, y: number }): LatLng;
}

// ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1061,6 +1070,9 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
project(data: LatLng) {
return this.mapbox && this.mapbox.project(data);
}
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
return this.mapbox && this.mapbox.projectBack(screenCoordinate);
}
}

// -----------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/ui-mapbox/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3391,4 +3391,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
const screenLocation = this._mapboxMapInstance.getProjection().toScreenLocation(mapboxPoint);
return { x: Utils.layout.toDeviceIndependentPixels(screenLocation.x), y: Utils.layout.toDeviceIndependentPixels(screenLocation.y) };
}
projectBack(screenCoordinate: { x: number, y: number }): LatLng {
const pointf = new android.graphics.PointF(screenCoordinate.x, screenCoordinate.y);
const coordinate = this._mapboxMapInstance.getProjection().fromScreenLocation(pointf);
return {
lat: coordinate.getLatitude(),
lng: coordinate.getLongitude()
}
}
}
3 changes: 2 additions & 1 deletion src/ui-mapbox/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@ export declare class Mapbox extends MapboxCommon implements MapboxApi {
x: number;
y: number;
};
}
projectBack(screenCoordinate: { x: number, y: number }): LatLng;
}
13 changes: 13 additions & 0 deletions src/ui-mapbox/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,19 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
const { x, y } = theMap.convertCoordinateToPointToView({ latitude: data.lat, longitude: data.lng }, theMap);
return { x, y };
}

projectBack(screenCoordinate: { x: number, y: number }): LatLng {
const theMap: MGLMapView = this._mapboxViewInstance;
const cgPoint = {
x: screenCoordinate.x,
y: screenCoordinate.y
}
const coordinate = theMap.convertPointToCoordinateFromView(cgPoint, theMap);
return {
lat: coordinate.latitude,
lng: coordinate.longitude
}
}
}

const _addObserver = (eventName, callback) => NSNotificationCenter.defaultCenter.addObserverForNameObjectQueueUsingBlock(eventName, null, NSOperationQueue.mainQueue, callback);
Expand Down