<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://resource.mapray.com/mapray-js/v0.9.6/mapray.min.js"></script>
<script src="https://resource.mapray.com/ui/v0.9.6/maprayui.min.js"></script>
<link rel="stylesheet" href="https://resource.mapray.com/styles/v1/mapray.css">
<style>
html, body, div#mapray-container { margin: 0; padding: 0; height: 100%; }
</style>
</head>
<body>
<div id="mapray-container"></div>
</body>
</html>
<script>
class CustomViewer extends maprayui.StandardUIViewer {
constructor( container, apikey ) {
super( container, apikey);
const pinEntity = new mapray.PinEntity( this.viewer.scene );
pinEntity.addPin( new mapray.GeoPoint( 139.699985, 35.690777, 40 ), { id: "pin", size: 40, bg_color: [1, 0, 0] });
this.viewer.scene.addEntity( pinEntity );
const pinEntry = pinEntity.getEntry( "pin" );
// Create linear curve.
const curve1 = new mapray.animation.KFLinearCurve( mapray.animation.Type.find( "number" ) );
const curve2 = new mapray.animation.KFLinearCurve( mapray.animation.Type.find( "vector3" ) );
curve1.setKeyFrames([
mapray.animation.Time.fromNumber( 0 ), 10.0,
mapray.animation.Time.fromNumber( 1 ), 25.0,
mapray.animation.Time.fromNumber( 2 ), 40.0,
]);
const keyframes2 = [
mapray.animation.Time.fromNumber( 0 ), [ 0.0, 1.0, 0.0 ],
mapray.animation.Time.fromNumber( 1 ), [ 0.0, 0.0, 1.0 ],
mapray.animation.Time.fromNumber( 2 ), [ 1.0, 0.0, 0.0 ],
];
for ( let t = 0; t <= 3; ++t ) {
keyframes2.push(
mapray.animation.Time.fromNumber( 2.5 + t ), [ 1.0, 1.0, 1.0 ],
mapray.animation.Time.fromNumber( 3.0 + t ), [ 1.0, 0.0, 0.0 ],
);
}
curve2.setKeyFrames( keyframes2 );
// Create updater.
this.totalTime = 0;
this.isAnimationStart = false;
this.updater = new mapray.animation.Updater();
// Bind "size" and "bg_color" param to updater and curve.
pinEntry.animation.bind( "size", this.updater, curve1 );
pinEntry.animation.bind( "bg_color", this.updater, curve2 );
}
/** @override */
onUpdateFrame( delta_time ) {
super.onUpdateFrame( delta_time );
if ( this.isAnimationStart ) {
this.totalTime += delta_time;
this.updater.update( mapray.animation.Time.fromNumber( this.totalTime ) );
}
}
/** @override */
onMouseDown( point, event ) {
super.onMouseDown( point, event );
this.totalTime = 0;
}
startAnimation() {
this.totalTime = 0;
this.isAnimationStart = true;
console.log( "start animation" );
}
}
// Set up your API Key, which can be created in Mapray Cloud.
const apikey = "<YOUR_MAPRAY_API_KEY>";
const uiviewer = new CustomViewer( "mapray-container", apikey);
uiviewer.setCameraPosition({
longitude: 139.697475,
latitude: 35.682494,
height: 420
});
uiviewer.setLookAtPosition({
longitude: 139.699985,
latitude: 35.690777,
height: 35
});
uiviewer.startAnimation();
</script>