Once you have created aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/spatialillusions/milsymbol/llms.txt
Use this file to discover all available pages before exploring further.
Symbol object and configured its options, milsymbol can deliver the rendered symbol in several formats. You can get an SVG string for lightweight web use, a DOM element for direct insertion into the page, an HTMLCanvasElement for pixel-based rendering, an OffscreenCanvas for use in Web Workers, or a base64 data URL for embedding in <img> tags and CSS. All formats are derived from the same underlying draw instructions and stay synchronized as you update the symbol via setOptions().
asSVG() — SVG String
Returns the symbol as a complete SVG XML string. This is the most common format for web applications. SVG is resolution-independent and lightweight — creating 1,000 symbols takes under 20 ms in most environments.
asDOM() — SVG DOM Element
Returns the symbol as a live SVG DOM Element (an SVGElement). This is useful when you want to manipulate the symbol element further with JavaScript before inserting it, or when you need to append multiple symbols to a container.
- asDOM
- asSVG
asCanvas(factor?) — HTMLCanvasElement
Returns the symbol as an HTMLCanvasElement. An optional factor argument multiplies the canvas pixel dimensions, producing a higher-resolution canvas for HiDPI (Retina) screens or high-quality exports — without affecting the numbers returned by getSize() or getAnchor().
Using with OpenLayers
The
factor argument scales the canvas pixel buffer but does not affect the values returned by getSize(), getAnchor(), or getOctagonAnchor(). Those methods always return values in the logical coordinate space (at factor 1). When placing the canvas on screen, use the logical size values for layout calculations.asOffscreenCanvas(factor?) — OffscreenCanvas
Returns the symbol as an OffscreenCanvas. This is the counterpart to asCanvas() for use in Web Workers, where the DOM is not available. The optional factor argument behaves identically to asCanvas().
toDataURL() — Base64 SVG Data URL
Returns the SVG symbol as a base64-encoded data: URI string. This is useful when you need to assign the symbol as the src of an <img> element, a CSS background-image, or a Leaflet icon URL.
PNG Data URL
toDataURL() produces an SVG data URL. For a PNG base64 data URL, chain asCanvas() and then call the native canvas toDataURL() method:
Leaflet icon example
getSize() — Symbol Dimensions
Returns an object with the width and height of the rendered symbol in pixels. These dimensions include any text modifiers and direction arrows, and they change as modifiers are added or removed.
getAnchor() — Insertion Point
Returns the anchor point { x, y } measured from the top-left corner of the symbol image. This is the point that should align with the geographic coordinate of the symbol — for a ground unit, typically the bottom-center of the frame. Use this when placing symbols as map markers.
getOctagonAnchor() — Octagon Center
Returns the center of the symbol octagon { x, y } measured from the top-left corner of the image. This is the geometric center of the symbol frame, useful when you want to center a symbol on a point rather than anchor it at its insertion point.
Choosing the Right Format
SVG / asDOM
Best for web applications where SVG is supported. Resolution-independent, lightweight, and easily styled with CSS. Use
asSVG() when you need a string, asDOM() when you need a live element.Canvas
Best for pixel-based rendering — game engines, canvas-based map layers (Leaflet
L.Canvas, etc.), server-side rendering with node-canvas, or wherever SVG is unavailable.OffscreenCanvas
Best for Web Workers — lets you generate symbols off the main thread and transfer bitmaps for maximum UI responsiveness.
toDataURL / PNG
Best for embedding in
<img> tags, CSS backgrounds, or APIs that only accept image URLs. Use .asCanvas().toDataURL() when you need a PNG instead of SVG.Performance
milsymbol is designed for high-volume symbol generation. Creating 1,000 symbols with SVG output takes under 20 ms in most browser environments. For best performance:- Supply all options at construction time rather than calling
setOptions()multiple times. - Use
asCanvas()with an appropriatefactorfor HiDPI screens rather than using CSS scaling. - Cache
getSize()andgetAnchor()results if you are placing symbols in a tight rendering loop, as these values only change when options change.
