@@ -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) ,
@@ -170,7 +170,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
170170 if let langStr = Locale . current. languageCode {
171171 setMapLanguage ( language: langStr)
172172 }
173-
173+
174174 result ( nil )
175175 case " map#updateContentInsets " :
176176 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
@@ -316,7 +316,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
316316 case " camera#move " :
317317 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
318318 guard let cameraUpdate = arguments [ " cameraUpdate " ] as? [ Any ] else { return }
319-
319+
320320 if let camera = Convert . parseCameraUpdate ( cameraUpdate: cameraUpdate, mapView: mapView) {
321321 mapView. setCamera ( camera, animated: false )
322322 }
@@ -325,12 +325,12 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
325325 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
326326 guard let cameraUpdate = arguments [ " cameraUpdate " ] as? [ Any ] else { return }
327327 guard let camera = Convert . parseCameraUpdate ( cameraUpdate: cameraUpdate, mapView: mapView) else { return }
328-
329-
328+
329+
330330 let completion = {
331331 result ( nil )
332332 }
333-
333+
334334 if let duration = arguments [ " duration " ] as? TimeInterval {
335335 if let padding = Convert . parseLatLngBoundsPadding ( cameraUpdate) {
336336 mapView. fly ( to: camera, edgePadding: padding, withDuration: duration / 1000 , completionHandler: completion)
@@ -537,7 +537,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
537537 properties: properties
538538 )
539539 result ( nil )
540-
540+
541541 case " heatmapLayer#add " :
542542 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
543543 guard let sourceId = arguments [ " sourceId " ] as? String else { return }
@@ -840,11 +840,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
840840 }
841841 layer. isVisible = visible
842842 result ( nil )
843-
843+
844844 case " map#querySourceFeatures " :
845845 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
846846 guard let sourceId = arguments [ " sourceId " ] as? String else { return }
847-
847+
848848 var sourceLayerId = Set < String > ( )
849849 if let layerId = arguments [ " sourceLayerId " ] as? String {
850850 sourceLayerId. insert ( layerId)
@@ -853,10 +853,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
853853 if let filter = arguments [ " filter " ] as? [ Any ] {
854854 filterExpression = NSPredicate ( mglJSONObject: filter)
855855 }
856-
856+
857857 var reply = [ String: NSObject] ( )
858858 var features : [ MLNFeature ] = [ ]
859-
859+
860860 guard let style = mapView. style else { return }
861861 if let source = style. source ( withIdentifier: sourceId) {
862862 if let vectorSource = source as? MLNVectorTileSource {
@@ -865,7 +865,7 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
865865 features = shapeSource. features ( matching: filterExpression)
866866 }
867867 }
868-
868+
869869 var featuresJson = [ String] ( )
870870 for feature in features {
871871 let dictionary = feature. geoJSONDictionary ( )
@@ -883,11 +883,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
883883
884884 case " style#getLayerIds " :
885885 var layerIds = [ String] ( )
886-
886+
887887 guard let style = mapView. style else { return }
888-
888+
889889 style. layers. forEach { layer in layerIds. append ( layer. identifier) }
890-
890+
891891 var reply = [ String: NSObject] ( )
892892 reply [ " layers " ] = layerIds as NSObject
893893 result ( reply)
@@ -902,18 +902,18 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
902902 var reply = [ String: NSObject] ( )
903903 reply [ " sources " ] = sourceIds as NSObject
904904 result ( reply)
905-
905+
906906 case " style#getFilter " :
907907 guard let arguments = methodCall. arguments as? [ String : Any ] else { return }
908908 guard let layerId = arguments [ " layerId " ] as? String else { return }
909-
909+
910910 guard let style = mapView. style else { return }
911911 guard let layer = style. layer ( withIdentifier: layerId) else { return }
912-
912+
913913 var currentLayerFilter : String = " "
914914 if let vectorLayer = layer as? MLNVectorStyleLayer {
915915 if let layerFilter = vectorLayer. predicate {
916-
916+
917917 let jsonExpression = layerFilter. mgl_jsonExpressionObject
918918 if let data = try ? JSONSerialization . data ( withJSONObject: jsonExpression, options: [ ] ) {
919919 currentLayerFilter = String ( data: data, encoding: String . Encoding. utf8) ?? " "
@@ -925,11 +925,11 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
925925 ) . flutterError)
926926 return ;
927927 }
928-
928+
929929 var reply = [ String: NSObject] ( )
930930 reply [ " filter " ] = currentLayerFilter as NSObject
931931 result ( reply)
932-
932+
933933 default :
934934 result ( FlutterMethodNotImplemented)
935935 }
@@ -967,16 +967,16 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
967967 private func getCamera( ) -> MLNMapCamera ? {
968968 return trackCameraPosition ? mapView. camera : nil
969969 }
970-
970+
971971 private func setMapLanguage( language: String ) {
972972 self . mapView. setMapLanguage ( language)
973973 }
974974
975975 /*
976976 * Scan layers from top to bottom and return the first matching feature
977977 */
978- private func firstFeatureOnLayers( at: CGPoint ) -> ( feature : MLNFeature ? , layerId : String ? ) {
979- guard let style = mapView. style else { return ( nil , nil ) }
978+ private func firstFeatureOnLayers( at: CGPoint ) -> MLNFeature ? {
979+ guard let style = mapView. style else { return nil }
980980
981981 // get layers in order (interactiveFeatureLayerIds is unordered)
982982 let clickableLayers = style. layers. filter { layer in
@@ -989,10 +989,10 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
989989 styleLayerIdentifiers: [ layer. identifier]
990990 )
991991 if let feature = features. first {
992- return ( feature, layer . identifier )
992+ return feature
993993 }
994994 }
995- return ( nil , nil )
995+ return nil
996996 }
997997
998998 /*
@@ -1004,15 +1004,13 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10041004 let point = sender. location ( in: mapView)
10051005 let coordinate = mapView. convert ( point, toCoordinateFrom: mapView)
10061006
1007- let result = firstFeatureOnLayers ( at: point)
1008- if let feature = result. feature {
1007+ if let feature = firstFeatureOnLayers ( at: point) {
10091008 channel? . invokeMethod ( " feature#onTap " , arguments: [
10101009 " id " : feature. identifier,
10111010 " x " : point. x,
10121011 " y " : point. y,
10131012 " lng " : coordinate. longitude,
10141013 " lat " : coordinate. latitude,
1015- " layerId " : result. layerId,
10161014 ] )
10171015 } else {
10181016 channel? . invokeMethod ( " map#onMapClick " , arguments: [
@@ -1055,23 +1053,22 @@ class MapLibreMapController: NSObject, FlutterPlatformView, MLNMapViewDelegate,
10551053 let point = sender. location ( in: mapView)
10561054 let coordinate = mapView. convert ( point, toCoordinateFrom: mapView)
10571055
1058- if dragFeature == nil , began, sender. numberOfTouches == 1 {
1059- let result = firstFeatureOnLayers ( at: point)
1060- if let feature = result. feature,
1061- let draggable = feature. attribute ( forKey: " draggable " ) as? Bool ,
1062- draggable {
1063- sender. state = UIGestureRecognizer . State. began
1064- dragFeature = feature
1065- originDragCoordinate = coordinate
1066- previousDragCoordinate = coordinate
1067- mapView. allowsScrolling = false
1068- let eventType = " start "
1069- invokeFeatureDrag ( point, coordinate, eventType)
1070- for gestureRecognizer in mapView. gestureRecognizers! {
1071- if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1072- gestureRecognizer. addTarget ( self , action: #selector( handleMapPan) )
1073- break
1074- }
1056+ if dragFeature == nil , began, sender. numberOfTouches == 1 ,
1057+ let feature = firstFeatureOnLayers ( at: point) ,
1058+ let draggable = feature. attribute ( forKey: " draggable " ) as? Bool ,
1059+ draggable
1060+ {
1061+ sender. state = UIGestureRecognizer . State. began
1062+ dragFeature = feature
1063+ originDragCoordinate = coordinate
1064+ previousDragCoordinate = coordinate
1065+ mapView. allowsScrolling = false
1066+ let eventType = " start "
1067+ invokeFeatureDrag ( point, coordinate, eventType)
1068+ for gestureRecognizer in mapView. gestureRecognizers! {
1069+ if let _ = gestureRecognizer as? UIPanGestureRecognizer {
1070+ gestureRecognizer. addTarget ( self , action: #selector( handleMapPan) )
1071+ break
10751072 }
10761073 }
10771074 }
0 commit comments