百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
M

map-gesture-controls

> 包管理
开源

通过网络摄像头使用手势控制 OpenLayers、Google Maps 和 Leaflet。使用 MediaPipe 实时跟踪手部,实现平移、放大和导航等功能。

100 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

通过网络摄像头使用手势控制 OpenLayers、Google Maps 和 Leaflet。使用 MediaPipe 实时跟踪手部,实现平移、放大和导航等功能。

Map Gesture Controls: Hand Tracking for OpenLayers, Google Maps & Leaflet

Control web maps with hand gestures using your webcam. No mouse, no touch, no backend.

Using MediaPipe hand-tracking WASM running entirely in the browser, users can pan a map with the left hand, zoom with the right hand, and rotate with both hands. Each action can be triggered with either a fist or a pinch -- whichever feels more natural. This makes maps accessible in kiosk and exhibit environments, enables hands-free interaction for users with limited mobility, and opens up novel touchless UI experiences. Camera data never leaves the device.

Supports OpenLayers | Google Maps | Leaflet

Live demo and documentation

How it works

  1. Webcam capture: GestureController opens the user's camera and feeds each frame to MediaPipe Hand Landmarker, which returns 21 3-D landmarks per detected hand.
  2. Gesture classification: GestureStateMachine classifies each frame using classifyGesture(): left fist or pinch = pan; right fist or pinch = zoom (vertical movement); both hands active = rotate; anything else = idle. A configurable dwell timer (actionDwellMs, default 80 ms) prevents flickering, and a grace period (releaseGraceMs, default 150 ms) smooths gesture releases.
  3. OL integration: OpenLayersGestureInteraction translates frame-over-frame hand deltas into ol/Map pan pixel offsets and zoom-level adjustments, applying dead-zone filtering and exponential smoothing before every update.

Packages

Package npm Description
@map-gesture-controls/core Gesture detection engine, map-agnostic. Exports GestureController, GestureStateMachine, WebcamOverlay, classifyGesture, all types, constants, and utility functions.
@map-gesture-controls/ol OpenLayers integration. Re-exports the full core API and adds GestureMapController and OpenLayersGestureInteraction.
@map-gesture-controls/google-maps Google Maps integration. Re-exports the full core API and adds GestureMapController and GoogleMapsGestureInteraction.
@map-gesture-controls/leaflet Leaflet integration. Re-exports the full core API and adds GestureMapController and LeafletGestureInteraction.

Most users only need the ol, google-maps, or leaflet package. Each re-exports everything from core.

Requirements

  • A modern browser with WebGL and getUserMedia (webcam permission).
  • OpenLayers 10.x, Google Maps JavaScript API, or Leaflet 1.9.x.

Install

OpenLayers:

bash
npm install @map-gesture-controls/ol ol

Google Maps:

bash
npm install @map-gesture-controls/google-maps @googlemaps/js-api-loader
npm install -D @types/google.maps

Leaflet:

bash
npm install @map-gesture-controls/leaflet leaflet
npm install -D @types/leaflet

Publish flow (maintainers): run npm run build so the dist/ folder exists before npm publish (this repo does not commit dist/).

Usage

OpenLayers

You need a container element in your HTML (e.g. ) and an OpenLayers Map instance:

…

Google Maps

typescript
import { Loader } from '@googlemaps/js-api-loader';
import { GestureMapController } from '@map-gesture-controls/google-maps';
import '@map-gesture-controls/google-maps/style.css';

const loader = new Loader({ apiKey: 'YOUR_API_KEY', version: 'weekly' });
const { Map } = await loader.importLibrary('maps');

const map = new Map(document.getElementById('map')!, {
  center: { lat: 0, lng: 0 },
  zoom: 2,
  mapId: 'YOUR_MAP_ID', // enables vector maps (required for rotation)
});

const controller = new GestureMapController({ map });

await controller.start();

controller.stop();

You need a Google Maps API key and a Map ID from the Google Cloud Console. Create the Map ID with the Vector map type to enable rotation support. For local development, add both to a .env file:

VITE_GOOGLE_MAPS_API_KEY=your_api_key
VITE_GOOGLE_MAPS_MAP_ID=your_map_id

See the Google Maps Getting Started guide for full setup details.

Leaflet

typescript
import L from 'leaflet';
import 'leaflet/dist/leaflet.css';
import { GestureMapController } from '@map-gesture-controls/leaflet';
import '@map-gesture-controls/leaflet/style.css';

const map = L.map('map').setView([52.37, 4.9], 10);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  attribution:
    '&copy; OpenStreetMap contributors',
}).addTo(map);

const controller = new GestureMapController({ map });

await controller.start();

controller.stop();

No API key needed. Leaflet uses OpenStreetMap tiles by default. Rotation is supported via CSS transforms on the map pane.

See the Leaflet Getting Started guide for full setup details.

Optional config: webcam, tuning, and debug. See the Configuration section below.

Configuration

All options are optional. Pass only the keys you want to override; the rest use sensible defaults.

typescript
// `map` is your ol/Map or google.maps.Map instance (see Usage above)
const controller = new GestureMapController({
  map,
  webcam: {
    position: 'top-left', // move overlay to top-left corner
    width: 240, // narrower overlay
    height: 180,
    margin: 24, // 24 px from viewport edges
    opacity: 0.7,
  },
  tuning: {
    actionDwellMs: 40, // faster gesture confirmation
    releaseGraceMs: 80, // shorter grace period
    panDeadzonePx: 0, // direct panning for slow movement
  },
  debug: true, // log gesture mode to console
});

webcam options (WebcamConfig)

Key Type Default Description
enabled boolean true Show/hide the overlay entirely.
mode 'corner' | 'full' | 'hidden' 'corner' Display mode.
position 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' 'bottom-right' Corner when mode === 'corner'.
width number 320 Overlay width in px (corner mode).
height number 240 Overlay height in px (corner mode).
margin number 16 Distance in px from the nearest edge(s).
opacity number 0.85 CSS opacity (0 to 1).

tuning options (TuningConfig)

Key Type Default Description
actionDwellMs number 80 Hold time (ms) before a gesture is confirmed.
releaseGraceMs number 150 Grace period (ms) before returning to idle after gesture ends.
panDeadzonePx number 0 Minimum pixel movement to register a pan.
zoomDeadzoneRatio number 0.005 Minimum distance-ratio change to register a zoom.
rotateDeadzoneRad number 0.005 Minimum wrist-to-wrist angle change (radians) to emit a rotate delta. Lower values respond to smaller wrist tilts; higher values filter micro jitter.
smoothingAlpha number 0.35 Exponential smoothing factor (0 = max smooth, 1 = raw).
minDetectionConfidence number 0.65 MediaPipe minimum detection confidence.
minTrackingConfidence number 0.65 MediaPipe minimum tracking confidence.
minPresenceConfidence number 0.60 MediaPipe minimum presence confidence.

Development

bash
npm install
npm run dev

Runs the demo in examples/ (Vite, port 5173 by default).

bash
npm run build

Produces the library in dist/ (JS, declarations, bundled CSS).

bash
npm run type-check

Gestures

Both fist and pinch (thumb and index finger touching) trigger the same actions, use whichever feels more comfortable.

Mode Condition Action How to perform
Pan Left hand fist or pinch (right hand absent or open) Move left

Issues· 2 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptaccessibilitycomputer-visiongesture-controlgesture-recognition

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类包管理
定价开源

> 相关工具

N
npm
Node.js 默认包管理器
P
pnpm
高效节省磁盘的 Node 包管理器
I
is-gif
Check if a Buffer/Uint8Array is a GIF image