package com.lnkj.ln_jq_app;

import android.app.Activity;
import android.content.Context;

import io.flutter.plugin.common.MessageCodec;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.plugin.platform.PlatformView;
import io.flutter.plugin.platform.PlatformViewFactory;

/**
 * 高德地图导航 Platform View Factory
 * 对应iOS的NativeViewFactory
 */
public class NativeMapFactory extends PlatformViewFactory {

    private static final String VIEW_TYPE_ID = "NativeFirstPage";
    private static NativeMapView mapViewInstance = null;
    private final Context context;

    public NativeMapFactory(Context context) {
        super(StandardMessageCodec.INSTANCE);
        this.context = context;
    }

    @Override
    public PlatformView create(Context context, int viewId, Object args) {
        mapViewInstance = new NativeMapView(context, viewId, args);
        return mapViewInstance;
    }

    /**
     * 获取地图实例，供MainActivity使用
     */
    public static NativeMapView getMapView() {
        return mapViewInstance;
    }

    /**
     * 设置 Activity 实例
     */
    public static void setActivity(Activity activity) {
        if (mapViewInstance != null) {
            mapViewInstance.setActivity(activity);
        }
    }
}
