Open IzumoYamato opened 2 years ago
https://mapv.baidu.com/gl/examples/editor.html#threejs-camera.html //替换示例为如下代码
var map = new window.BMapGL.Map('map_container'); map.setTilt(47); var projection = mapvgl.MercatorProjection; var point = projection.convertLL2MC(new BMapGL.Point(106.542353,29.565448)); var point2 = projection.convertLL2MC(new BMapGL.Point(106.542353,29.565448)); map.centerAndZoom(new BMapGL.Point(106.542353,29.565448), 13); map.enableKeyboard(); map.enableScrollWheelZoom(); map.enableInertialDragging(); map.enableContinuousZoom(); var view = new mapvgl.View({ map: map }); var threeLayer = new mapvgl.ThreeLayer(); view.addLayer(threeLayer); //创建ShapeLayer fetch('./static/chongqing.json').then(function (rs) { return rs.json(); }).then(function (rs) { var data = rs; var polygons = []; var len = data.length; for (var i = 0; i < len; i++) { var line = data[i]; var polygon = []; var pt = [line[1] * 512, line[2] * 512]; for (var j = 3; j < line.length; j += 2) { pt[0] += line[j] / 100 / 2; pt[1] += line[j + 1] / 100 / 2; polygon.push([pt[0], pt[1]]); } if (Math.random() > 0.5) { polygons.push({ geometry: { type: 'Polygon', coordinates: [polygon] }, properties: { height: line[0] / 2 } }); } } var shapeLayer = new mapvgl.ShapeLayer({ color: 'rgba(194, 147, 75, 0.8)', // 柱状图颜色 enablePicked: true, // 是否可以拾取 selectedIndex: -1, // 选中项 selectedColor: '#ee1111', // 选中项颜色 autoSelect: true, // 根据鼠标位置来自动设置选中项 onClick: (e) => { // 点击事件 console.log(e); }, }); view.addLayer(shapeLayer); shapeLayer.setData(polygons); }); var geometry = new THREE.BoxGeometry(20, 20, 20); var material = new THREE.MeshBasicMaterial( { color: 0x0000ff, flatShading: true, wireframe: false } ); //var cube = new THREE.Mesh(geometry, material); //cube.position.z = 10; //以下代码创建InstancedMesh后导致ShapeLayer不可见 var z = 0; var mesh = new THREE.InstancedMesh(geometry, material, 6); for (var xt = 0; xt < 6; xt++) { var matrix = mesh.matrixWorld.clone(); matrix.setPosition(0, 0, z); mesh.setMatrixAt(xt, matrix); z += 50; } threeLayer.add(mesh, point2);
//当不执行threeLayer.add(mesh, point2);这行代码时,效果如下 //当将InstancedMesh添加到ThreeLayer时,将导致上面ShapeLayer里面的对象不可见
threeLayer.add(mesh, point2);
https://mapv.baidu.com/gl/examples/editor.html#threejs-camera.html //替换示例为如下代码