setCenterOffset と setMapAreaPadding は同時に使えません。flyTo の第1引数 FlightDestination は各要素をコールバック関数で返す形式です。
オブジェクトのプロパティ(center/zoom/tilt)を直接渡す形式は誤りです。setCenterBasedOnLatLngList の第3〜6引数(maxZoomLevel, padding, step, zoomLevelFixFunc)はすべて任意です。setMaxTilt は60度以上には設定できません。import * as GIA from '@ntj/gaia';
const LOCATION_TO = new GIA.value.LatLng(35.68142, 139.76588194);
const LOCATION_BACK = new GIA.value.LatLng(35.681109, 139.767165);
class EaseInOutCubic implements GIA.value.animation.Easing {
calculateAnimationProgress(progress: number): number {
if (progress < 0.5) {
return 4 * progress ** 3;
}
return 1 - ((-2 * progress + 2) ** 3) / 2;
}
}
const animationOption = new GIA.value.animation.AnimationOption(2.0, new EaseInOutCubic());
// 行き
map.flyTo(
{
locationCallback: () => LOCATION_TO,
zoomLevelCallback: () => 18.5,
tiltCallback: () => 60,
directionCallback: () => 90,
},
animationOption,
);
// 戻り
map.flyTo(
{
locationCallback: () => LOCATION_BACK,
zoomLevelCallback: () => 17,
tiltCallback: () => 0,
directionCallback: () => 0,
},
animationOption,
);
import * as GIA from '@ntj/gaia';
const points = locations.map((l) => new GIA.value.LatLng(l.lat, l.lng));
map.setCenterBasedOnLatLngList(
points,
true, // アニメーション
17, // 最大ズームレベル
undefined, // パディング
0.2, // step
(z) => z // zoomLevelFixFunc
);
import * as GIA from '@ntj/gaia';
const northWest = new GIA.value.LatLng(35.70, 139.75);
const southEast = new GIA.value.LatLng(35.67, 139.79);
const rect = new GIA.object.LatLngRect(northWest, southEast);
map.moveBasedOnLatLngRect(rect, true, 18);
import * as GIA from '@ntj/gaia';
map.getCanvas().addEventListener('click', (ev) => {
const latlng = map.getLatLngFromClientCoord(new GIA.value.Point(ev.clientX, ev.clientY));
if (!latlng) return;
console.log('クリック緯度経度:', latlng);
// 2点間のピクセル距離(長距離移動検知などに利用)
const origin = map.getCenter();
const dist = GIA.util.calcPixelDistance(origin, latlng, map.getZoomLevel());
console.log('ピクセル距離:', dist);
});
import * as GIA from '@ntj/gaia';
map.setMapDirectionChangeListener((direction) => {
compassIcon.style.transform = `rotate(${direction}deg)`;
});
import * as GIA from '@ntj/gaia';
// 左に400pxのUIパネルがあるケース
map.setMapAreaPadding(new GIA.value.RectExtension(100, 0, 400, 0));
// パディングをクリア
map.setMapAreaPadding(new GIA.value.RectExtension(0, 0, 0, 0));
中心座標・移動・飛行・傾き・方位角を操作する — 詳細な使用例
地図の視点(位置・ズーム・傾き・回転)を制御するメソッド群です。
中心座標
getCenter()setCenter(latlng)getTargetLocation()setTargetLocation(latlng)setCenterOffset使用時に中心とずれる)移動
moveTo(latlng, zoom)flyTo(destination)moveBasedOnLatLngRect(rect)setCenterBasedOnLatLngList(list)getZoomLevelWithLatLngRect(rect)setCenterOffset(offset)setMapAreaPadding(padding)傾き (Tilt / Polar)
getTilt()setTilt(tilt)setMaxTilt(maxTilt)setTiltWithZoomOptions(opts)getPolar()setPolar(polar)方位角 (Direction)
getDirection()setDirection(dir)setMapDirectionChangeListener(fn)clearMapDirectionChangeListener()setMapTiltChangeListener(fn)clearMapTiltChangeListener()