carto/README.md

84 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2012-06-29 02:59:14 +08:00
# CartoCSS
2011-02-01 06:34:10 +08:00
2012-06-19 05:11:47 +08:00
[![Build Status](https://secure.travis-ci.org/mapbox/carto.png)](http://travis-ci.org/mapbox/carto)
2014-06-06 16:04:19 +08:00
Is as stylesheet renderer for javascript, It's an evolution of the Mapnik renderer from Mapbox.
Please, see original [Mapbox repo](http://github.com/mapbox/carto) for more information and credits
## Quick Start
```javascript
// shader is a CartoCSS object
var cartocss = [
'#layer {',
' marker-width: [property]',
' marker-fill: red',
'}'
].join('')
var shader = new carto.RendererJS().render(cartocss);
var layers = shader.getLayers()
for (var i = 0; i < layers.length; ++i) {
var layer = layers[i];
console.log("layer name: ", layer.fullName())
console.log("- frames: ", layer.frames())
console.log("- attachment: ", layer.attachment())
var layerShader = layer.getStyle({ property: 1 }, { zoom: 10 })
2014-06-06 16:04:19 +08:00
console.log(layerShader['marker-width']) // 1
console.log(layerShader['marker-fill']) // #FF0000
}
2011-02-01 06:34:10 +08:00
2014-06-06 16:04:19 +08:00
```
2011-02-03 06:26:38 +08:00
2014-06-06 16:04:19 +08:00
# API
2011-02-03 06:26:38 +08:00
2014-06-06 16:04:19 +08:00
## RendererJS
2012-05-09 03:44:30 +08:00
2014-06-06 16:04:19 +08:00
### render(cartocss)
2012-05-09 03:44:30 +08:00
2014-06-06 16:04:19 +08:00
## CartoCSS
2012-05-09 03:44:30 +08:00
2014-06-06 16:04:19 +08:00
compiled cartocss object
2012-05-09 03:44:30 +08:00
2014-06-06 16:04:19 +08:00
### getLayers
2012-05-09 03:44:30 +08:00
2014-06-06 16:04:19 +08:00
return the layers, an array of ``CartoCSS.Layer`` object
2011-02-01 06:34:10 +08:00
2014-06-06 16:04:19 +08:00
### getDefault
2012-05-22 02:07:14 +08:00
2014-06-06 16:04:19 +08:00
return the default layer (``CartoCSS.Layer``), usually the Map layer
2012-05-22 02:07:14 +08:00
2014-06-06 16:04:19 +08:00
### findLayer(where)
2012-05-22 02:07:14 +08:00
2014-06-06 16:04:19 +08:00
find a layer using where object.
2011-02-01 06:34:10 +08:00
2014-06-06 16:04:19 +08:00
```
shader.findLayer({ name: 'test' })
```
2011-02-01 06:34:10 +08:00
2014-06-06 16:04:19 +08:00
## CartoCSS.Layer
2011-08-03 23:50:08 +08:00
### getStyle(props, context)
2011-02-01 06:34:10 +08:00
return the evaluated style:
2014-06-06 16:04:19 +08:00
- props: object containing properties needed to render the style. If the cartocss style uses
some variables they should be passed in this object
- context: rendering context variables like ``zoom`` or animation ``frame``
2011-02-03 06:08:05 +08:00
2011-02-03 06:29:04 +08:00
2011-02-07 23:07:40 +08:00
2014-06-06 16:04:19 +08:00
## Reference Documentation
2011-02-07 23:07:40 +08:00
2014-06-06 16:04:19 +08:00
* [mapbox.com/carto](http://mapbox.com/carto/)
2011-02-03 06:29:04 +08:00
2011-02-01 06:34:10 +08:00