Click or drag to resize
XDL

NXMilmapLayerCompositesHitTest Method

화면에 도시된 XDMComposite 중에서 특정 위치에 Hitting 되는 XDMComposite 중 가장 상위의 XDMComposite 를 가져온다.

Namespace: Pixoneer.NXDL.NXMilmap
Assembly: NXMilmap (in NXMilmap.dll) Version: 3.0.0.0
Syntax
C#
public bool HitTest(
	XVertex2d vWorld,
	ref XDMComposite pHitComp
)

Parameters

vWorld  XVertex2d
테스트를 위한 월드 좌표(위경도 좌표)
pHitComp  XDMComposite
[out] Hitting 되는 최상위 XDMComposite

Return Value

Boolean
성공이면 true, 실패하면 false를 반환한다.
Example
예제 #1: 컨트롤 화면을 클릭할 시 화면에 도시된 XDMComposite들 중 해당 위치에 Hitting 되는 가장 상위의 XDMComposite 를 가져온다.
C#
using Pixoneer.NXDL;
using Pixoneer.NXDL.NGR;
using Pixoneer.NXDL.NXMilmap;
using Pixoneer.NXDL.NIO;
using Pixoneer.NXDL.NRS;

namespace XDL_MilmapView
{
public partial class MainWindow : Window
{
    NXMilmapLayerComposites nxMilmapLayerComposites1 = new NXMilmapLayerComposites();
    public XRasterIO RasterIO;
    public MainWindow()
    {
        InitializeComponent();
        NXRenderLayer milmapLayer = nxMilmapLayerComposites1;
        nxMilmapView1.AddRenderLayer(ref milmapLayer);
        nxMilmapView1.MouseDown += NxMilmapView1_MouseDown;
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        // 군사지도를 위한 NXMilmapView 및 NXMilmapEngine을 초기화
        if (!NXMilmapView.m_MapEngine.InitFromXML("c:\\Pixoneer\\Xdl3.0\\Config\\XMilmapConfig.xml")) return;
        nxMilmapView1.WheelZoomAction = NXMilmapView.eWheelZoomAction.ByZoomFactor;
        nxMilmapView1.SetGeoToCenter(0, new XVertex2d(127.0, 36.0));

        // Image load
        RasterIO = new XRasterIO();
        String StrError;
        if (RasterIO.Initialize(out StrError) == false)
        {
             MessageBox.Show(StrError);
        }

        String strFilePathLoad1 = "C:\\Pixoneer\\PG-STEAMER 5.0\\data\\IKONOS.xdm";
        String strFilePathLoad2 = "C:\\Pixoneer\\PG-STEAMER 5.0\\data\\DEM.xdm";
        XRSLoadFile xrsFileInput1 = new XRSLoadFile();
        XRSLoadFile xrsFileInput2 = new XRSLoadFile();
        xrsFileInput1 = RasterIO.LoadFile(strFilePathLoad1, out StrError, false, eIOCreateXLDMode.All_NoMsg);
        xrsFileInput2 = RasterIO.LoadFile(strFilePathLoad2, out StrError, false, eIOCreateXLDMode.All_NoMsg);

        // Create Composite
        if (xrsFileInput1 == null && xrsFileInput2 == null) return;
        XDMComposite newComp1 = CreateComposite(xrsFileInput1, 0, 1, 2);
        XDMComposite newComp2 = CreateComposite(xrsFileInput2, 0, 1, 2);
        XDMCompManager xdmCompManager = nxMilmapLayerComposites1.GetXDMCompManager();
        xdmCompManager.AddXDMComposite(ref newComp1);
        xdmCompManager.AddXDMComposite(ref newComp2);
        nxMilmapLayerComposites1.Invalidate();
        nxMilmapView1.RefreshScreen();
    }

    private void NxMilmapView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        // e.X, e.Y : 스크린 좌표(컨트롤 화면 기준 좌상단(0,0) 픽셀 단위)

        // MilmpaView 는 위경도 좌표계를 사용한다.
        XDMComposite newComp = null;
        NXMilmapDrawArgs drawArgs = nxMilmapView1.GetDrawArgs();
        XVertex2d vtPos = drawArgs.ScreenToGeographic(new XVertex2d(e.X, e.Y));

        nxMilmapLayerComposites1.HitTest(vtPos, ref newComp);
        // Hit Composite 결과를 출력한다.
        if (newComp != null && !string.IsNullOrEmpty(newComp.Name))
        {
            System.Windows.MessageBox.Show($"Hit Composite 이름: {newComp.Name}\n모드: {newComp.Mode}");
        }
        else
        {
            System.Windows.MessageBox.Show("해당 위치에 Composite가 없습니다.");
        }
    }

    XDMComposite CreateComposite(XRSLoadFile xrsFileInput, int nBandIdx0, int nBandIdx1, int nBandIdx2)
    {
        XDMComposite newComp = new XDMComposite();

        int nNumBand = xrsFileInput.NumBand;
        if (nNumBand < 3)
        {
            XDMBand band = xrsFileInput.GetBandAt(0);
            newComp.Name = band.BandName;
            newComp.Mode = eCompMode.Gray;
            newComp.SetBand(ref band, 0);
            newComp.SetCutType(eCompCutType.Ct95, 0);
            newComp.SetStretchCoverage(eCompStretchCoverage.Band, 0);
            newComp.SetStretchType(eCompStretchType.Gaussian, 0);
        }
        else
        {
            XDMBand band1 = xrsFileInput.GetBandAt(0);
            XDMBand band2 = xrsFileInput.GetBandAt(1);
            XDMBand band3 = xrsFileInput.GetBandAt(2);
            newComp.Name = xrsFileInput.FileName;

            newComp.Mode = eCompMode.RGB;
            newComp.SetBand(ref band3, nBandIdx0);
            newComp.SetBand(ref band2, nBandIdx1);
            newComp.SetBand(ref band1, nBandIdx2);

            for (int i = 0; i < 3; i++)
            {
                newComp.SetCutType(eCompCutType.Ct95, i);
                newComp.SetStretchCoverage(eCompStretchCoverage.Band, i);
                newComp.SetStretchType(eCompStretchType.Gaussian, i);
            }
        }
        return newComp;
    }

    private void Window_Closed(object sender, EventArgs e)
    {
        Xfn.Close();
    }
}
}
See Also