Skip to content

Commit

Permalink
Refactor: Change return type of getLocationOverlay from Future<NLocat…
Browse files Browse the repository at this point in the history
…ionOverlay> to NLocationOverlay (non-async function)
  • Loading branch information
note11g committed Mar 1, 2024
1 parent 8a7b64c commit d950661
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.naver.maps.map.Projection
import com.naver.maps.map.Symbol
import com.naver.maps.map.indoor.IndoorSelection
import com.naver.maps.map.overlay.LocationOverlay
import dev.note11.flutter_naver_map.flutter_naver_map.controller.overlay.OverlayController
import dev.note11.flutter_naver_map.flutter_naver_map.controller.overlay.OverlayHandler
import dev.note11.flutter_naver_map.flutter_naver_map.converter.AddableOverlay
import dev.note11.flutter_naver_map.flutter_naver_map.converter.AddableOverlay.Companion.toMessageable
Expand Down Expand Up @@ -38,6 +37,7 @@ internal class NaverMapController(
private var naverMapViewOptions: NaverMapViewOptions? = null

init {
overlayController.initializeLocationOverlay(naverMap.locationOverlay)
channel.setMethodCallHandler(::handle)
}

Expand Down Expand Up @@ -80,10 +80,6 @@ internal class NaverMapController(

override fun getLocationOverlay(onSuccess: (Map<String, Any?>) -> Unit) {
val overlay = naverMap.locationOverlay
val info = NOverlayInfo.locationOverlayInfo
if (!overlayController.hasOverlay(info)) {
overlayController.saveOverlay(overlay, info)
}
onSuccess(overlay.toMessageable())
}

Expand Down Expand Up @@ -251,6 +247,6 @@ internal class NaverMapController(

fun remove() {
channel.setMethodCallHandler(null)
(overlayController as OverlayController).remove()
overlayController.remove()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ internal class OverlayController(
channel.setMethodCallHandler(::handler)
}

override fun initializeLocationOverlay(overlay: LocationOverlay) {
saveOverlay(overlay, NOverlayInfo.locationOverlayInfo)
}

/* ----- sender ----- */
override fun onOverlayTapped(info: NOverlayInfo) {
val query = NOverlayQuery(info, methodName = OverlayHandler.onTapName).query
Expand Down Expand Up @@ -668,7 +672,7 @@ internal class OverlayController(
--- remove ---
*/

fun remove() {
override fun remove() {
channel.setMethodCallHandler(null)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.note11.flutter_naver_map.flutter_naver_map.controller.overlay

import com.naver.maps.map.overlay.LocationOverlay
import com.naver.maps.map.overlay.Overlay
import dev.note11.flutter_naver_map.flutter_naver_map.converter.AddableOverlay
import dev.note11.flutter_naver_map.flutter_naver_map.model.enum.NOverlayType
Expand All @@ -18,6 +19,8 @@ internal interface OverlayHandler {

fun clearOverlays(type: NOverlayType)

fun initializeLocationOverlay(overlay: LocationOverlay)

fun <T : Overlay> saveOverlayWithAddable(creator: AddableOverlay<out T>): T {
if (hasOverlay(creator.info)) deleteOverlay(creator.info)

Expand Down Expand Up @@ -70,6 +73,8 @@ internal interface OverlayHandler {

fun setHasOnTapListener(overlay: Overlay, rawHasOnTapListener: Any)

fun remove()

companion object {
/* --- Messaging Name Define --- */
const val zIndexName = "zIndex"
Expand Down
Binary file added assets/icon/location_overlay_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/location_overlay_icon_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/location_overlay_sub_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/location_overlay_sub_icon_face.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions ios/Classes/controller/NaverMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal class NaverMapController: NaverMapControlSender, NaverMapControlHandler
self.naverMap = naverMap
self.channel = channel
self.overlayController = overlayController
overlayController.initializeLocationOverlay(overlay: naverMap.mapView.locationOverlay)

channel.setMethodCallHandler(handle)
}
Expand Down Expand Up @@ -45,10 +46,6 @@ internal class NaverMapController: NaverMapControlSender, NaverMapControlHandler

func getLocationOverlay(onSuccess: @escaping (Any?) -> ()) {
let overlay = mapView.locationOverlay
let info = NOverlayInfo.locationOverlayInfo
if (!overlayController.hasOverlay(info: info)) {
overlayController.saveOverlay(overlay: overlay, info: info)
}
onSuccess(overlay.toMessageable())
}

Expand Down Expand Up @@ -198,6 +195,6 @@ internal class NaverMapController: NaverMapControlSender, NaverMapControlHandler

func removeChannel() {
channel.setMethodCallHandler(nil)
(overlayController as! OverlayController).removeChannel()
overlayController.removeChannel()
}
}
4 changes: 4 additions & 0 deletions ios/Classes/controller/overlay/OverlayController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ internal class OverlayController: OverlaySender, OverlayHandler, ArrowheadPathOv
self.channel = channel
channel.setMethodCallHandler(handler)
}

func initializeLocationOverlay(overlay: NMFLocationOverlay) {
saveOverlay(overlay: overlay, info: NOverlayInfo.locationOverlayInfo)
}

/* ----- sender ----- */
func onOverlayTapped(info: NOverlayInfo) {
Expand Down
4 changes: 4 additions & 0 deletions ios/Classes/controller/overlay/OverlayHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ internal protocol OverlayHandler {
func clearOverlays()

func clearOverlays(type: NOverlayType)

func initializeLocationOverlay(overlay: NMFLocationOverlay)

/*
--- methods ---
Expand All @@ -32,6 +34,8 @@ internal protocol OverlayHandler {
func performClick(_ overlay: NMFOverlay, success: (Any?) -> Void)

func setHasOnTapListener(_ overlay: NMFOverlay, rawHasOnTapListener: Any)

func removeChannel()
}

func getterName(_ name: String) -> String {
Expand Down
13 changes: 7 additions & 6 deletions lib/src/controller/map/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ class _NaverMapControllerImpl
}

@override
Future<NLocationOverlay> getLocationOverlay() async {
final rawLocationOverlay = await invokeMethod("getLocationOverlay");
overlayController.locationOverlay ??=
NLocationOverlay._fromMessageable(rawLocationOverlay)
.._addedOnMap(overlayController);
return overlayController.locationOverlay!;
NLocationOverlay getLocationOverlay() {
if (overlayController.locationOverlay != null) {
return overlayController.locationOverlay!;
}
final lo = NLocationOverlay._attachToMapWhenFirstUse(overlayController);
overlayController.locationOverlay = lo;
return lo;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controller/map/sender.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class _NaverMapControlSender {
Future<List<NLatLng>> getContentRegion({bool withPadding = false});

/// 위치 오버레이를 가져옵니다. 위치 오버레이는 직접 생성하지 않고 이 메서드를 통해 가져옵니다.
Future<NLocationOverlay> getLocationOverlay();
NLocationOverlay getLocationOverlay();

/// 화면 좌표를 위경도 좌표로 변환합니다.
///
Expand Down
40 changes: 10 additions & 30 deletions lib/src/type/map/overlay/overlay/location_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,10 @@ part of "../../../../../flutter_naver_map.dart";
class NLocationOverlay extends NOverlay<NLocationOverlay> {
/* ----- Constructor ----- */

factory NLocationOverlay._fromMessageable(dynamic m) => NLocationOverlay._(
anchor: NPoint._fromMessageable(m[_anchorName]!),
circleColor: Color(m[_circleColorName] as int),
circleOutlineColor: Color(m[_circleOutlineColorName] as int),
circleOutlineWidth: m[_circleOutlineWidthName] as double,
circleRadius: m[_circleRadiusName] as double,
iconSize: NSize._fromMessageable(m[_iconSizeName]!),
subAnchor: NPoint._fromMessageable(m[_subAnchorName]!),
subIconSize: NSize._fromMessageable(m[_subIconSizeName]!),
).._applyFromMessageable(m);

NLocationOverlay._({
required NPoint anchor,
required Color circleColor,
required Color circleOutlineColor,
required double circleOutlineWidth,
required double circleRadius,
required NSize iconSize,
required NPoint subAnchor,
required NSize subIconSize,
}) : _anchor = anchor,
_circleColor = circleColor,
_circleOutlineColor = circleOutlineColor,
_circleOutlineWidth = circleOutlineWidth,
_circleRadius = circleRadius,
_iconSize = iconSize,
_subAnchor = subAnchor,
_subIconSize = subIconSize,
super(_locationOverlayInfo);
NLocationOverlay._attachToMapWhenFirstUse(_NOverlayController controller) : super(_locationOverlayInfo) {
_addedOnMap(controller);
_allSyncByDefaultForPlatformDiffProperties();
}

static const NOverlayInfo _locationOverlayInfo =
NOverlayInfo(type: NOverlayType.locationOverlay, id: "L");
Expand Down Expand Up @@ -135,6 +110,11 @@ class NLocationOverlay extends NOverlay<NLocationOverlay> {
_set(_subIconSizeName, size);
}

void _allSyncByDefaultForPlatformDiffProperties() {
setIcon(defaultIcon);
setCircleColor(defaultCircleColor);
}

/*
--- Messaging Name Define ---
*/
Expand All @@ -154,7 +134,7 @@ class NLocationOverlay extends NOverlay<NLocationOverlay> {

static const defaultAnchor = NPoint(0.5, 0.5);
static const defaultSubAnchor = NPoint(0.5, 1.0);
static const defaultCircleColor = Color(0x0A1666F0);
static const defaultCircleColor = Color(0x3D1666F0);
static const defaultCircleRadius = 18.0;
static const autoSize = Size(0, 0);
static const defaultIcon = NOverlayImage.fromAssetImage(
Expand Down
5 changes: 5 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ flutter:
pluginClass: FlutterNaverMapPlugin
ios:
pluginClass: FlutterNaverMapPlugin

assets:
- ./assets/icon/location_overlay_icon.png
- ./assets/icon/location_overlay_sub_icon.png
- ./assets/icon/location_overlay_sub_icon_face.png

0 comments on commit d950661

Please sign in to comment.