Skip to content

Commit

Permalink
Fix camera center not being deserialized properly upon platform view …
Browse files Browse the repository at this point in the history
…creation (#469)

* Fix camera center not being deserialed properly upon platform view creation

* Add changelog entry
  • Loading branch information
evil159 committed Apr 3, 2024
1 parent 5f4904a commit 31c92bf
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -37,6 +37,10 @@ CameraOptions(
)))
```

* Bump Pigeon to 17.1.2
* [iOS] Fix crash in `onStyleImageMissingListener`.
* Fix camera center not applied from map init options.

### 1.0.0

* Add `MapboxMapsOptions.get/setWorldview()` and ``MapboxMapsOptions.get/setLanguage()`. Use this to to adjust administrative boundaries/map language based on the map's audience.
Expand Down
@@ -1,13 +1,25 @@
package com.mapbox.maps.mapbox_maps

import android.content.Context
import com.mapbox.common.*
import com.mapbox.maps.*
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.ConstrainMode
import com.mapbox.maps.ContextMode
import com.mapbox.maps.EdgeInsets
import com.mapbox.maps.GlyphsRasterizationMode
import com.mapbox.maps.GlyphsRasterizationOptions
import com.mapbox.maps.MapInitOptions
import com.mapbox.maps.MapOptions
import com.mapbox.maps.NorthOrientation
import com.mapbox.maps.ScreenCoordinate
import com.mapbox.maps.Size
import com.mapbox.maps.Style
import com.mapbox.maps.ViewportMode
import com.mapbox.maps.applyDefaultParams
import com.mapbox.maps.mapbox_maps.mapping.turf.PointDecoder
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.StandardMessageCodec
import io.flutter.plugin.platform.PlatformView
import io.flutter.plugin.platform.PlatformViewFactory
import java.lang.RuntimeException

class MapboxMapFactory(
private val messenger: BinaryMessenger,
Expand Down Expand Up @@ -71,8 +83,8 @@ class MapboxMapFactory(
cameraOptions[4]?.let {
cameraOptionsBuilder.bearing(it as Double)
}
(cameraOptions[0] as? Map<String?, Any?>?)?.let {
cameraOptionsBuilder.center(it.toPoint())
(cameraOptions[0] as? List<Any?>?)?.let {
cameraOptionsBuilder.center(PointDecoder.fromList(it))
}
cameraOptions[5]?.let {
cameraOptionsBuilder.pitch(it as Double)
Expand Down
@@ -1,14 +1,17 @@
package com.mapbox.maps.mapbox_maps.mapping.turf

import com.google.gson.Gson
import com.mapbox.geojson.Point

fun Point.toList(): List<Any?> {
return listOf(mapOf("coordinates" to coordinates()))
}

object PointDecoder {
@Suppress("UNCHECKED_CAST")
fun fromList(list: List<Any?>): Point {
return Point.fromJson(Gson().toJson(list.first()))
val rawPoint = list.first() as Map<String, Any>
val coordinates = rawPoint["coordinates"] as List<Double>

return Point.fromLngLat(coordinates[0], coordinates[1])
}
}
4 changes: 2 additions & 2 deletions ios/Classes/MapboxMapFactory.swift
Expand Up @@ -84,8 +84,8 @@ class MapboxMapFactory: NSObject, FlutterPlatformViewFactory {
let bearing: CLLocationDirection? = cameraOptionsMap[4] as? CLLocationDirection
let pitch: CGFloat? = cameraOptionsMap[5] as? CGFloat

if let centerMap = cameraOptionsMap[0] as? [String: Any] {
center = convertDictionaryToCLLocationCoordinate2D(dict: centerMap)
if let centerList = cameraOptionsMap[0] as? [Any] {
center = Point.fromList(centerList).coordinates
}

if let paddingMap = cameraOptionsMap[1] as? [CGFloat] {
Expand Down

0 comments on commit 31c92bf

Please sign in to comment.