milsymbol is deliberately library-agnostic. It takes a SIDC code and options as input and produces output — either an SVG string viaDocumentation 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.
asSVG(), a Canvas element via asCanvas(), a DOM element via asDOM(), or a Base64 data URL via toDataURL(). Because it generates standard web primitives with no external dependencies, every mainstream mapping and visualization library can consume its output. You don’t change how you call milsymbol; you only decide which output format best fits your target library’s marker API.
Leaflet
Use
L.divIcon with inline SVG or L.icon with a data URL. Correct anchor placement with getAnchor().OpenLayers
Pass a Canvas element directly into
ol.style.Icon with pixel-unit anchor offsets for crisp, high-DPI rendering.Cesium
Supply a data URL as
billboard.image on a 3D entity and correct the default center-origin with pixelOffset.D3
Append an SVG DOM element directly into a D3
g node using asDOM() and position it with getOctagonAnchor().Integration patterns
All integrations follow one of two fundamental patterns, driven by whether the target library expects an HTML/SVG node or a raster image URL.SVG / HTML div icon
Libraries that accept an HTML string or DOM node as a marker icon — like Leaflet’sL.divIcon — can receive symbol.asSVG() directly. The resulting SVG is inline in the DOM, which means CSS hover effects, pointer events, and developer-tool inspection all work as expected.
Image / data URL icon
Libraries that expect a URL for a bitmap marker — like Leaflet’sL.icon, OpenLayers’ ol.style.Icon, or Cesium’s billboard.image — can use symbol.toDataURL(), which returns a Base64-encoded PNG data URL produced from the Canvas renderer.
Anchor points and symbol size
Military symbols are not always square, and their geographic reference point — the point that should sit exactly on the map coordinate — is rarely the top-left corner of the bounding box. milsymbol exposes two methods to retrieve placement metadata after a symbol is rendered:| Method | Return value | Description |
|---|---|---|
getAnchor() | { x, y } | Pixel offset from the top-left of the symbol image to the geographic anchor point |
getOctagonAnchor() | { x, y } | Pixel offset to the center of the symbol’s octagon frame (useful for ORBAT diagrams) |
getSize() | { width, height } | Pixel dimensions of the rendered symbol |
getAnchor() values for each:
| Library | Anchor format | Translation |
|---|---|---|
Leaflet L.divIcon | new L.Point(x, y) | Direct pixel values |
Leaflet L.icon | [x, y] array | Direct pixel values |
OpenLayers ol.style.Icon | [x, y] with anchorXUnits: "pixels" | Direct pixel values |
Cesium billboard.pixelOffset | new Cesium.Cartesian2(dx, dy) | dx = -(anchor.x - size.width / 2), dy = -(anchor.y - size.height / 2) |
D3 SVG transform | translate(-x, -y) | Negate both values |
General integration pattern
The core loop for any integration is always the same:Node.js / server-side rendering
milsymbol works in Node.js without a browser. Install it withnpm install milsymbol and require it as you would any module. Symbol creation and SVG output work identically — only Canvas output requires a compatible canvas package (such as canvas) since HTMLCanvasElement is not available natively in Node.
asSVG() and asDOM() work in Node.js without any additional dependencies. asCanvas() and toDataURL() require a Canvas implementation such as the canvas npm package.Java and C++ environments
milsymbol can run inside embedded JavaScript engines in non-browser runtimes:- Java — Load milsymbol via the
ScriptEngineAPI (Nashorn or GraalVM). CallasSVG()and capture the returned string for further processing in Java. - C++ / Qt — Load milsymbol into
QJSEngineorQtWebEngine.asSVG()returns a string that can be passed toQSvgRendereror written to an SVG file.
