JavaScript의 메서드를 호출 하는 것은 지난번에 포스팅하였다.

http://ehdrn.tistory.com/197

 

이번에는 JavaScript에서 이벤트가 발생하였을 때

CallBack 받는 부분을 작성하려고 한다.

 

 

Class Atttribute 아래의 코드 작성과

[System.Runtime.InteropServices.ComVisibleAttribute(true)]

 


CallBack 받을 메서드 Attribute에 아래의 코드를 작성 해주면된다.

[System.Runtime.InteropServices.DispId(0)]

 

 

C# 호출 부분

인스턴스를 넘겨주어야한다.

 

this.Document.InvokeScript("CreateSimpleTextMarker", new object[] { marker.LatLng.Lat, marker.LatLng.Lng, marker.Content, cssText, marker.MarkerDrawEvent });


 

 

 

C# Class

 

    /// <summary>
    /// Marker의 Draw Event를 받기 위한 Class
    /// </summary>
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public class MarkerDrawEvent
    {
        /// <summary>
        /// Marker Draw Delegate
        /// </summary>
        /// <param name="point"></param>
        public delegate void MarkerDrawEventHandler(Point point);

        /// <summary>
        /// Marker Click EventHandler
        /// </summary>
        public event MarkerDrawEventHandler MarkerDraw;


        /// <summary>
        /// 자바스크립트 코드에서 CallBack 받기위한 메서드
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        
        [System.Runtime.InteropServices.DispId(0)]
        public void MarkerDrawRaised(string _point)
        {
            string []xy = _point.Split(new char[] { ',','(',')' }, StringSplitOptions.RemoveEmptyEntries);
            string x = xy[0];
            string y = xy[1];
            if (MarkerDraw != null)
            {
                MarkerDraw(new Point(Convert.ToInt32(x),Convert.ToInt32(y)));
            }
        }
    }


 

JavaScript

    //간단한 텍스트 마커를 생성합니다.
    function CreateSimpleTextMarker( lat, lng, content, cssText, markerDrawEventHandler) {

 

......생략.....

 

SimpleTextMarker.prototype.draw = function () { var projection = this.getProjection(); self.m_projection = projection; var point = projection.pointFromCoords(this.position_); var width = this.node_.offsetWidth; var height = this.node_.offsetHeight; this.node_.style.cssText = cssText + 'position: absolute; white-space: nowrap; left: ' + (point.x - width / 2) + 'px; top: ' + (point.y - height / 2) + 'px'; if (markerDrawEventHandler != null) { markerDrawEventHandler(point.toString()); } }; ......생략.....

 

}


 

+ Recent posts