該方法可實現(xiàn)百度上拾取的經(jīng)緯度葱峡,在你cesium自定義3d tiles瓦片場景中恍涂,添加3d (gltf)模型貼地行走動畫哑舒,3d(gltf)上面可以有標(biāo)牌顯示模型名字
? //starLng(起始點(diǎn)經(jīng)度), startLat(起始點(diǎn)緯度), endLng(結(jié)束點(diǎn)經(jīng)度), endLat(結(jié)束點(diǎn)緯度)
*地圖坐標(biāo)轉(zhuǎn)換參考文章http://www.reibang.com/p/2ec37020041e
function addCarModel(starLng, startLat, endLng, endLat) {
var sa1 = bd09togcj02(starLng, startLat);? ? //轉(zhuǎn)換拿到的百度經(jīng)度為火星坐標(biāo)? ? ? ??
var sa2 = gcj02towgs84(sa1[0], sa1[1]);? ? ??//轉(zhuǎn)換拿到的百度緯度為火星坐標(biāo)
var ea1 = bd09togcj02(endLng, endLat);? ???//轉(zhuǎn)換拿到的火星經(jīng)度為wgs-84坐標(biāo)
var ea2 = gcj02towgs84(ea1[0], ea1[1]);? ? ?//轉(zhuǎn)換拿到的火星緯度為wgs-84坐標(biāo)
var pos1 = Cesium.Cartesian3.fromDegrees(sa2[0], sa2[1]);? ?
var pos2 = Cesium.Cartesian3.fromDegrees(ea2[0], ea2[1]);? ?? ?
var carCzml = [{
id: "document",
version: "1.0",
clock: {
interval: "2018-07-19T15:18:00Z/2018-07-19T15:18:30Z",
currentTime: "2018-07-19T15:18:00Z",
// multiplier: 5,
// range: "LOOP_STOP",
// step: "SYSTEM_CLOCK_MULTIPLIER"
}
},
{
id: "car1",
model: {
gltf: "img/car03.glb",
scale: 6.0,
minimumPixelSize: 168,
maximumScale: 200000,
},
label: {
text: "汽車001",
fillColor: {
rgba: [255, 254, 249, 255],
},
font: "14pt Lucida Console",
horizontalOrigin: "LEFT",
pixelOffset: {
cartesian2: [-30, -64],
},
show: true,
style: "FILL",
showBackground: true,
backgroundColor: {
rgba: [252, 12, 0, 200],
}
},
position: {
interpolationAlgorithm: "LINEAR",
forwardExtrapolationType: "HOLD",
cartesian: [
"2018-07-19T15:18:00Z", pos1.x, pos1.y, pos1.z,
"2018-07-19T15:18:30Z", pos2.x, pos2.y, pos2.z
]
}
},
{
id: "Polyline",
polyline: {
positions: {
cartesian: [
pos1.x, pos1.y, pos1.z,
pos2.x, pos2.y, pos2.z
]
},
material: {
polylineOutline: {
color: {
rgba: [255, 255, 0, 255]
},
outlineColor: {
rgba: [0, 0, 0, 255]
},
outlineWidth: 2
}
},
width: 10,
clampToGround: true
}
}
];
var scene = viewer.scene;
var clock = viewer.clock;
var entity;
var positionProperty;
// czml加載到場景中
var carModel = viewer.dataSources.add(Cesium.CzmlDataSource.load(carCzml)).then(function(dataSource) {
entity = dataSource.entities.getById("car1");
positionProperty = entity.position;
entity.orientation = new Cesium.VelocityOrientationProperty(entity.position); ?
});
if (scene.clampToHeightSupported) {
? tiles.initialTilesLoaded.addEventListener(start);? ? //tiles為自定義3d場景瓦片
} else {
? window.alert("瀏覽器不支持貼地锅知!");
}
function start() {
? clock.shouldAnimate = true;
? var objectsToExclude = [entity];
? scene.postRender.addEventListener(function () {
? ? var position = positionProperty.getValue(clock.currentTime);
? ? entity.position = scene.clampToHeight(position, objectsToExclude);
? });
}
return carModel;
}