Skip to main content

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.
backgroundColorstring"#ffffff"The background color of the canvas.
minScalenumberscale * 0.5Minimum allowed zoom level.
maxScalenumberscale * 2Maximum allowed zoom level.

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.

Interactions

Control how the user interacts with the map via eventHandlers.

HandlerDefaultDescription
dragfalseEnable panning by dragging the map.
zoomfalseEnable zooming with the mouse wheel.
clickfalseEnable click events on grid cells.
hoverfalseEnable hover events and tracking.
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.
grid.enabledfalseDraw a grid overlay.
grid.color"rgba(255,255,255,0.25)"Grid line color.
grid.lineWidth1Grid line width.
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 = {
renderer?: "canvas";
scale: number;
maxScale?: number;
minScale?: number;
backgroundColor?: string;
size: {
width: number;
height: number;
minWidth?: number;
minHeight?: number;
maxWidth?: number;
maxHeight?: number;
};
eventHandlers?: {
click?: 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;
};
};
};