diff --git a/CHANGELOG.md b/CHANGELOG.md index 03779b7..57e633c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.1.1 + +* Fixed issue where `OnMapReadyListener` would not be invoked during the initial load on iOS. + ## 2.1.0 * Updated MapsIndoors SDK to 4.2.13 diff --git a/LICENSE b/LICENSE index fcccc54..75757d5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,28 +1,11 @@ -BSD 3-Clause License +Copyright 2023 Mapspeople -Copyright (c) 2024, MapsPeople A/S +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/ios/Classes/MapsIndoorsView.swift b/ios/Classes/MapsIndoorsView.swift index 4425f31..4a47ce6 100644 --- a/ios/Classes/MapsIndoorsView.swift +++ b/ios/Classes/MapsIndoorsView.swift @@ -35,9 +35,8 @@ class FLNativeViewFactory: NSObject, FlutterPlatformViewFactory { class FLNativeView: NSObject, FlutterPlatformView, MPMapControlDelegate, FlutterMapView { - private var _GMSView: GMSMapView? - private let MP_APIKEY = "mapspeople" - private var mapsIndoorsData: MapsIndoorsData? = nil + private var _GMSView: GMSMapView + private var mapsIndoorsData: MapsIndoorsData private var args: Any? = nil private let googleApiKey = Bundle.main.object(forInfoDictionaryKey: "GoogleMapsAPIKey") as? String ?? "" @@ -47,15 +46,14 @@ class FLNativeView: NSObject, FlutterPlatformView, MPMapControlDelegate, Flutter binaryMessenger messenger: FlutterBinaryMessenger?, mapsIndoorsData: MapsIndoorsData ) { - super.init() - self.args = args self.mapsIndoorsData = mapsIndoorsData; GMSServices.provideAPIKey(googleApiKey) _GMSView = GMSMapView(frame: frame, camera: GMSCameraPosition()) + super.init() if (MPMapsIndoors.shared.ready) { - mapsIndoorsData.mapControlMethodChannel?.invokeMethod("create", arguments: args) + mapsIndoorsIsReady() }else { mapsIndoorsData.delegate.append(MIReadyDelegate(view: self)) } @@ -63,29 +61,25 @@ class FLNativeView: NSObject, FlutterPlatformView, MPMapControlDelegate, Flutter mapsIndoorsData.mapView = self // To fix an odd bug, where the map center would be in the top left corner of the view. // It should be the center of the view. - _GMSView?.moveCamera(GMSCameraUpdate.setCamera(GMSCameraPosition())) + _GMSView.moveCamera(GMSCameraUpdate.setCamera(GMSCameraPosition())) } func view() -> UIView { - return _GMSView! + return _GMSView } func mapsIndoorsIsReady() { - if (mapsIndoorsData?.mapView != nil) { - DispatchQueue.main.async { [self] in - let config = MPMapConfig(gmsMapView: _GMSView!, googleApiKey: googleApiKey) - let mapControl = MPMapsIndoors.createMapControl(mapConfig: config) - if (mapControl != nil) { - //TODO: parse config - mapControl?.showUserPosition = true - //pretend config^ - mapsIndoorsData!.mapControl = mapControl - mapsIndoorsData?.directionsRenderer = nil - Task { - //Momentary code just to get the map to a place where we show data on the map - mapControl?.goTo(entity: await MPMapsIndoors.shared.venues()[0]) - } - } + guard mapsIndoorsData.mapView != nil else { return } + + DispatchQueue.main.async { [self] in + let config = MPMapConfig(gmsMapView: _GMSView, googleApiKey: googleApiKey) + if let mapControl = MPMapsIndoors.createMapControl(mapConfig: config) { + //TODO: parse config + mapControl.showUserPosition = true + //pretend config^ + mapsIndoorsData.mapControl = mapControl + mapsIndoorsData.directionsRenderer = nil + mapsIndoorsData.mapControlMethodChannel?.invokeMethod("create", arguments: nil) } } } @@ -94,14 +88,14 @@ class FLNativeView: NSObject, FlutterPlatformView, MPMapControlDelegate, Flutter guard let update = makeGMSCameraUpdate(cameraUpdate: cameraUpdate) else { throw MPError.unknownError } - _GMSView?.animate(with: update) + _GMSView.animate(with: update) } func moveCamera(cameraUpdate: CameraUpdate) throws { guard let update = makeGMSCameraUpdate(cameraUpdate: cameraUpdate) else { throw MPError.unknownError } - _GMSView?.moveCamera(update) + _GMSView.moveCamera(update) } func makeGMSCameraUpdate(cameraUpdate: CameraUpdate) -> GMSCameraUpdate? { diff --git a/ios/Classes/core/MapsIndoorsData.swift b/ios/Classes/core/MapsIndoorsData.swift index 0b42691..50b947c 100644 --- a/ios/Classes/core/MapsIndoorsData.swift +++ b/ios/Classes/core/MapsIndoorsData.swift @@ -20,81 +20,44 @@ protocol LiveDataDelegate: AnyObject { } public class MapsIndoorsData: NSObject { - - private var _mapView: FlutterMapView? = nil - private var _mapControl: MPMapControl? = nil - private var _mapControlMethodChannel: FlutterMethodChannel? = nil - private var _mapControlFloorSelector: FlutterMethodChannel? = nil - private var _mapsIndoorsMethodChannel: FlutterMethodChannel? = nil - private var _directionsRendererMethodChannel: FlutterMethodChannel? = nil - private var _positionProvider: FlutterPositionProvider? = nil - private var _directionsRenderer: MPDirectionsRenderer? = nil - private var _floorSelector: CustomFloorSelector? = nil - + var delegate: [MapsIndoorsReadyDelegate] = [] var liveDataDelegate: LiveDataDelegate? var mapControlListenerDelegate: MapControlDelegate? - var mapView: FlutterMapView? { - set { _mapView = newValue } - get { return _mapView } - } + var mapView: FlutterMapView? - var mapControl: MPMapControl? { - set { _mapControl = newValue } - get { return _mapControl } - } + var mapControl: MPMapControl? var isMapControlInitialized: Bool { - get { return _mapControl == nil } + get { mapControl != nil } } var isMapsIndoorsReady: Bool { - get { return MPMapsIndoors.shared.ready } + get { MPMapsIndoors.shared.ready } } func mapsIndoorsReady(error: MPError?) { - delegate.forEach { onReady in - onReady.isReady(error: error) + delegate.forEach { + $0.isReady(error: error) } } - var mapControlMethodChannel: FlutterMethodChannel? { - set { _mapControlMethodChannel = newValue } - get { return _mapControlMethodChannel } - } + var mapControlMethodChannel: FlutterMethodChannel? - var directionsRendererMethodChannel: FlutterMethodChannel? { - set { _directionsRendererMethodChannel = newValue } - get { return _directionsRendererMethodChannel } - } + var directionsRendererMethodChannel: FlutterMethodChannel? - var mapsIndoorsMethodChannel: FlutterMethodChannel? { - set { _mapsIndoorsMethodChannel = newValue } - get { return _mapsIndoorsMethodChannel } - } + var mapsIndoorsMethodChannel: FlutterMethodChannel? - var mapControlFloorSelector: FlutterMethodChannel? { - set { _mapControlFloorSelector = newValue } - get { return _mapControlFloorSelector } - } + var mapControlFloorSelector: FlutterMethodChannel? - var positionProvider: FlutterPositionProvider? { - set { _positionProvider = newValue } - get { return _positionProvider } - } + var positionProvider: FlutterPositionProvider? - var directionsRenderer: MPDirectionsRenderer? { - set { _directionsRenderer = newValue } - get { return _directionsRenderer } - } + var directionsRenderer: MPDirectionsRenderer? - var floorSelector: MPCustomFloorSelector? { - set { _floorSelector = newValue as? CustomFloorSelector } - get { return _floorSelector } - } + var floorSelector: MPCustomFloorSelector? } public class CustomFloorSelector: UIView, MPCustomFloorSelector { diff --git a/pubspec.yaml b/pubspec.yaml index 9325f31..612b540 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mapsindoors_googlemaps_ios description: iOS implementation of the mapsindoors plugin -version: 2.1.0 +version: 2.1.1 repository: https://github.com/MapsPeople/mapsindoors_flutter_googlemaps_ios homepage: https://www.mapsindoors.com/ @@ -18,7 +18,7 @@ flutter: dependencies: flutter: sdk: flutter - mapsindoors_platform_interface: ^2.1.0 + mapsindoors_platform_interface: ^2.1.1 dev_dependencies: flutter_test: