Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript THREEJS-Bing贴图:对象不会保留在初始坐标_Javascript_Three.js - Fatal编程技术网

Javascript THREEJS-Bing贴图:对象不会保留在初始坐标

Javascript THREEJS-Bing贴图:对象不会保留在初始坐标,javascript,three.js,Javascript,Three.js,我在google()上创建这段代码是为了在Bing地图的特定坐标上放置一个对象。但我不明白为什么当我改变图书馆的时候,这不起作用 使用库70工作,而使用库76不工作 var MM = Microsoft.Maps; var map; var scene; var camera; var renderer; var plane; var startWidth; var boxe; var raycaster = new THREE.Raycaster(); function loadM

我在google()上创建这段代码是为了在Bing地图的特定坐标上放置一个对象。但我不明白为什么当我改变图书馆的时候,这不起作用

使用库70工作,而使用库76不工作

var MM = Microsoft.Maps;
var map;

var scene;
var camera;
var renderer;

var plane;

var startWidth;

var boxe;

var raycaster = new THREE.Raycaster();

function loadMap() {

    document.getElementById("log").innerHTML += "> Loading map";


    map = new MM.Map(document.getElementById("mapDiv"), {
        center: new MM.Location(45.06, 7.66),
        zoom: 10,
        inertiaIntensity: 0.4,
        mapTypeId: Microsoft.Maps.MapTypeId.birdseye,
        labelOverlay: Microsoft.Maps.LabelOverlay.hidden,
        disableBirdseye: true,
        credentials:"xxx"});

    MM.Events.addHandler(map, 'viewchange', updatePosition);

    loadCanvas(map);

}

function loadCanvas(map) {

    document.getElementById("log").innerHTML += "> Starting webgl";

    var mapDiv = map.getRootElement();

    var width = map.getWidth();
    var height = map.getHeight();

    renderer = new THREE.WebGLRenderer( { alpha: true } );
    renderer.shadowMap.enabled = true;

    renderer.setSize(width, height);
    mapDiv.parentNode.lastChild.appendChild( renderer.domElement );

    renderer.domElement.style.position = "absolute";
    renderer.domElement.style.top = "0px";
    renderer.domElement.style.left = "0px";

    scene = new THREE.Scene();


    camera = new THREE.PerspectiveCamera( 75, width / height, 1, 1000 );
    camera.position.z = 100;

    document.getElementById("log").innerHTML += "> Loading texture";
    document.getElementById("log").innerHTML += "> Creating boxes";

    var geometry = new THREE.BoxGeometry( 5, 5, 10 );
    var material = new THREE.MeshPhongMaterial( { color: 0xaaaaaa } );
    var cube = new THREE.Mesh( geometry, material );
    cube.position.z = 5;

    var pivot = new THREE.Object3D();
    pivot.lat = 45.06;
    pivot.lon = 7.66;

    cube.position.x = 10;

    pivot.add( cube );
    scene.add( pivot );
    boxe = pivot;

    plane = new THREE.Mesh(new THREE.PlaneBufferGeometry (1000, 1000), new THREE.MeshPhongMaterial({color: 0xFFFF00}));

    plane.visible = false;
    scene.add(plane);

    var axisHelper = new THREE.AxisHelper( 10 );
    scene.add( axisHelper );
    var light = new THREE.AmbientLight( 0x404040 );
    scene.add( light );


    var pointLight = new THREE.PointLight(0xffffff);
    pointLight.position.set(0, 300, 200);
    scene.add(pointLight);

    startWidth = getCurrentWidth();

    render();

    updatePosition({linear:true});

    document.getElementById("log").innerHTML = "";       

}


function render() {

    renderer.render( scene, camera );
}

function updatePosition(e) {

    if(!e.linear)
    {

            var currentWidth = getCurrentWidth();
            var diff = startWidth / currentWidth;
            boxe.scale.set(diff,diff,diff);
    }

    var mouse = new THREE.Vector2();
    var latitude = boxe.lat;
    var longitude = boxe.lon;

    var pixelCoordinate = map.tryLocationToPixel(new MM.Location(latitude, longitude),MM.PixelReference.control);

    mouse.x = ( pixelCoordinate.x / window.innerWidth ) * 2 - 1;
    mouse.y = - ( pixelCoordinate.y / window.innerHeight ) * 2 + 1;



    raycaster.setFromCamera( mouse, camera);   

    var intersects = raycaster.intersectObject(plane);

    if(intersects.length > 0) {
        boxe.position.x = intersects[0].point.x;
        boxe.position.y = intersects[0].point.y;            
    }

    window.requestAnimationFrame(render);

}


function getCurrentWidth() {

    var bounds = map.getBounds();

    var nw = bounds.getNorthwest();
    var se = map.getBounds().getSoutheast();

    return latLongToPixelXY(se.latitude, se.longitude, 10).x - latLongToPixelXY(nw.latitude, nw.longitude, 10).x;

}

function latLongToPixelXY(latitude, longitude, levelOfDetail) {

    var sinLatitude = Math.sin(latitude * Math.PI / 180);
    var pixelX = ((longitude + 180) / 360) * 256 * (2 << (levelOfDetail - 1));
    var pixelY = (0.5 - Math.log((1 + sinLatitude) / (1 - sinLatitude)) / (4 * Math.PI)) * 256 * (2 << (levelOfDetail - 1));

    return {
        x: pixelX,
        y: pixelY};

}
var MM=Microsoft.Maps;
var映射;
var场景;
var摄像机;
var渲染器;
var平面;
var startWidth;
var boxe;
var raycaster=new THREE.raycaster();
函数loadMap(){
document.getElementById(“log”).innerHTML+=“>加载映射”;
map=新的MM.map(document.getElementById(“mapDiv”){
中心:新的毫米位置(45.06,7.66),
缩放:10,
惯性强度:0.4,
mapTypeId:Microsoft.Maps.mapTypeId.birdseye,
labelOverlay:Microsoft.Maps.labelOverlay.hidden,
残疾鸟眼:没错,
全权证书:“xxx”});
addHandler(映射'viewchange',updatePosition);
装载画布(地图);
}
函数loadCanvas(地图){
document.getElementById(“log”).innerHTML+=“>启动webgl”;
var mapDiv=map.getRootElement();
var width=map.getWidth();
var height=map.getHeight();
renderer=new THREE.WebGLRenderer({alpha:true});
renderer.shadowMap.enabled=true;
设置大小(宽度、高度);
mapDiv.parentNode.lastChild.appendChild(renderer.doElement);
renderer.doElement.style.position=“绝对”;
renderer.doElement.style.top=“0px”;
renderer.doElement.style.left=“0px”;
场景=新的三个。场景();
摄像机=新的三个透视摄像机(75,宽/高,11000);
摄像机位置z=100;
document.getElementById(“log”).innerHTML+=“>加载纹理”;
document.getElementById(“log”).innerHTML+=“>创建框”;
var geometry=新的3.BoxGeometry(5,5,10);
var material=new THREE.MeshPhongMaterial({color:0xaaaaaa});
var cube=新的三个网格(几何体、材质);
立方体位置z=5;
var pivot=new THREE.Object3D();
pivot.lat=45.06;
pivot.lon=7.66;
立方体位置x=10;
pivot.add(立方体);
场景。添加(轴);
拳击=枢轴;
plane=新的THREE.Mesh(新的THREE.PlaneBuffer几何体(10001000),新的THREE.MeshPhongMaterial({color:0xFFFFFF00}));
平面可见=假;
场景。添加(平面);
var axisHelper=新的三个.axisHelper(10);
添加(axisHelper);
var灯=新的三个环境灯(0x404040);
场景。添加(灯光);
var pointLight=新的三点光源(0xffffff);
点光源位置设置(0,300,200);
场景。添加(点光源);
startWidth=getCurrentWidth();
render();
更新位置({linear:true});
document.getElementById(“log”).innerHTML=“”;
}
函数render(){
渲染器。渲染(场景、摄影机);
}
函数更新位置(e){
如果(!e.linear)
{
var currentWidth=getCurrentWidth();
var diff=起始宽度/当前宽度;
盒刻度设置(差,差,差);
}
var mouse=new THREE.Vector2();
var纬度=boxe.lat;
var经度=boxe.lon;
var PixelCoordination=map.tryLocationPixel(新的MM.位置(纬度、经度),MM.PixelReference.control);
mouse.x=(pixelCoordinate.x/window.innerWidth)*2-1;
mouse.y=-(pixelCoordinate.y/window.innerHeight)*2+1;
raycaster.setFromCamera(鼠标、相机);
var intersects=光线投射器。intersectObject(平面);
如果(相交长度>0){
boxe.position.x=与[0]相交。点.x;
boxe.position.y=与[0]相交。点.y;
}
window.requestAnimationFrame(渲染);
}
函数getCurrentWidth(){
var bounds=map.getBounds();
var nw=bounds.getNorthwest();
var se=map.getBounds().getSoutheast();
返回latLongToPixelXY(东南纬度,东南经度,10).x-latLongToPixelXY(西北纬度,西北经度,10).x;
}
函数X(纬度、经度、详细等级){
var sinlation=Math.sin(纬度*Math.PI/180);
var pixelX=((经度+180)/360)*256*(2)