碰到很多添加一些客户端标示的需求,SuperMap IS.NET中这样的问题解决方法一般有两种情况,一个是使用自定义Action方式获取坐标,然后添加到CustomLayer层上,另外就是获取鼠标点击地图窗体的像素坐标,然后使用像素坐标转地理坐标的方法。下面展示第一种思路的添加Mark的方法
//自定义Action,当鼠标单击地图时候添加Mark
insertMarkT = function() {
this.type = "insertMarkT";
this.Init = function(mapControl) { this.mapControl = mapControl; };
this.Destroy = function() { this.mapControl = null; };
this.OnClick = function(e) {
//当鼠标单击事件时候,触发添加Mark操作,map对象为实例化的MapControl对象
map.CustomLayer.AddMark("Mark"+Math.random(), e.mapCoord.x, e.mapCoord.y, null, null, "<img src='images/poi_search.gif' onclick='test()'/>", "", 10000, "mark", 1);
//当添加Mark后设置地图控件的操作为平移操作
var pan = new SuperMap.IS.PanAction();
map.SetAction(pan);
};
this.OnDblClick = function(e) { };
this.OnMouseMove = function(e) { };
this.OnMouseDown = function(e) { };
this.OnMouseUp = function(e) { };
this.OnContextMenu = function(e) { };
this.GetJSON = function() { return _ActionToJSON(this.type, []); }
};
//给地图控件设置
var tt = null;
function InsertTable() {
if (!tt) {
tt = new insertMarkT ();
}
map.SetAction(tt);
}
//Mark响应的鼠标单击事件
function test() {
alert("查询");
}