Convert route coordinates into a snapshot image with customizable styling options. Perfect for visualizing routes from map services like Kakao Maps into customizable canvas images.
npm install route-snap
# or
yarn add route-snap
# or
pnpm add route-snap
- Convert route coordinates to image
- Customizable canvas size and styling
- Background grid support
- Built-in Kakao Maps adapter
- TypeScript support
import { RouteSnapshot, fromKakaoLatLng } from "route-snap";
// Basic usage
const snapshot = new RouteSnapshot({
canvasRef: { current: canvasElement },
routes: coordinates,
});
const imageUrl = snapshot.generate();
// With Kakao Maps + custom config
const snapshot = new RouteSnapshot({
canvasRef: { current: canvasElement },
routes: fromKakaoLatLng(kakaoCoordinates),
config: {
grid: {
color: "red",
gap: 15,
},
},
});
interface RouteSnapshotOptions {
canvasRef: { current: HTMLCanvasElement | null }; // Canvas element reference
routes: Array<{ latitude: number; longitude: number }>; // Route coordinates
}
interface RouteSnapshotConfig {
canvas?: {
width?: number; // default: 600
height?: number; // default: 600
paddingX?: number; // default: 60
paddingY?: number; // default: 60
bgColor?: string; // default: '#f0f0f0'
};
grid?: {
enabled?: boolean; // default: true
color?: string; // default: '#cccccc'
gap?: number; // default: 20
width?: number; // default: 0.5
};
line?: {
color?: string; // default: '#FFAE00'
width?: number; // default: 3
};
}
Here are some examples of different configurations and their results.
const snapshot = new RouteSnapshot({
canvasRef: { current: canvasElement },
routes: coordinates,
},
});
Map Route | Generated Canvas Image |
---|---|
![]() |
![]() |
const snapShot = new RouteSnapshot({
canvasRef: { current: canvasRef.current },
routes: coordinates,
config: {
grid: {
color: "#fcfcfc",
},
canvas: {
bgColor: "#0c0c0c",
},
line: {
color: "yellow",
width: 8,
},
},
});
![Dark theme with grid](https://private-user-images.githubusercontent.com/96780693/407232751-6ae889fb-1c4b-4962-bd36-f62f8b377245.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTUyMzMsIm5iZiI6MTczODk1NDkzMywicGF0aCI6Ii85Njc4MDY5My80MDcyMzI3NTEtNmFlODg5ZmItMWM0Yi00OTYyLWJkMzYtZjYyZjhiMzc3MjQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDE5MDIxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2OWJhMmIxOTc0MjRlOTdjYzY2MWJmYzRlZjczZjA2OWZiYzM0ZmQ3YTlhZjc2ZGI2MmVhMThlYzBhNmM1ODgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.HdjL5BwudIzgdqTzDo5e4vzLaJbomvWc_KwgZJ41BDs)
const snapShot = new RouteSnapshot({
canvasRef: { current: canvasRef.current },
routes: coordinates,
config: {
grid: {
enabled: false,
},
canvas: {
bgColor: "#0c0c0c",
},
line: {
color: "yellow",
width: 8,
},
},
});
![Route snapshot with dark theme](https://private-user-images.githubusercontent.com/96780693/407233521-7e4c2a40-dac1-40f2-bdbb-537c45a60100.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5NTUyMzMsIm5iZiI6MTczODk1NDkzMywicGF0aCI6Ii85Njc4MDY5My80MDcyMzM1MjEtN2U0YzJhNDAtZGFjMS00MGYyLWJkYmItNTM3YzQ1YTYwMTAwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA3VDE5MDIxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM4MjYwMmQ0YjhhNTYwMDk3YWQ5ZWFjODI0YmRiNGY5MDMzM2I1YmUxNjJhNjI2ODNhZmM2M2IwZjc4ZWM2NzImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.IFA_F3oAA3nNnBFRzEdLBVQNlGL0UDobKzdj7qh9wtE)
- Canvas size and background color
- Grid visibility, color, and gap size
- Route line color and width
- Padding and other layout options
Check the Configuration section for all available options.