index.html
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>instance模型 - 模型添加到图层上</title>
<style type="text/css">
html,body{margin:0px;height:100%;width:100%}
.container{width:100%;height:100%}
</style>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/maptalks/dist/maptalks.min.js"></script>
<script type="text/javascript" src="/gltf-examples/lib/maptalksgl.js"></script>
<script type="text/javascript" src="/gltf-examples/lib/maptalks.gltf.js"></script>
<body>
<div id="map" class="container"></div>
<script>
var map = new maptalks.Map('map', {
center: [-0.113049,51.498568],
zoom: 14,
pitch: 75,
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
subdomains: ['a','b','c','d'],
attribution: '© <a href="http://osm.org">OpenStreetMap</a> contributors, © <a href="https://carto.com/">CARTO</a>'
})
});
var url = '../../../../resource/gltf/cube-animation/cube.gltf';
var symbol = {
animation: true,
loop: true,
url: url,
rotation: [90, 0, 0],
uniforms: {
'baseColorFactor': [0.8, 0.0, 0.0, 1.0]
}
};
var gltflayer = new maptalks.GLTFLayer('groupgltflayer').addTo(map);
var position = map.getCenter();
//准备groupgltfmarker的数据
var data = [];
var coordinate = position.add(0, 0);
for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
data.push({
coordinates : coordinate.add(i * 0.01, j * 0.01),
translation : [0, 0, 0],
rotation : [0, 0, 0],
scale : [1, 1, 1],
color : [i / 15 + 0.2, 0.1 + j / 12, 1.0 - (i + j) / 20, 0.9]
});
}
}
var gltfmarker = new maptalks.GroupGLTFMarker(data, {
symbol: symbol
}).addTo(gltflayer);
</script>
</body>
</html>