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
projection
is ad3-geo
GeoProjection
. Defaults to ageoMercator
projection that fits all geometrieswidth
is anumber
. Defaults to1000
height
is anumber
. Defaults to500
backgroundColor
is an HTML color. Defaults toundefined
Attributes
geometry
is a GeoJSON geometry of typePolygon
orMultiPolygon
. REQUIRED- all stroke attributes
- all fill attributes
Attributes
geometry
is a GeoJSON geometry of typeLineString
orMultiLineString
. REQUIRED- all stroke attributes
geometry
is a GeoJSON geometry of typePoint
orMultiPoint
. REQUIRED- all stroke attributes
- all fill attributes
geometry
is a GeoJSON geometry of typePoint
orMultiPoint
. REQUIREDr
is anumber
. It is the radius of the circle. REQUIRED- all stroke attributes
- all fill attributes
geometry
is a GeoJSON geometry of typePoint
orMultiPoint
. REQUIREDtext
is astring
. The content of the label. REQUIREDtranslate
is an array of twonumber
s.- all stroke attributes
- all fill attributes
- all text attributes
url
is astring
, the url to the tile server. REQUIREDattribution
is astring
, the copyright for the tiles. REQUIREDext
is astring
, the file extension if applicablesubdomains
is 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.
fill
is an HTML color. Defaults toblack
fillOpacity
is anumber
between 0 and 1
stroke
is an HTML color. Defaults toundefined
strokeWidth
is anumber
. Defaults to1
strokeLinejoin
is astring
. Options:arcs
|bevel
|miter
|miter-clip
|round
strokeDasharray
is an array ofnumber
sstrokeDashoffset
is anumber
strokeLinecap
is astring
. Options:butt
|round
|square
strokeOpacity
is anumber
between 0 and 1
fontFamily
is astring
fontSize
is anumber
textAnchor
is 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
id
of 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
id
of 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)