通过继承SceneAction的方式来扩展用户的Action时报错
var point = new SuperMap.Geometry.Point(-111.04, 45.68); 用这个方法,我无法选中
trackingLayer3D的对象
您好,问题确定了,是这样的,trackingLayer3D的hitTest方法传的是像素点,不是几何点(Geometry.Point),帮助手册上关于trackingLayer3D的hitTest方法传参描述是错误的,给您带来不便,深感歉意。
示范:
//通过继承SceneAction的方式来扩展用户的Action,继承方式采用框架提供的格式 //扩展Action的构造函数 SuperMap.Web.UI.Action3Ds.MyAction = function (sceneControl) { ///<param name="sceneControl" type="SuperMap.Web.UI.Controls.SceneControl"></param> SuperMap.Web.UI.Action3Ds.MyAction.initializeBase(this); this._name = "myAction"; this._sceneControl = sceneControl; //对应的场景操作类型为漫游 this._type = SuperMap.Web.UI.Action3Ds.SceneActionType.POINTSELECT; }; //扩展Action的属性和方法 SuperMap.Web.UI.Action3Ds.MyAction.prototype = { /* * 析构方法 */ dispose: function () { ///<returns type="void"></returns> this._sceneControl = null; }, /* * 鼠标单击方法 */ onMouseDown: function (e) { //通过事件对象查询到相关的信息 var x = e.get_clientX(); var y = e.get_clientY(); var point = new SuperMap.Pixel(x, y); //var point3d = sceneControl.pixelToGlobe(point); //alert(point3d.x + "," + point3d.y); var select = scene.get_trackingLayer3D().hitTest(point); if (select == null) { alert("你没有选中对象") } else { alert("你选中了对象," + "对象名字为:" + select.get_name()) } } }; SuperMap.Web.UI.Action3Ds.MyAction.registerClass('SuperMap.Web.UI.Action3Ds.MyAction', SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable);
详见samplecode中的Hittest.html