在三维场景添加文本时出现问题,我本意是在鼠标点击的位置添加文本标签,但是每次点击都会在同一固定位置添加,如下是我具体代码,请帮助看下是哪里造成的错误。
//添加文本标签
function addLabel() {
var newAction = new SuperMap.Web.UI.Action3Ds.MakeLabelAction(sceneControl);
sceneControl.set_sceneAction(newAction);
setFocus();
}
//点击添加文本扩展Action
SuperMap.Web.UI.Action3Ds.MakeLabelAction = function (sceneControl) {
SuperMap.Web.UI.Action3Ds.MakeLabelAction.initializeBase(this);
this._name = "MakeLabel";
this._sceneControl = sceneControl;
this._type = SuperMap.Web.UI.Action3Ds.SceneActionType.PAN;
};
SuperMap.Web.UI.Action3Ds.MakeLabelAction.prototype = {
dispose: function () {
this._sceneControl = null;
}, onMouseDown: function (e) {
if (e.get_flagType() % 2 == 1) {
var point = new SuperMap.Web.Core.Point3D(e.get_longitude(), e.get_latitude(), e.get_altitude());
var point3D = new SuperMap.Web.Core.GeoPoint3D(point);
var txtPart3D = new SuperMap.Web.Core.TextPart3D("文本标签测试", point3D);
var textArray = [txtPart3D];
var text3D = new SuperMap.Web.Core.GeoText3D(textArray);
//text3D.set_position(point3D);
var feature3D = new SuperMap.Web.Core.Feature3D();
feature3D.set_geometry(text3D);
var textStyle = new SuperMap.Web.Core.TextStyle3D();
textStyle.set_foreColor(new SuperMap.Web.Core.Color(255,0,0,255));
textStyle.set_backColor(new SuperMap.Web.Core.Color(0,0,0,255));
textStyle.set_outline(true);
textStyle.set_fontName("微软雅黑");
textStyle.set_fontScale(0.8);
feature3D.set_textStyle3D(textStyle);
var trackingLayer = this._sceneControl.get_scene().get_trackingLayer3D(); //设置跟踪图层可见性
trackingLayer.set_isVisible(true);
trackingLayer.add(feature3D,"Text");
}
}
};
SuperMap.Web.UI.Action3Ds.MakeLabelAction.registerClass('SuperMap.Web.UI.Action3Ds.MakeLabelAction', SuperMap.Web.UI.Action3Ds.SceneAction, Sys.IDisposable);