Skip to content

Commit 2f17f15

Browse files
author
farfromrefug
committed
fix(android): many bug fixes
1 parent b430be9 commit 2f17f15

File tree

3 files changed

+121
-83
lines changed

3 files changed

+121
-83
lines changed

src/ui-mapbox/index.android.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ export class MapboxView extends MapboxViewBase {
298298
* @todo FIXME: this.nativeMapView is unused and never actually set to anything.
299299
*/
300300
async initMap() {
301-
const accessToken = this.config?.accessToken ?? this.settings?.accessToken
301+
const accessToken = this.config?.accessToken ?? this.settings?.accessToken;
302302
if (Trace.isEnabled()) {
303303
CLog(CLogTypes.info, "MapboxView:initMap(): top - accessToken is '" + accessToken + "'", this.config);
304304
}
@@ -636,6 +636,9 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
636636
this._mapboxMapInstance,
637637
this._mapboxViewInstance,
638638
(marker: AndroidMarker) => {
639+
if (Trace.isEnabled()) {
640+
CLog(CLogTypes.info, 'MarkerManager.onMarkerClicked():');
641+
}
639642
const cachedMarker = this._getClickedMarkerDetails(marker);
640643
if (cachedMarker?.onTap) {
641644
const result = cachedMarker.onTap(cachedMarker);
@@ -1423,6 +1426,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
14231426
new AndroidMarker({
14241427
position: com.mapbox.geojson.Point.fromLngLat(marker.lng, marker.lat),
14251428
title: marker.title,
1429+
id: marker.id,
14261430
snippet: marker.subtitle,
14271431
icon: icon?.android
14281432
})
@@ -1434,7 +1438,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
14341438
}
14351439

14361440
marker.update = (newSettings: MapboxMarker) => {
1437-
console.log('update marker', Object.keys(newSettings), newSettings);
14381441
const theMarker = this._markers.find((m) => m.id === marker.id);
14391442
if (theMarker) {
14401443
if (newSettings.onTap) {
@@ -1474,7 +1477,9 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
14741477
if (!this._mapboxMapInstance) {
14751478
return;
14761479
}
1477-
1480+
if (Trace.isEnabled()) {
1481+
CLog(CLogTypes.info, '_removeMarkers: ', ids);
1482+
}
14781483
this._markers.forEach((marker) => {
14791484
if (!ids || (marker && marker.id && ids.indexOf(marker.id) > -1)) {
14801485
if (marker && marker.android) {
@@ -1774,7 +1779,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
17741779
}
17751780
const polygonOptions = new com.mapbox.maps.plugin.annotation.generated.PolygonAnnotationOptions();
17761781
const nPoints = java.util.Arrays.asList([java.util.Arrays.asList(points.map((p) => com.mapbox.geojson.Point.fromLngLat(p.lng, p.lat)))]);
1777-
console.log('add points', nPoints);
17781782
polygonOptions.withPoints(nPoints);
17791783

17801784
polygonOptions.withFillColor(Mapbox.getAndroidColor(options.fillColor));
@@ -1785,7 +1789,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
17851789
polygonOptions.withFillOutlineColor(Mapbox.getAndroidColor(options.strokeColor));
17861790
}
17871791

1788-
this._polylines[options.id || new Date().getTime()] = this.polygonManager.create(polygonOptions);
1792+
this._polygons[options.id || new Date().getTime()] = this.polygonManager.create(polygonOptions);
17891793
resolve();
17901794
} catch (ex) {
17911795
if (Trace.isEnabled()) {
@@ -1972,10 +1976,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
19721976
if (Trace.isEnabled()) {
19731977
CLog(CLogTypes.info, 'Mapbox:setOnMapClickListener(): click event at point:', point);
19741978
}
1975-
return this.checkForClickEvent({
1976-
lat: point.latitude(),
1977-
lng: point.longitude()
1978-
});
1979+
return (
1980+
listener({
1981+
lat: point.latitude(),
1982+
lng: point.longitude()
1983+
}) ?? true
1984+
);
19791985
}
19801986
});
19811987
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMapClickListener(this._mapboxMapInstance, this.onMapClickListener);
@@ -2005,7 +2011,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
20052011
})
20062012
});
20072013

2008-
this._getGesturesPlugin().addOnMapLongClickListener(this.onMapLongClickListener);
2014+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnMapLongClickListener(this._mapboxMapInstance, this.onMapLongClickListener);
20092015

20102016
resolve();
20112017
} catch (ex) {
@@ -2139,7 +2145,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
21392145
this.onFlingListener = new com.mapbox.maps.plugin.gestures.OnFlingListener({
21402146
onFling: () => listener()
21412147
});
2142-
this._getGesturesPlugin().addOnFlingListener(this.onFlingListener);
2148+
com.mapbox.maps.plugin.gestures.GesturesUtils.addOnFlingListener(this._mapboxMapInstance, this.onFlingListener);
21432149

21442150
resolve();
21452151
} catch (ex) {
@@ -2348,7 +2354,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
23482354
bounds: options.bounds,
23492355
...options.metadata
23502356
};
2351-
console.log('downloadRegion', regionId, new com.mapbox.bindgen.Value(JSON.stringify(info)));
23522357
const regionOptions = new com.mapbox.common.TileRegionLoadOptions.Builder()
23532358
.geometry(bbox)
23542359
.descriptors(java.util.Collections.singletonList(tilesetDescriptor))
@@ -3319,14 +3324,7 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
33193324
invoke: (settings: com.mapbox.maps.plugin.locationcomponent.generated.LocationComponentSettings.Builder) => {
33203325
settings.setEnabled(true);
33213326
settings.setPulsingEnabled(true);
3322-
console.log(
3323-
'setPuckBearingEnabled',
3324-
options.cameraMode,
3325-
options.renderMode,
3326-
options.renderMode !== 'NORMAL',
3327-
com.mapbox.maps.plugin.PuckBearing.HEADING,
3328-
com.mapbox.maps.plugin.PuckBearing.COURSE
3329-
);
3327+
33303328
settings.setLocationPuck(com.mapbox.maps.plugin.locationcomponent.LocationComponentUtils.createDefault2DPuck(true));
33313329

33323330
settings.setPuckBearingEnabled(options.renderMode !== 'NORMAL');

src/ui-mapbox/markers/Marker.android.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ export class AndroidMarker {
99
icon: android.graphics.Bitmap;
1010
title?: string;
1111
snippet?: string;
12+
id?: string | number;
1213

1314
pointAnnotation: com.mapbox.maps.plugin.annotation.generated.PointAnnotation;
1415
viewAnnotation: android.view.View;
1516
view: StackLayout;
1617
anchor: com.mapbox.maps.ViewAnnotationAnchorConfig;
1718
layerId: string;
18-
prepared = false;
1919

20-
constructor(opts: { position: com.mapbox.geojson.Point; icon: android.graphics.Bitmap; title?: string; snippet?: string }) {
20+
constructor(opts: { id: string | number; position: com.mapbox.geojson.Point; icon: android.graphics.Bitmap; title?: string; snippet?: string }) {
2121
if (!opts.title && !opts.snippet) {
2222
throw new Error('Marker should have either title or snippet!');
2323
}
2424

2525
this.position = opts.position;
26+
this.id = opts.id;
2627
this.icon = opts.icon;
2728
this.title = opts.title;
2829
this.snippet = opts.snippet;
@@ -40,7 +41,7 @@ export class AndroidMarker {
4041
) as com.mapbox.maps.plugin.annotation.generated.PointAnnotation;
4142
this.layerId = layerId;
4243
if (Trace.isEnabled()) {
43-
CLog(CLogTypes.log, 'MarkerManager prepareAnnotationMarker: ' + layerId);
44+
CLog(CLogTypes.log, 'MarkerManager prepareAnnotationMarker: ' + layerId, this.id, this.pointAnnotation);
4445
}
4546
}
4647

0 commit comments

Comments
 (0)