Define your maps once and render to:
npm install karto
import karto from 'karto'
import polygonGeometry from './polygon.json'
import lineGeometry from './line.json'
const map = karto`
<map>
<polygon geometry=${polygonGeometry} fill="blue" stroke="lightblue" />
<line geometry=${lineGeometry} stroke="red" strokeWidth=${3} strokeDasharray=${[10, 2]} />
</map>
`karto is a tagged template. Use an xml-like syntax to describe your map.
<map> must be the parent element.
Attributes
projectionis ad3-geoGeoProjection. Defaults to ageoMercatorprojection that fits all geometrieswidthis anumber. Defaults to1000heightis anumber. Defaults to500backgroundColoris an HTML color. Defaults toundefined
Attributes
geometryis a GeoJSON geometry of typePolygonorMultiPolygon. REQUIRED- all stroke attributes
- all fill attributes
Attributes
geometryis a GeoJSON geometry of typeLineStringorMultiLineString. REQUIRED- all stroke attributes
geometryis a GeoJSON geometry of typePointorMultiPoint. REQUIRED- all stroke attributes
- all fill attributes
geometryis a GeoJSON geometry of typePointorMultiPoint. REQUIREDris anumber. It is the radius of the circle. REQUIRED- all stroke attributes
- all fill attributes
geometryis a GeoJSON geometry of typePointorMultiPoint. REQUIREDtextis astring. The content of the label. REQUIREDtranslateis an array of twonumbers.- all stroke attributes
- all fill attributes
- all text attributes
urlis astring, the url to the tile server. REQUIREDattributionis astring, the copyright for the tiles. REQUIREDextis astring, the file extension if applicablesubdomainsis astring, the server subdomains if applicable
Look at Leaflet providers for an idea of how this works.
All elements have an opacity attribute. It is a number between 0 and 1.
fillis an HTML color. Defaults toblackfillOpacityis anumberbetween 0 and 1
strokeis an HTML color. Defaults toundefinedstrokeWidthis anumber. Defaults to1strokeLinejoinis astring. Options:arcs|bevel|miter|miter-clip|roundstrokeDasharrayis an array ofnumbersstrokeDashoffsetis anumberstrokeLinecapis astring. Options:butt|round|squarestrokeOpacityis anumberbetween 0 and 1
fontFamilyis astringfontSizeis anumbertextAnchoris astring. Options:start|middle|end
Takes one argument, the map definition.
import karto, { renderSvgString } from 'karto'
const map = karto`
// your map definition
`
renderSvgString(map)
.then(console.log)Takes two arguments:
- The
idof an existing<div>to which the canvas will be added - The map definition
import karto from 'karto'
import renderToCanvas from 'karto/dist/renderers/canvas'
const map = karto`
// your map definition
`
renderToCanvas('divId', map)Takes two arguments:
- The
idof an existing<div>to which the map will be added - The map definition
import karto from 'karto'
import renderToLeaflet from 'karto/dist/renderers/leaflet'
const map = karto`
// your map definition
`
renderToLeaflet('divId', map)