Skip to content

Commit 3d4cedd

Browse files
committed
fix(ios): missing options and improvements
1 parent 7975da7 commit 3d4cedd

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

packages/ui-mapbox/platforms/ios/src/MapboxBridge.swift

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ public class MapboxBridge: NSObject {
176176
@objc public func createMap(_ x: Double, _ y: Double, _ width: Double, _ height: Double, _ accessToken: String, _ styleURIString: String?, _ optionsJSON: String) -> UIView {
177177
MapboxOptions.accessToken = accessToken
178178
let styleURI = getMapStyleURI(styleURIString)
179-
179+
let optionsOpt = MapboxBridge.parseJSONParameter(optionsJSON) as? [String: Any]
180+
180181
var centerCoordinate = CLLocationCoordinate2D(latitude: 48.858093, longitude: 2.294694)
181182
var zoom = 0.0
182-
if let options = MapboxBridge.parseJSONParameter(optionsJSON) as? [String: Any] {
183+
if let options = optionsOpt {
183184
if let z = options["zoomLevel"] as? Double {
184185
zoom = z
185186
}
@@ -202,6 +203,31 @@ public class MapboxBridge: NSObject {
202203
MapboxBridge.registerBridge(self, for: mv)
203204

204205
addImage("default_pin", image: UIImage(named: "default_pin"))
206+
207+
if let options = optionsOpt {
208+
if ((options["hideLogo"] as? Bool) == true) {
209+
mv.ornaments.logoView.isHidden = true
210+
}
211+
if ((options["hideAttribution"] as? Bool) == true) {
212+
mv.ornaments.attributionButton.isHidden = true
213+
}
214+
if ((options["hideCompass"] as? Bool) == true) {
215+
mv.ornaments.compassView.isHidden = true
216+
}
217+
if ((options["disableRotation"] as? Bool) == true) {
218+
mv.gestures.options.rotateEnabled = false
219+
}
220+
if ((options["disableScroll"] as? Bool) == true) {
221+
mv.gestures.options.panEnabled = false
222+
}
223+
if ((options["disableZoom"] as? Bool) == true) {
224+
mv.gestures.options.pinchZoomEnabled = false
225+
mv.gestures.options.quickZoomEnabled = false
226+
}
227+
if ((options["disableTilt"] as? Bool) == true) {
228+
mv.gestures.options.pitchEnabled = false
229+
}
230+
}
205231

206232
// mapLoaded
207233
mv.mapboxMap.onMapLoaded.observeNext { _ in
@@ -1162,7 +1188,7 @@ public class MapboxBridge: NSObject {
11621188
}
11631189

11641190

1165-
@objc public func trackUser(_ optionsJSON: String) -> Bool {
1191+
@objc public func showUserLocationMarker(_ optionsJSON: String) -> Bool {
11661192
guard let mv = mapView else { return false }
11671193

11681194
guard let data = optionsJSON.data(using: .utf8),

src/ui-mapbox/index.ios.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,13 @@ export class MapboxView extends MapboxViewBase {
143143
private initCountHack = 50;
144144

145145
setConfig(settings: any) {
146-
if (Trace.isEnabled()) {
147-
CLog(CLogTypes.info, 'setConfig(): settings:', settings);
146+
if (settings.zoomLevel && !settings.center) {
147+
// Eiffel tower, Paris
148+
settings.center = {
149+
lat: 48.858093,
150+
lng: 2.294694
151+
};
148152
}
149-
150153
this.settings = settings;
151154
}
152155
getNativeMapView(): any {
@@ -189,7 +192,7 @@ export class MapboxView extends MapboxViewBase {
189192

190193
initMap(): void {
191194
if (Trace.isEnabled()) {
192-
CLog(CLogTypes.info, 'initMap() top with settings:', this.settings);
195+
CLog(CLogTypes.info, 'initMap() top');
193196
}
194197

195198
if (!this.settings && !this.config.accessToken) {
@@ -470,6 +473,10 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
470473
view.addSubview(nativeMap);
471474
this.setMapboxViewInstance(nativeMap);
472475

476+
if (settings.showUserLocation) {
477+
this.showUserLocationMarker({});
478+
}
479+
473480
this.initEventHandlerShim(settings, this._mapboxViewInstance);
474481
if (settings.onMapReady) {
475482
settings.onMapReady(this._mapboxViewInstance);
@@ -1575,15 +1582,15 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
15751582

15761583
// ---------------- User location & tilt ----------------
15771584

1578-
showUserLocationMarker(show: boolean): Promise<void> {
1585+
showUserLocationMarker(options: Partial<TrackUserOptions>): Promise<void> {
15791586
return new Promise((resolve, reject) => {
15801587
try {
15811588
const b = this.bridgeInstance;
15821589
if (!b) {
15831590
reject('No bridge available');
15841591
return;
15851592
}
1586-
b.showUserLocationMarker(show);
1593+
b.showUserLocationMarker(JSON.stringify(options));
15871594
resolve();
15881595
} catch (ex) {
15891596
reject(ex);
@@ -1634,7 +1641,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
16341641
if (Trace.isEnabled()) {
16351642
CLog(CLogTypes.info, 'trackUser():', JSON.stringify(options));
16361643
}
1637-
const ok = b.trackUser(JSON.stringify(options));
1644+
const ok = b.showUserLocationMarker(JSON.stringify(options));
16381645
if (ok) {
16391646
resolve();
16401647
} else {

src/ui-mapbox/typings/mapbox.bridge.ios.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ declare class MapboxBridge extends NSObject {
8585
deleteOfflineRegion(idOrName: string): void;
8686

8787
// user location & tilt
88-
showUserLocationMarker(show: boolean): void;
88+
showUserLocationMarker(optionsJSON: string);
8989
hideUserLocationMarker(): void;
9090
forceUserLocationUpdate(): boolean;
9191
getTilt(): number | null;
9292
setTilt(tilt: number, animated: boolean): void;
9393
getUserLocation(): NSDictionary | null;
9494

95-
trackUser(optionsJSON: string): boolean;
9695
stopTrackingUser(): void;
9796

9897
// added/updated methods

0 commit comments

Comments
 (0)