Skip to main content
Version: Next

Configuration

The CanvasTileEngineConfig object controls the initial state and behavior of the engine.

Core Settings

These are the fundamental settings required to initialize the engine.

PropertyTypeDefaultDescription
scalenumberRequiredThe initial zoom level (pixels per grid unit).
sizeobjectRequiredThe dimensions of the canvas. See Size Options.
responsive"preserve-scale" | "preserve-viewport" | falsefalseEnable responsive mode. See Responsive Mode.
backgroundColorstring"#ffffff"The background color of the canvas.
minScalenumberscale * 0.5Minimum allowed zoom level.
maxScalenumberscale * 2Maximum allowed zoom level.
gridAlignedbooleanfalseSnap initial center to cell centers (x.5, y.5) for pixel-perfect grid alignment.

Size Options

Define the canvas dimensions and constraints.

PropertyTypeDefaultDescription
widthnumberRequiredInitial width in pixels.
heightnumberRequiredInitial height in pixels.
minWidthnumber100Minimum width allowed during resize.
minHeightnumber100Minimum height allowed during resize.
maxWidthnumberInfinityMaximum width allowed during resize.
maxHeightnumberInfinityMaximum height allowed during resize.

Responsive Mode

Enable responsive mode to automatically resize the canvas when its container changes size. Two modes are available:

ModeDescription
"preserve-scale"Scale stays constant, visible tile count changes as container resizes.
"preserve-viewport"Visible tile count stays constant, scale adjusts based on width.

preserve-scale

The scale remains fixed while the visible tile count changes based on the container size. The wrapper size is fully controlled by your CSS.

const config = {
size: { width: 800, height: 600 },
scale: 50,
responsive: "preserve-scale",
};

preserve-viewport

The visible tile count remains fixed while the scale adjusts based on container width. The engine automatically:

  • Sets wrapper width: 100%
  • Calculates height based on the tile ratio from size.width / size.height
  • Derives minWidth / maxWidth from minScale / maxScale:
    • minWidth = minScale × (size.width / scale)
    • maxWidth = maxScale × (size.width / scale)
  • Derives minHeight / maxHeight similarly based on the tile ratio

This ensures the scale always stays within minScale and maxScale bounds.

const config = {
size: { width: 800, height: 600 }, // 16×12 tiles at scale 50
scale: 50,
minScale: 25, // → minWidth: 400px, minHeight: 300px
maxScale: 100, // → maxWidth: 1600px, maxHeight: 1200px
responsive: "preserve-viewport",
};
Automatic Size Limits

In preserve-viewport mode, size.minWidth, size.maxWidth, size.minHeight, and size.maxHeight are ignored. The size limits are automatically calculated from minScale and maxScale to maintain the configured tile count.

Limitations

When responsive mode is enabled:

  • resize() method is disabled (canvas size is controlled by the wrapper element)
  • eventHandlers.resize is ignored (resizing is handled automatically)

Interactions

Control how the user interacts with the map via eventHandlers.

HandlerDefaultDescription
clickfalseEnable click events on grid cells.
rightClickfalseEnable right click events on grid cells.
hoverfalseEnable hover events and tracking.
dragfalseEnable panning by dragging the map.
zoomfalseEnable zooming with the mouse wheel.
resizefalseAutomatically resize canvas when container changes.
// Example usage
eventHandlers: {
drag: true,
zoom: true,
click: true
}

Map Boundaries

Restrict camera movement to a specific area of the world. This is useful for preventing users from scrolling beyond your map limits.

PropertyTypeDefaultDescription
minXnumber-InfinityMinimum X coordinate the camera can reach.
maxXnumberInfinityMaximum X coordinate the camera can reach.
minYnumber-InfinityMinimum Y coordinate the camera can reach.
maxYnumberInfinityMaximum Y coordinate the camera can reach.
// Example: Restrict map to a 200x200 grid centered at origin
bounds: {
minX: -100,
maxX: 100,
minY: -100,
maxY: 100
}

// Example: Only restrict horizontal movement
bounds: {
minX: 0,
maxX: 500,
minY: -Infinity,
maxY: Infinity
}
Runtime Updates

You can change boundaries at runtime using engine.setBounds(). See Camera Controls for details.

Visual Customization

Coordinate Overlay

Display X/Y axes numbers on the edges of the screen.

PropertyTypeDefaultDescription
enabledbooleanfalseShow the coordinate numbers.
shownScaleRange{ min, max }AllOnly show coordinates when zoom is within this range.

Cursors

Customize the mouse cursor for different states.

StateDefaultDescription
default"default"The standard cursor.
move"move"The cursor shown while dragging the map.

Debugging

Built-in tools to help you develop. Enable via the debug object.

FeatureDefaultDescription
enabledfalseMaster switch for all debug features.
hud.enabledfalseShow HUD panel.
hud.topLeftCoordinatesfalseDisplay top-left world coords.
hud.coordinatesfalseDisplay center coords.
hud.scalefalseDisplay current scale.
hud.tilesInViewfalseDisplay visible tile counts.
hud.fpsfalseDisplay current FPS (continuously updated).
eventHandlers.*trueDebug-time overrides for click/hover/drag/zoom/resize.

Full TypeScript Type

For reference, here is the complete type definition:

export type CanvasTileEngineConfig = {
scale: number;
maxScale?: number;
minScale?: number;
backgroundColor?: string;
gridAligned?: boolean;
size: {
width: number;
height: number;
minWidth?: number;
minHeight?: number;
maxWidth?: number;
maxHeight?: number;
};
responsive?: "preserve-scale" | "preserve-viewport" | false;
eventHandlers?: {
click?: boolean;
rightClick?: boolean;
hover?: boolean;
drag?: boolean;
zoom?: boolean;
resize?: boolean;
};
coordinates?: {
enabled?: boolean;
shownScaleRange?: { min: number; max: number };
};
cursor?: {
default?: string;
move?: string;
};
debug?: {
enabled?: boolean;
grid?: {
enabled?: boolean;
color?: string;
lineWidth?: number;
};
hud?: {
enabled?: boolean;
topLeftCoordinates?: boolean;
coordinates?: boolean;
scale?: boolean;
tilesInView?: boolean;
};
eventHandlers?: {
click?: boolean;
hover?: boolean;
drag?: boolean;
zoom?: boolean;
resize?: boolean;
};
};
};