@@ -71,9 +71,9 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
7171 longPress. require ( toFail: recognizer)
7272 }
7373 var longPressRecognizerAdded = false
74-
74+
7575 if let args = args as? [ String : Any ] {
76-
76+
7777 Convert . interpretMapLibreMapOptions ( options: args [ " options " ] , delegate: self )
7878 if let initialCameraPosition = args [ " initialCameraPosition " ] as? [ String : Any ] ,
7979 let camera = MLNMapCamera . fromDict ( initialCameraPosition, mapView: mapView) ,
@@ -179,7 +179,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
179179 if let langStr = Locale . current. languageCode {
180180 setMapLanguage ( language: langStr)
181181 }
182-
182+
183183 result ( nil )
184184 case " map#updateContentInsets " :
185185 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
@@ -325,7 +325,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
325325 case " camera#move " :
326326 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
327327 guard let cameraUpdate = arguments [ " cameraUpdate " ] as? [ Any ] else { return }
328-
328+
329329 if let camera = Convert . parseCameraUpdate ( cameraUpdate: cameraUpdate, mapView: mapView) {
330330 mapView. setCamera ( camera, animated: false )
331331 }
@@ -334,12 +334,12 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
334334 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
335335 guard let cameraUpdate = arguments [ " cameraUpdate " ] as? [ Any ] else { return }
336336 guard let camera = Convert . parseCameraUpdate ( cameraUpdate: cameraUpdate, mapView: mapView) else { return }
337-
338-
337+
338+
339339 let completion = {
340340 result ( nil )
341341 }
342-
342+
343343 if let duration = arguments [ " duration " ] as? TimeInterval {
344344 if let padding = Convert . parseLatLngBoundsPadding ( cameraUpdate) {
345345 mapView. fly ( to: camera, edgePadding: padding, withDuration: duration / 1000 , completionHandler: completion)
@@ -546,7 +546,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
546546 properties: properties
547547 )
548548 result ( nil )
549-
549+
550550 case " heatmapLayer#add " :
551551 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
552552 guard let sourceId = arguments [ " sourceId " ] as? String else { return }
@@ -849,11 +849,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
849849 }
850850 layer. isVisible = visible
851851 result ( nil )
852-
852+
853853 case " map#querySourceFeatures " :
854854 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
855855 guard let sourceId = arguments [ " sourceId " ] as? String else { return }
856-
856+
857857 var sourceLayerId = Set < String > ( )
858858 if let layerId = arguments [ " sourceLayerId " ] as? String {
859859 sourceLayerId. insert ( layerId)
@@ -862,10 +862,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
862862 if let filter = arguments [ " filter " ] as? [ Any ] {
863863 filterExpression = NSPredicate ( mglJSONObject: filter)
864864 }
865-
865+
866866 var reply = [ String: NSObject] ( )
867867 var features : [ MLNFeature ] = [ ]
868-
868+
869869 guard let style = mapView. style else { return }
870870 if let source = style. source ( withIdentifier: sourceId) {
871871 if let vectorSource = source as? MLNVectorTileSource {
@@ -874,7 +874,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
874874 features = shapeSource. features ( matching: filterExpression)
875875 }
876876 }
877-
877+
878878 var featuresJson = [ String] ( )
879879 for feature in features {
880880 let dictionary = feature. geoJSONDictionary ( )
@@ -892,11 +892,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
892892
893893 case " style#getLayerIds " :
894894 var layerIds = [ String] ( )
895-
895+
896896 guard let style = mapView. style else { return }
897-
897+
898898 style. layers. forEach { layer in layerIds. append ( layer. identifier) }
899-
899+
900900 var reply = [ String: NSObject] ( )
901901 reply [ " layers " ] = layerIds as NSObject
902902 result ( reply)
@@ -911,18 +911,18 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
911911 var reply = [ String: NSObject] ( )
912912 reply [ " sources " ] = sourceIds as NSObject
913913 result ( reply)
914-
914+
915915 case " style#getFilter " :
916916 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
917917 guard let layerId = arguments [ " layerId " ] as? String else { return }
918-
918+
919919 guard let style = mapView. style else { return }
920920 guard let layer = style. layer ( withIdentifier: layerId) else { return }
921-
921+
922922 var currentLayerFilter : String = " "
923923 if let vectorLayer = layer as? MLNVectorStyleLayer {
924924 if let layerFilter = vectorLayer. predicate {
925-
925+
926926 let jsonExpression = layerFilter. mgl_jsonExpressionObject
927927 if let data = try ? JSONSerialization . data ( withJSONObject: jsonExpression, options: [ ] ) {
928928 currentLayerFilter = String ( data: data, encoding: String . Encoding. utf8) ?? " "
@@ -934,11 +934,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
934934 ) . flutterError)
935935 return ;
936936 }
937-
937+
938938 var reply = [ String: NSObject] ( )
939939 reply [ " filter " ] = currentLayerFilter as NSObject
940940 result ( reply)
941-
941+
942942 default :
943943 result ( FlutterMethodNotImplemented)
944944 }
@@ -976,16 +976,16 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
976976 private func getCamera( ) -> MLNMapCamera ? {
977977 return trackCameraPosition ? mapView. camera : nil
978978 }
979-
979+
980980 private func setMapLanguage( language: String ) {
981981 self . mapView. setMapLanguage ( language)
982982 }
983983
984984 /*
985985 * Scan layers from top to bottom and return the first matching feature
986986 */
987- private func firstFeatureOnLayers( at: CGPoint ) -> MLNFeature ? {
988- guard let style = mapView. style else { return nil }
987+ private func firstFeatureOnLayers( at: CGPoint ) -> ( feature : MLNFeature ? , layerId : String ? ) {
988+ guard let style = mapView. style else { return ( nil , nil ) }
989989
990990 // get layers in order (interactiveFeatureLayerIds is unordered)
991991 let clickableLayers = style. layers. filter { layer in
@@ -998,10 +998,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
998998 styleLayerIdentifiers: [ layer. identifier]
999999 )
10001000 if let feature = features. first {
1001- return feature
1001+ return ( feature, layer . identifier )
10021002 }
10031003 }
1004- return nil
1004+ return ( nil , nil )
10051005 }
10061006
10071007 /*
@@ -1013,13 +1013,15 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10131013 let point = sender. location ( in: mapView)
10141014 let coordinate = mapView. convert ( point, toCoordinateFrom: mapView)
10151015
1016- if let feature = firstFeatureOnLayers ( at: point) {
1016+ let result = firstFeatureOnLayers ( at: point)
1017+ if let feature = result. feature {
10171018 channel? . invokeMethod ( " feature#onTap " , arguments: [
10181019 " id " : feature. identifier,
10191020 " x " : point. x,
10201021 " y " : point. y,
10211022 " lng " : coordinate. longitude,
10221023 " lat " : coordinate. latitude,
1024+ " layerId " : result. layerId,
10231025 ] )
10241026 } else {
10251027 channel? . invokeMethod ( " map#onMapClick " , arguments: [
@@ -1062,22 +1064,23 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10621064 let point = sender. location ( in: mapView)
10631065 let coordinate = mapView. convert ( point, toCoordinateFrom: mapView)
10641066
1065- if dragFeature == nil , began, sender. numberOfTouches == 1 ,
1066- let feature = firstFeatureOnLayers ( at: point) ,
1067- let draggable = feature. attribute ( forKey: " draggable " ) as? Bool ,
1068- draggable
1069- {
1070- sender. state = UIGestureRecognizer . State. began
1071- dragFeature = feature
1072- originDragCoordinate = coordinate
1073- previousDragCoordinate = coordinate
1074- mapView. allowsScrolling = false
1075- let eventType = " start "
1076- invokeFeatureDrag ( point, coordinate, eventType)
1077- for gestureRecognizer in mapView. gestureRecognizers! {
1078- if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1079- gestureRecognizer. addTarget ( self , action: #selector( handleMapPan) )
1080- break
1067+ if dragFeature == nil , began, sender. numberOfTouches == 1 {
1068+ let result = firstFeatureOnLayers ( at: point)
1069+ if let feature = result. feature,
1070+ let draggable = feature. attribute ( forKey: " draggable " ) as? Bool ,
1071+ draggable {
1072+ sender. state = UIGestureRecognizer . State. began
1073+ dragFeature = feature
1074+ originDragCoordinate = coordinate
1075+ previousDragCoordinate = coordinate
1076+ mapView. allowsScrolling = false
1077+ let eventType = " start "
1078+ invokeFeatureDrag ( point, coordinate, eventType)
1079+ for gestureRecognizer in mapView. gestureRecognizers! {
1080+ if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1081+ gestureRecognizer. addTarget ( self , action: #selector( handleMapPan) )
1082+ break
1083+ }
10811084 }
10821085 }
10831086 }
0 commit comments