我使用mapbox和three.js创建了一个不合理的地图。 当我拖动地图时,我还将对象拖放到three.js场景上,这是mapbox上的一个图层。这是一个工作版本:http://test3.stdmed.ru 我有一个问题:当我开始拖动时,three.js场景上的物体会自动居中于光标位置,这是不正确的,因为这种效果会破坏定位。
您可以在此示例中看到一个简单的效果:http://alexan0308.github.io/threejs/examples/#controls_events_example 当你点击一个检查器时它会居中到你的光标位置。但是我需要在没有这种效果的情况下拖延它。
这是我在地图上使用的代码:
EventsControls2 = new EventsControls( camera, renderer.domElement );
EventsControls2.attach( plane );
EventsControls2.attachEvent( 'mouseOver', function () {
controls.enabled = false;
controls.target0.copy( controls.target );
});
EventsControls2.attachEvent( 'mouseOut', function () {
controls.reset();
controls.target.copy( controls.target0 );
controls.object.position.copy( controls.position0 );
controls.update();
controls.enabled = true;
});
EventsControls = new EventsControls( camera, renderer.domElement );
EventsControls.map = plane;
EventsControls.attachEvent( 'mouseOver', function () {
this.container.style.cursor = 'pointer';
});
EventsControls.attachEvent( 'mouseOut', function () {
this.container.style.cursor = 'auto';
});
EventsControls.attachEvent( 'dragAndDrop', function () {
this.container.style.cursor = 'move';
//this.focused.position.y = this.previous.y;
//this.focused.position.x = this.previous.x;
});
EventsControls.attachEvent( 'onclick', function () {
controls.enabled = false;
});
EventsControls.attachEvent( 'mouseUp', function () {
this.container.style.cursor = 'auto';
});
答案 0 :(得分:0)
EventsControls = new EventsControls( camera, renderer.domElement );
EventsControls.map = plane;
EventsControls.offsetUse = true;
EventsControls.offsetUse = true; <<<<<<<<<这是你必须添加的!!!