안녕하십니까. 개발 2개월차 새내기 개발자입니다. 궁금한게 있어 글을 쓰게됬습니다.
var CustomOverlay = function(options)
{
this._element = $(
'<div style="width:100px; height:40; color:red;">' +
'<br><b>TEXT</b>' +
'</div>'
);
this.setPosition(options.position);
this.setMap(options.map || null);
};
CustomOverlay.prototype = new naver.maps.OverlayView();
CustomOverlay.prototype.constructor = CustomOverlay;
CustomOverlay.prototype.setPosition = function(position)
{
this._position = position;
this.draw();
};
CustomOverlay.prototype.getPosition = function()
{
return this._position;
};
CustomOverlay.prototype.onAdd = function()
{
var overlayLayer = this.getPanes().overlayLayer;
this._element.appendTo(overlayLayer);
};
CustomOverlay.prototype.draw = function()
{
if(!this.getMap())
{
return;
}
var projection = this.getProjection(),
position = this.getPosition(),
pixelPosition = projection.fromCoordToOffset(position);
this._element.css('left', pixelPosition.x);
this._element.css('top', pixelPosition.y);
};
CustomOverlay.prototype.onRemove = function()
{
var overlayLayer = this.getPanes().overlayLayer;
this._element.remove();
this._element.off();
};
overlay = new CustomOverlay(
{
map: map,
position: marker.getPosition()
});
overlay.setMap(map);
네이버 map api에 사용자 정의 오버레이입니다.
위 코드에서 CustomOverlay를 선언할 때 익명 함수가 만들어져 있는데 따로 함수를 사용하는 부분이 없는거 같은데 코드는 정상 작동 합니다. 그래서 혹시 다음줄에 있는 CustomOverlay.prototype.constructor = CustomOverlay <- 부분에서 호출되는게 아닐까 라는 추측을 해보았는데 protottype에 대해 아는게 별로 없어 질문을 하러 왔습니다.
점심식사 맛있게 하십시오!