initPositionMap method

  1. @override
Future<void> initPositionMap({
  1. GeoPoint? initPosition,
  2. UserTrackingOption? userPositionOption,
})

Implementation

@override
Future<void> initPositionMap({
  GeoPoint? initPosition,
  UserTrackingOption? userPositionOption,
}) async {
  interop.setUpMap(mapIdMixin);
  assert((initPosition != null) ^ (userPositionOption != null));
  if (osmWebFlutterState.widget.controller.customTile != null) {
    await changeTileLayer(
      tileLayer: osmWebFlutterState.widget.controller.customTile,
    );
  }
  webPlatform.onLongPressMapClickListener(mapIdMixin).listen((event) {
    osmWebFlutterState.widget.controller
        .setValueListenerMapLongTapping(event.value);
    osmWebFlutterState.widget.controller.osMMixins.forEach((osmMixin) {
      osmMixin.onLongTap(event.value);
    });
  });
  webPlatform.onSinglePressMapClickListener(mapIdMixin).listen((event) {
    osmWebFlutterState.widget.controller
        .setValueListenerMapSingleTapping(event.value);
    osmWebFlutterState.widget.controller.osMMixins.forEach((osmMixin) {
      osmMixin.onSingleTap(event.value);
    });
  });
  webPlatform.onMapIsReady(mapIdMixin).listen((event) async {
    osmWebFlutterState.widget.mapIsReadyListener.value = event.value;
    osmWebFlutterState.widget.controller
        .setValueListenerMapIsReady(event.value);
    if (osmWebFlutterState.widget.onMapIsReady != null) {
      osmWebFlutterState.widget.onMapIsReady!(event.value);
    }
    if (osmWebFlutterState.widget.controller.osMMixins.isNotEmpty) {
      osmWebFlutterState.widget.controller.osMMixins.forEach((element) async {
        await element.mapIsReady(event.value);
      });
    }
    if (_androidOSMLifecycle != null) {
      _androidOSMLifecycle!.mapIsReady(event.value);
    }
  });
  webPlatform.onRegionIsChangingListener(mapIdMixin).listen((event) {
    osmWebFlutterState.widget.controller
        .setValueListenerRegionIsChanging(event.value);
    osmWebFlutterState.widget.controller.osMMixins.forEach((osmMixin) {
      osmMixin.onRegionChanged(event.value);
    });
  });
  webPlatform.onRoadMapClickListener(mapIdMixin).listen((event) {
    osmWebFlutterState.widget.controller
        .setValueListenerMapRoadTapping(event.value);
    osmWebFlutterState.widget.controller.osMMixins.forEach((osmMixin) {
      osmMixin.onRoadTap(event.value);
    });
  });

  if (osmWebFlutterState.widget.onGeoPointClicked != null) {
    webPlatform.onGeoPointClickListener(mapIdMixin).listen((event) {
      osmWebFlutterState.widget.onGeoPointClicked!(event.value);
    });
  }
  webPlatform.onUserPositionListener(mapIdMixin).listen((event) {
    if (osmWebFlutterState.widget.onLocationChanged != null) {
      osmWebFlutterState.widget.onLocationChanged!(event.value);
    }
    osmWebFlutterState.widget.controller.osMMixins.forEach((osmMixin) {
      osmMixin.onLocationChanged(event.value);
    });
  });

  if (osmWebFlutterState.widget.markerOption?.defaultMarker != null) {
    await changeHomeIconMarker(osmWebFlutterState.defaultMarkerKey!);
  }
  if (osmWebFlutterState.widget.staticIconGlobalKeys.isNotEmpty) {
    var keys = osmWebFlutterState.widget.staticIconGlobalKeys;
    keys.removeWhere((key, value) =>
        osmWebFlutterState.widget.staticPoints
            .firstWhere((element) => element.id == key)
            .markerIcon ==
        null);
    keys.forEach((id, key) {
      markerIconsStaticPositions(id, key);
    });
  }
  if (osmWebFlutterState.widget.roadConfiguration != null) {
    defaultRoadOption = osmWebFlutterState.widget.roadConfiguration!;
  }

  if (osmWebFlutterState.widget.markerOption?.advancedPickerMarker != null) {
    if (osmWebFlutterState.advancedPickerMarker?.currentContext != null) {
      await changeIconAdvPickerMarker(
        osmWebFlutterState.advancedPickerMarker!,
      );
    }
  }
  if (osmWebFlutterState.widget.markerOption?.advancedPickerMarker == null) {
    osmWebFlutterState.widget.dynamicMarkerWidgetNotifier.value = Icon(
      Icons.location_on,
      color: Colors.red,
      size: 32,
    );
    Future.delayed(duration, () async {
      await changeIconAdvPickerMarker(osmWebFlutterState.dynamicMarkerKey!);
    });
  }

  /// change user person Icon and arrow Icon
  if (osmWebFlutterState.widget.userLocationMarker != null) {
    await customUserLocationMarker(
      osmWebFlutterState.personIconMarkerKey,
    );
  }

  await configureZoomMap(
    osmWebFlutterState.widget.minZoomLevel,
    osmWebFlutterState.widget.maxZoomLevel,
    osmWebFlutterState.widget.stepZoom,
    osmWebFlutterState.widget.initZoom,
  );

  GeoPoint? initLocation = initPosition;

  if (userPositionOption != null) {
    initLocation = await myLocation();
  }
  await initLocationMap(initLocation!);

  if (osmWebFlutterState.widget.staticPoints.isNotEmpty) {
    osmWebFlutterState.widget.staticPoints.forEach((ele) {
      setStaticPosition(ele.geoPoints, ele.id);
    });
  }
}