From 09159201bdf9e7e4f28d67ae03a3b02447b377dc Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Wed, 31 May 2023 08:11:37 -0500 Subject: [PATCH 01/11] update set properties --- .../mapbox/mapboxgl/MapboxMapController.java | 21 +++++++++++++++++++ lib/src/color_tools.dart | 4 ++++ lib/src/controller.dart | 6 ++++++ .../lib/src/mapbox_gl_platform_interface.dart | 2 ++ .../lib/src/method_channel_mapbox_gl.dart | 10 +++++++++ .../lib/src/mapbox_web_gl_platform.dart | 7 +++++++ 6 files changed, 50 insertions(+) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index 3499d4ef5..f2c7d3c98 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -138,6 +138,8 @@ final class MapboxMapController private LatLng dragOrigin; private LatLng dragPrevious; private LatLngBounds bounds = null; + private HashMap lineLayers = new HashMap(); + Style.OnStyleLoaded onStyleLoadedCallback = new Style.OnStyleLoaded() { @Override @@ -424,6 +426,11 @@ private void addSymbolLayer( } } + private void setLineLayerProperties(String layerName, PropertyValue[] properties){ + LineLayer layer = lineLayers.get(layerName); + layer.setProperties(properties); + } + private void addLineLayer( String layerName, String sourceName, @@ -456,6 +463,8 @@ private void addLineLayer( if (enableInteraction) { interactiveFeatureLayerIds.add(layerName); } + + lineLayers.put(layerName, lineLayer); } private void addFillLayer( @@ -1429,6 +1438,18 @@ public void onError(String error) { }); break; } + case "lineLayer#setProperties": + { + + final PropertyValue[] properties = LayerPropertyConverter.interpretLineLayerProperties(call.argument("properties")); + final String layerId = call.argument("layerId"); + + setLineLayerProperties(layerId, properties); + + result.success(null); + + break; + } default: result.notImplemented(); } diff --git a/lib/src/color_tools.dart b/lib/src/color_tools.dart index f78a5a1c8..fda61dc04 100644 --- a/lib/src/color_tools.dart +++ b/lib/src/color_tools.dart @@ -7,4 +7,8 @@ extension MapBoxColorConversion on Color { final b = blue.toRadixString(16).padLeft(2, '0'); return '#$r$g$b'; } + + String toRgbWithAlphaString() { + return 'rgba($red,$green, $blue, ${alpha / 255})'; + } } diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 4c97274fa..3b9f6408e 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -387,6 +387,12 @@ class MapboxMapController extends ChangeNotifier { ); } + Future setLineLayerProperties( + String layerId, LineLayerProperties properties) async { + await _mapboxGlPlatform.setLineLayerProperties( + layerId, properties.toJson()); + } + /// Add a line layer to the map with the given properties /// /// Consider using [addLayer] for an unified layer api. diff --git a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart index 346998bd0..2447bc045 100644 --- a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart +++ b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart @@ -123,6 +123,8 @@ abstract class MapboxGlPlatform { dynamic filter, required bool enableInteraction}); + Future setLineLayerProperties(String layerId, Map properties); + Future addLineLayer( String sourceId, String layerId, Map properties, {String? belowLayerId, diff --git a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart index 28a8e268c..25e643335 100644 --- a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart +++ b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart @@ -582,6 +582,16 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { }); } + @override + Future setLineLayerProperties( + String layerId, Map properties) async { + await _channel.invokeMapMethod('lineLayer#setProperties', { + 'layerId': layerId, + 'properties': properties + .map((key, value) => MapEntry(key, jsonEncode(value))) + }); + } + @override Future addLineLayer( String sourceId, String layerId, Map properties, diff --git a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart index c3872cf50..454aea725 100644 --- a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart +++ b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart @@ -1069,4 +1069,11 @@ class MapboxWebGlPlatform extends MapboxGlPlatform void forceResizeWebMap() { _map.resize(); } + + @override + Future setLineLayerProperties( + String layerId, Map properties) { + // TODO: implement setLineLayerProperties + throw UnimplementedError(); + } } From 1e4afd1cb1d8fe1ca99a8d96f480b770cd07fa84 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Thu, 1 Jun 2023 08:38:47 -0500 Subject: [PATCH 02/11] ios implementation and cleanup --- .../mapbox/mapboxgl/MapboxMapController.java | 1 + example/android/.project | 11 +++++++ .../org.eclipse.buildship.core.prefs | 11 +++++++ ios/Classes/MapboxMapController.swift | 29 +++++++++++++++++++ pubspec.lock | 18 ++++++------ scripts/pubspec.lock | 8 +++-- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index f2c7d3c98..c4084232b 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -2010,6 +2010,7 @@ void removeLayer(String layerId) { if (style != null && layerId != null) { style.removeLayer(layerId); interactiveFeatureLayerIds.remove(layerId); + lineLayers.remove(layerId); } } diff --git a/example/android/.project b/example/android/.project index 3964dd3f5..2fdf8f58d 100644 --- a/example/android/.project +++ b/example/android/.project @@ -14,4 +14,15 @@ org.eclipse.buildship.core.gradleprojectnature + + + 1685582061856 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/example/android/.settings/org.eclipse.buildship.core.prefs b/example/android/.settings/org.eclipse.buildship.core.prefs index e8895216f..44b7d4122 100644 --- a/example/android/.settings/org.eclipse.buildship.core.prefs +++ b/example/android/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments=--init-script /var/folders/x9/_754gdq53b1dqkmjk09_4q540000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/x9/_754gdq53b1dqkmjk09_4q540000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.4.2)) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index e9b992653..4f3f498de 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -28,6 +28,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma private var interactiveFeatureLayerIds = Set() private var addedShapesByLayer = [String: MGLShape]() + private var lineLayers = [String : MGLLineStyleLayer]() + func view() -> UIView { return mapView } @@ -399,6 +401,21 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma case .success: result(nil) case let .failure(error): result(error.flutterError) } + + case "lineLayer#setProperties": + guard let arguments = methodCall.arguments as? [String: Any] else { return } + guard let layerId = arguments["layerId"] as? String else { return } + guard let properties = arguments["properties"] as? [String: String] else { return } + + let editResult = setLineLayerProperties( + layerId: layerId, + properties: properties + ) + + switch editResult { + case .success: result(nil) + case let .failure(error): result(error.flutterError) + } case "fillLayer#add": guard let arguments = methodCall.arguments as? [String: Any] else { return } @@ -916,6 +933,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let layer = mapView.style?.layer(withIdentifier: layerId) { mapView.style?.removeLayer(layer) interactiveFeatureLayerIds.remove(layerId) + lineLayers.removeValue(forKey: layerId) } } @@ -1236,6 +1254,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma return .success(()) } + func setLineLayerProperties(layerId: String, properties: [String: String]) -> Result { + let layer : MGLLineStyleLayer? = lineLayers[layerId] + if let lineLayer = layer { + LayerPropertyConverter.addLineProperties(lineLayer: lineLayer, properties: properties) + } + + return .success(()) + } + func addLineLayer( sourceId: String, layerId: String, @@ -1273,6 +1300,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if enableInteraction { interactiveFeatureLayerIds.insert(layerId) } + + lineLayers[layerId] = layer; } } return .success(()) diff --git a/pubspec.lock b/pubspec.lock index 3064bfbed..4fc2653e3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -13,18 +13,18 @@ packages: dependency: transitive description: name: characters - sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.3.0" collection: dependency: "direct main" description: name: collection - sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 + sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" url: "https://pub.dev" source: hosted - version: "1.17.0" + version: "1.17.1" crypto: dependency: transitive description: @@ -55,10 +55,10 @@ packages: dependency: transitive description: name: js - sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 url: "https://pub.dev" source: hosted - version: "0.6.5" + version: "0.6.7" mapbox_gl_dart: dependency: transitive description: @@ -93,10 +93,10 @@ packages: dependency: transitive description: name: meta - sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" + sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" url: "https://pub.dev" source: hosted - version: "1.8.0" + version: "1.9.1" path: dependency: transitive description: @@ -143,5 +143,5 @@ packages: source: hosted version: "5.1.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.0.0-0 <4.0.0" flutter: ">=2.0.0" diff --git a/scripts/pubspec.lock b/scripts/pubspec.lock index fed710049..561dc45be 100644 --- a/scripts/pubspec.lock +++ b/scripts/pubspec.lock @@ -5,15 +5,17 @@ packages: dependency: "direct main" description: name: mustache_template - url: "https://pub.dartlang.org" + sha256: a46e26f91445bfb0b60519be280555b06792460b27b19e2b19ad5b9740df5d1c + url: "https://pub.dev" source: hosted version: "2.0.0" recase: dependency: "direct main" description: name: recase - url: "https://pub.dartlang.org" + sha256: "7aec9b9f498cba65ed969eda51ea3d86a77bbd633d876b57d9db7d9f94fc6ca5" + url: "https://pub.dev" source: hosted version: "4.0.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.12.0 <4.0.0" From 147a1d4e8b6f4262b1b3b1140d91fb24756c30bc Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Wed, 7 Jun 2023 23:29:15 -0500 Subject: [PATCH 03/11] adding support symbol layer set properties --- .../mapbox/mapboxgl/MapboxMapController.java | 23 +++++++++++++- example/ios/Podfile | 2 +- ios/Classes/MapboxMapController.swift | 30 +++++++++++++++++++ lib/src/controller.dart | 6 ++++ .../lib/src/mapbox_gl_platform_interface.dart | 6 +++- .../lib/src/method_channel_mapbox_gl.dart | 11 +++++++ .../lib/src/mapbox_web_gl_platform.dart | 7 +++++ 7 files changed, 82 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index c4084232b..6d1879cd5 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -138,7 +138,8 @@ final class MapboxMapController private LatLng dragOrigin; private LatLng dragPrevious; private LatLngBounds bounds = null; - private HashMap lineLayers = new HashMap(); + private HashMap lineLayers = new HashMap(); + private HashMap symbolLayers = new HashMap(); Style.OnStyleLoaded onStyleLoadedCallback = new Style.OnStyleLoaded() { @@ -424,6 +425,8 @@ private void addSymbolLayer( if (enableInteraction) { interactiveFeatureLayerIds.add(layerName); } + + symbolLayers.put(layerName, symbolLayer); } private void setLineLayerProperties(String layerName, PropertyValue[] properties){ @@ -431,6 +434,11 @@ private void setLineLayerProperties(String layerName, PropertyValue[] properties layer.setProperties(properties); } + private void setSymbolLayerProperties(String layerName, PropertyValue[] properties){ + SymbolLayer layer = symbolLayers.get(layerName); + layer.setProperties(properties); + } + private void addLineLayer( String layerName, String sourceName, @@ -1450,6 +1458,18 @@ public void onError(String error) { break; } + case "symbolLayer#setProperties": + { + + final PropertyValue[] properties = LayerPropertyConverter.interpretSymbolLayerProperties(call.argument("properties")); + final String layerId = call.argument("layerId"); + + setSymbolLayerProperties(layerId, properties); + + result.success(null); + + break; + } default: result.notImplemented(); } @@ -2011,6 +2031,7 @@ void removeLayer(String layerId) { style.removeLayer(layerId); interactiveFeatureLayerIds.remove(layerId); lineLayers.remove(layerId); + symbolLayers.remove(layerId); } } diff --git a/example/ios/Podfile b/example/ios/Podfile index d523a681f..14b9abd74 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '9.0' +platform :ios, '11.0' use_frameworks! # CocoaPods analytics sends network stats synchronously affecting flutter build latency. diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 4f3f498de..a9cb3129f 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -29,6 +29,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma private var addedShapesByLayer = [String: MGLShape]() private var lineLayers = [String : MGLLineStyleLayer]() + private var symbolLayers = [String : MGLSymbolStyleLayer]() func view() -> UIView { return mapView @@ -47,6 +48,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma } mapView = MGLMapView(frame: frame) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + mapView.logoView.isHidden = true + mapView.attributionButton.isHidden = true self.registrar = registrar super.init() @@ -416,6 +419,21 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma case .success: result(nil) case let .failure(error): result(error.flutterError) } + + case "symbolLayer#setProperties": + guard let arguments = methodCall.arguments as? [String: Any] else { return } + guard let layerId = arguments["layerId"] as? String else { return } + guard let properties = arguments["properties"] as? [String: String] else { return } + + let editResult = setSymbolLayerProperties( + layerId: layerId, + properties: properties + ) + + switch editResult { + case .success: result(nil) + case let .failure(error): result(error.flutterError) + } case "fillLayer#add": guard let arguments = methodCall.arguments as? [String: Any] else { return } @@ -934,6 +952,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma mapView.style?.removeLayer(layer) interactiveFeatureLayerIds.remove(layerId) lineLayers.removeValue(forKey: layerId) + symbolLayers.removeValue(forKey: layerId) } } @@ -1249,6 +1268,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if enableInteraction { interactiveFeatureLayerIds.insert(layerId) } + + symbolLayers[layerId] = layer; } } return .success(()) @@ -1263,6 +1284,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma return .success(()) } + func setSymbolLayerProperties(layerId: String, properties: [String: String]) -> Result { + let layer : MGLSymbolStyleLayer? = symbolLayers[layerId] + if let symbolLayer = layer { + LayerPropertyConverter.addSymbolProperties(symbolLayer: symbolLayer, properties: properties) + } + + return .success(()) + } + func addLineLayer( sourceId: String, layerId: String, diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 3b9f6408e..759dc1c27 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -393,6 +393,12 @@ class MapboxMapController extends ChangeNotifier { layerId, properties.toJson()); } + Future setSymbolLayerProperties( + String layerId, SymbolLayerProperties properties) async { + await _mapboxGlPlatform.setSymbolLayerProperties( + layerId, properties.toJson()); + } + /// Add a line layer to the map with the given properties /// /// Consider using [addLayer] for an unified layer api. diff --git a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart index 2447bc045..5611f26ab 100644 --- a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart +++ b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart @@ -123,7 +123,11 @@ abstract class MapboxGlPlatform { dynamic filter, required bool enableInteraction}); - Future setLineLayerProperties(String layerId, Map properties); + Future setLineLayerProperties( + String layerId, Map properties); + + Future setSymbolLayerProperties( + String layerId, Map properties); Future addLineLayer( String sourceId, String layerId, Map properties, diff --git a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart index 25e643335..2c229979f 100644 --- a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart +++ b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart @@ -592,6 +592,17 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { }); } + @override + Future setSymbolLayerProperties( + String layerId, Map properties) async { + await _channel + .invokeMapMethod('symbolLayer#setProperties', { + 'layerId': layerId, + 'properties': properties + .map((key, value) => MapEntry(key, jsonEncode(value))) + }); + } + @override Future addLineLayer( String sourceId, String layerId, Map properties, diff --git a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart index 454aea725..291f3e01d 100644 --- a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart +++ b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart @@ -1076,4 +1076,11 @@ class MapboxWebGlPlatform extends MapboxGlPlatform // TODO: implement setLineLayerProperties throw UnimplementedError(); } + + @override + Future setSymbolLayerProperties( + String layerId, Map properties) { + // TODO: implement setSymbolLayerProperties + throw UnimplementedError(); + } } From f21482e10082a3cb58cc203dd4a94197e4812b8c Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Thu, 8 Jun 2023 18:09:21 -0500 Subject: [PATCH 04/11] removing telemetry hide --- ios/Classes/MapboxMapController.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 720ac3b6e..0883aa1e3 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -48,8 +48,6 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma } mapView = MGLMapView(frame: frame) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - mapView.logoView.isHidden = true - mapView.attributionButton.isHidden = true self.registrar = registrar super.init() From f6f31d14dc6b525354973e3e8ef3d363137b6c41 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Tue, 13 Jun 2023 11:41:22 -0500 Subject: [PATCH 05/11] adding circle layer set properties --- .../mapbox/mapboxgl/MapboxMapController.java | 32 +++++++++++++++++-- ios/Classes/MapboxMapController.swift | 28 ++++++++++++++++ lib/src/controller.dart | 6 ++++ .../lib/src/mapbox_gl_platform_interface.dart | 3 ++ .../lib/src/method_channel_mapbox_gl.dart | 11 +++++++ .../lib/src/mapbox_web_gl_platform.dart | 7 ++++ 6 files changed, 85 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index 6d1879cd5..ee12647bb 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -61,6 +61,7 @@ import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.offline.OfflineManager; +import com.mapbox.mapboxsdk.plugins.annotation.Circle; import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin; import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter; import com.mapbox.mapboxsdk.storage.FileSource; @@ -140,6 +141,7 @@ final class MapboxMapController private LatLngBounds bounds = null; private HashMap lineLayers = new HashMap(); private HashMap symbolLayers = new HashMap(); + private HashMap circleLayers = new HashMap(); Style.OnStyleLoaded onStyleLoadedCallback = new Style.OnStyleLoaded() { @@ -431,12 +433,23 @@ private void addSymbolLayer( private void setLineLayerProperties(String layerName, PropertyValue[] properties){ LineLayer layer = lineLayers.get(layerName); - layer.setProperties(properties); + if(layer != null) { + layer.setProperties(properties); + } } private void setSymbolLayerProperties(String layerName, PropertyValue[] properties){ SymbolLayer layer = symbolLayers.get(layerName); - layer.setProperties(properties); + if (layer != null) { + layer.setProperties(properties); + } + } + + private void setCircleLayerProperties(String layerName, PropertyValue[] properties) { + CircleLayer layer = circleLayers.get(layerName); + if(layer != null) { + layer.setProperties(properties); + } } private void addLineLayer( @@ -575,6 +588,8 @@ private void addCircleLayer( if (enableInteraction) { interactiveFeatureLayerIds.add(layerName); } + + circleLayers.put(layerName, circleLayer); } private Expression parseFilter(String filter) { @@ -1470,6 +1485,18 @@ public void onError(String error) { break; } + case "circleLayer#setProperties": + { + + final PropertyValue[] properties = LayerPropertyConverter.interpretSymbolLayerProperties(call.argument("properties")); + final String layerId = call.argument("layerId"); + + setCircleLayerProperties(layerId, properties); + + result.success(null); + + break; + } default: result.notImplemented(); } @@ -2032,6 +2059,7 @@ void removeLayer(String layerId) { interactiveFeatureLayerIds.remove(layerId); lineLayers.remove(layerId); symbolLayers.remove(layerId); + circleLayers.remove(layerId); } } diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 0883aa1e3..e031bc9bb 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -30,6 +30,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma private var lineLayers = [String : MGLLineStyleLayer]() private var symbolLayers = [String : MGLSymbolStyleLayer]() + private var circleLayers = [String: MGLCircleStyleLayer]() func view() -> UIView { return mapView @@ -433,6 +434,21 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma case .success: result(nil) case let .failure(error): result(error.flutterError) } + + case "circleLayer#setProperties": + guard let arguments = methodCall.arguments as? [String: Any] else { return } + guard let layerId = arguments["layerId"] as? String else { return } + guard let properties = arguments["properties"] as? [String: String] else { return } + + let editResult = setCircleLayerProperties( + layerId: layerId, + properties: properties + ) + + switch editResult { + case .success: result(nil) + case let .failure(error): result(error.flutterError) + } case "fillLayer#add": guard let arguments = methodCall.arguments as? [String: Any] else { return } @@ -952,6 +968,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma interactiveFeatureLayerIds.remove(layerId) lineLayers.removeValue(forKey: layerId) symbolLayers.removeValue(forKey: layerId) + circleLayers.removeValue(forKey: layerId) } } @@ -1291,6 +1308,15 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma return .success(()) } + + func setCircleLayerProperties(layerId: String, properties: [String: String]) -> Result { + let layer : MGLCircleStyleLayer? = circleLayers[layerId] + if let circleLayer = layer { + LayerPropertyConverter.addCircleProperties(circleLayer: circleLayer, properties: properties) + } + + return .success(()) + } func addLineLayer( sourceId: String, @@ -1463,6 +1489,8 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if enableInteraction { interactiveFeatureLayerIds.insert(layerId) } + + circleLayers[layerId] = layer; } } return .success(()) diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 759dc1c27..4ecec53cb 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -399,6 +399,12 @@ class MapboxMapController extends ChangeNotifier { layerId, properties.toJson()); } + Future setCircleLayerProperties( + String layerId, SymbolLayerProperties properties) async { + await _mapboxGlPlatform.setCircleLayerProperties( + layerId, properties.toJson()); + } + /// Add a line layer to the map with the given properties /// /// Consider using [addLayer] for an unified layer api. diff --git a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart index 5611f26ab..20f4a4395 100644 --- a/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart +++ b/mapbox_gl_platform_interface/lib/src/mapbox_gl_platform_interface.dart @@ -129,6 +129,9 @@ abstract class MapboxGlPlatform { Future setSymbolLayerProperties( String layerId, Map properties); + Future setCircleLayerProperties( + String layerId, Map properties); + Future addLineLayer( String sourceId, String layerId, Map properties, {String? belowLayerId, diff --git a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart index 6c77e4bfd..6f1bde8e7 100644 --- a/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart +++ b/mapbox_gl_platform_interface/lib/src/method_channel_mapbox_gl.dart @@ -608,6 +608,17 @@ class MethodChannelMapboxGl extends MapboxGlPlatform { }); } + @override + Future setCircleLayerProperties( + String layerId, Map properties) async { + await _channel + .invokeMapMethod('circleLayer#setProperties', { + 'layerId': layerId, + 'properties': properties + .map((key, value) => MapEntry(key, jsonEncode(value))) + }); + } + @override Future addLineLayer( String sourceId, String layerId, Map properties, diff --git a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart index 291f3e01d..6665af477 100644 --- a/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart +++ b/mapbox_gl_web/lib/src/mapbox_web_gl_platform.dart @@ -1083,4 +1083,11 @@ class MapboxWebGlPlatform extends MapboxGlPlatform // TODO: implement setSymbolLayerProperties throw UnimplementedError(); } + + @override + Future setCircleLayerProperties( + String layerId, Map properties) { + // TODO: implement setCircleLayerProperties + throw UnimplementedError(); + } } From 885dafa2d97b9b67059f8f2d509800d388e9594d Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Tue, 13 Jun 2023 11:51:17 -0500 Subject: [PATCH 06/11] symbol to circle --- lib/src/controller.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 4ecec53cb..db2f7a9f4 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -400,7 +400,7 @@ class MapboxMapController extends ChangeNotifier { } Future setCircleLayerProperties( - String layerId, SymbolLayerProperties properties) async { + String layerId, CircleLayerProperties properties) async { await _mapboxGlPlatform.setCircleLayerProperties( layerId, properties.toJson()); } From 39f61ef34e3b2b815aaf09e260a07372f8cd8756 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Thu, 22 Jun 2023 15:31:57 -0500 Subject: [PATCH 07/11] add style layer --- ios/Classes/MapboxMapController.swift | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index e031bc9bb..2e8461e7a 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -805,7 +805,7 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma case let .failure(error): result(error.flutterError) } - case "map#setVisibility": + case "style#setVisibility": guard let arguments = methodCall.arguments as? [String: Any] else { return } guard let layerId = arguments["layerId"] as? String else { return } guard let isVisible = arguments["isVisible"] as? Bool else { return } diff --git a/pubspec.yaml b/pubspec.yaml index ea086f30b..6b2ec5694 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mapbox_gl description: A Flutter plugin for integrating Mapbox Maps inside a Flutter application on Android, iOS and web platfroms. -version: 0.16.0 +version: 0.16.1 homepage: https://github.com/tobrun/flutter-mapbox-gl dependencies: From b658466723726092c8f30c8423cfe22afc7492eb Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Thu, 22 Jun 2023 17:42:03 -0500 Subject: [PATCH 08/11] on end handler --- ios/Classes/MapboxMapController.swift | 5 +++-- pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 2e8461e7a..20a0b628b 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -339,8 +339,9 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma if let duration = arguments["duration"] as? TimeInterval { mapView.setCamera(camera, withDuration: TimeInterval(duration / 1000), animationTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName - .easeInEaseOut)) - result(nil) + .easeInEaseOut), completionHandler: { + result(nil) + }) } else { mapView.setCamera(camera, animated: true) } diff --git a/pubspec.yaml b/pubspec.yaml index 6b2ec5694..307be6d9e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mapbox_gl description: A Flutter plugin for integrating Mapbox Maps inside a Flutter application on Android, iOS and web platfroms. -version: 0.16.1 +version: 0.16.2 homepage: https://github.com/tobrun/flutter-mapbox-gl dependencies: From 3e1755b335b3e5e940fe2bf8f3b03cd2102379f0 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Thu, 22 Jun 2023 18:19:05 -0500 Subject: [PATCH 09/11] adding guard --- ios/Classes/MapboxMapController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index 20a0b628b..f91425541 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -344,9 +344,10 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma }) } else { mapView.setCamera(camera, animated: true) + result(nil) } } - result(nil) + case "symbolLayer#add": guard let arguments = methodCall.arguments as? [String: Any] else { return } From c2e52abbe7727cc10d4f4f30cb0209a9edc8f007 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Fri, 14 Jul 2023 17:46:09 -0500 Subject: [PATCH 10/11] fix on ios bounds --- ios/Classes/Convert.swift | 47 +++++++++++++++++++++------ ios/Classes/MapboxMapController.swift | 9 +++-- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/ios/Classes/Convert.swift b/ios/Classes/Convert.swift index fb1a521c5..1a3152c8f 100644 --- a/ios/Classes/Convert.swift +++ b/ios/Classes/Convert.swift @@ -72,7 +72,7 @@ class Convert { } } - class func parseCameraUpdate(cameraUpdate: [Any], mapView: MGLMapView) -> MGLMapCamera? { + class func parseCameraUpdate(cameraUpdate: [Any], mapView: MGLMapView, completionHandler: (() -> Void)?, duration: TimeInterval?) -> MGLMapCamera? { guard let type = cameraUpdate[0] as? String else { return nil } switch type { case "newCameraPosition": @@ -89,15 +89,42 @@ class Convert { guard let paddingTop = cameraUpdate[3] as? CGFloat else { return nil } guard let paddingRight = cameraUpdate[4] as? CGFloat else { return nil } guard let paddingBottom = cameraUpdate[5] as? CGFloat else { return nil } - return mapView.cameraThatFitsCoordinateBounds( - MGLCoordinateBounds.fromArray(bounds), - edgePadding: UIEdgeInsets( - top: paddingTop, - left: paddingLeft, - bottom: paddingBottom, - right: paddingRight - ) - ) + + let newBounds: MGLCoordinateBounds = MGLCoordinateBounds.fromArray(bounds) + + let coordinates: [CLLocationCoordinate2D] = [ + CLLocationCoordinate2D(latitude: newBounds.ne.latitude, longitude: newBounds.sw.longitude), + newBounds.sw, + CLLocationCoordinate2D(latitude: newBounds.sw.latitude, longitude: newBounds.ne.longitude), + newBounds.ne + ] + + let padding : UIEdgeInsets = UIEdgeInsets( + top: paddingTop, + left: paddingLeft, + bottom: paddingBottom, + right: paddingRight + ) + + + if let animDur = duration { + mapView.setVisibleCoordinates(coordinates, + count: UInt(coordinates.count), edgePadding: padding, direction: mapView.direction, + duration: TimeInterval(animDur / 1000), + animationTimingFunction: CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut), + completionHandler: { + if let completion = completionHandler { + completion() + } + }) + } else { + mapView.setVisibleCoordinates(coordinates, count: UInt(coordinates.count), edgePadding: padding, animated: true) + if let completion = completionHandler { + completion() + } + } + + return nil case "newLatLngZoom": guard let coordinate = cameraUpdate[1] as? [Double] else { return nil } guard let zoom = cameraUpdate[2] as? Double else { return nil } diff --git a/ios/Classes/MapboxMapController.swift b/ios/Classes/MapboxMapController.swift index f91425541..45c3f53da 100644 --- a/ios/Classes/MapboxMapController.swift +++ b/ios/Classes/MapboxMapController.swift @@ -325,7 +325,9 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma guard let arguments = methodCall.arguments as? [String: Any] else { return } guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return } if let camera = Convert - .parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) + .parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView, completionHandler: { + result(nil) + }, duration: arguments["duration"] as? TimeInterval) { mapView.setCamera(camera, animated: false) } @@ -333,8 +335,11 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma case "camera#animate": guard let arguments = methodCall.arguments as? [String: Any] else { return } guard let cameraUpdate = arguments["cameraUpdate"] as? [Any] else { return } + if let camera = Convert - .parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView) + .parseCameraUpdate(cameraUpdate: cameraUpdate, mapView: mapView, completionHandler: { + result(nil) + }, duration: arguments["duration"] as? TimeInterval) { if let duration = arguments["duration"] as? TimeInterval { mapView.setCamera(camera, withDuration: TimeInterval(duration / 1000), From a629a23b5c4f76a4103b5340c20a9d1d717ab954 Mon Sep 17 00:00:00 2001 From: Martin Alejandro Escobar Espinel Date: Fri, 20 Oct 2023 15:23:20 -0500 Subject: [PATCH 11/11] adding padding to camera update --- .../java/com/mapbox/mapboxgl/Convert.java | 8 ++++++ .../lib/src/camera.dart | 26 +++++++++++++++++-- pubspec.lock | 18 +++++++++---- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/mapbox/mapboxgl/Convert.java b/android/src/main/java/com/mapbox/mapboxgl/Convert.java index f22b9d068..ffc273aa6 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/Convert.java +++ b/android/src/main/java/com/mapbox/mapboxgl/Convert.java @@ -36,6 +36,14 @@ static CameraPosition toCameraPosition(Object o) { builder.target(toLatLng(data.get("target"))); builder.tilt(toFloat(data.get("tilt"))); builder.zoom(toFloat(data.get("zoom"))); + HashMap paddingMap = ((HashMap) data.get("padding")); + if(paddingMap != null) { + builder.padding(toDouble(paddingMap.get("left")), + toDouble(paddingMap.get("top")), + toDouble(paddingMap.get("right")), + toDouble(paddingMap.get("bottom"))); + } + return builder.build(); } diff --git a/mapbox_gl_platform_interface/lib/src/camera.dart b/mapbox_gl_platform_interface/lib/src/camera.dart index 3094923aa..f69b8640a 100644 --- a/mapbox_gl_platform_interface/lib/src/camera.dart +++ b/mapbox_gl_platform_interface/lib/src/camera.dart @@ -13,6 +13,7 @@ class CameraPosition { required this.target, this.tilt = 0.0, this.zoom = 0.0, + this.padding, }); /// The camera's bearing in degrees, measured clockwise from north. @@ -48,11 +49,21 @@ class CameraPosition { /// will be silently clamped to the supported range. final double zoom; + final EdgeInsets? padding; + dynamic toMap() => { 'bearing': bearing, 'target': target.toJson(), 'tilt': tilt, 'zoom': zoom, + 'padding': padding != null + ? { + 'top': padding!.top, + 'bottom': padding!.bottom, + 'left': padding!.left, + 'right': padding!.right, + } + : null, }; @visibleForTesting @@ -60,11 +71,21 @@ class CameraPosition { if (json == null) { return null; } + var mapPadding = json['padding'] as Map?; + return CameraPosition( bearing: json['bearing'], target: LatLng._fromJson(json['target']), tilt: json['tilt'], zoom: json['zoom'], + padding: mapPadding != null + ? EdgeInsets.fromLTRB( + mapPadding['left'], + mapPadding['top'], + mapPadding['right'], + mapPadding['bottom'], + ) + : null, ); } @@ -76,7 +97,8 @@ class CameraPosition { return bearing == typedOther.bearing && target == typedOther.target && tilt == typedOther.tilt && - zoom == typedOther.zoom; + zoom == typedOther.zoom && + padding == padding; } @override @@ -84,7 +106,7 @@ class CameraPosition { @override String toString() => - 'CameraPosition(bearing: $bearing, target: $target, tilt: $tilt, zoom: $zoom)'; + 'CameraPosition(bearing: $bearing, target: $target, tilt: $tilt, zoom: $zoom, padding: ${padding.toString()})'; } /// Defines a camera move, supporting absolute moves as well as moves relative diff --git a/pubspec.lock b/pubspec.lock index 4fc2653e3..2bb16fe3a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -21,10 +21,10 @@ packages: dependency: "direct main" description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687 url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.17.2" crypto: dependency: transitive description: @@ -85,10 +85,10 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.5.0" meta: dependency: transitive description: @@ -134,6 +134,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10 + url: "https://pub.dev" + source: hosted + version: "0.1.4-beta" xml: dependency: transitive description: @@ -143,5 +151,5 @@ packages: source: hosted version: "5.1.0" sdks: - dart: ">=3.0.0-0 <4.0.0" + dart: ">=3.1.0-185.0.dev <4.0.0" flutter: ">=2.0.0"