Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumbera authored Jul 14, 2016
1 parent 32060c9 commit 7ff7fd3
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,46 @@ generic map layers for leaflet 0.7 and 1.0-rc, moving from original GIST here h

L.CanvasLayer API:

##API:
##API

|methods | description |
| ------------- |:-------------|
|needRedraw | will schedule next frame call for drawLayer|
|delegate(object) | optionaly set receiver of the events if not 'inheriting' from L.CanvasLayer |


events | description |
| ------------- |:-------------|
|onLayerDidMount | after layer is attached/added to the map|
|onLayerWillUnmount | before layer is removed from the map|
|onDrawLayer(info) | when layer is drawn , info contains view parameters like bounds, size, canvas etc.
note : events will be called only if presented on the 'subclass'
note : events will be called only if presented on the 'subclass' or if delegate(receiver) is set

## example
## Examples
### Basic usage
```javascript
L.canvasLayer()
.delegate(this) // -- if we do not inherit from L.CanvasLayer we can setup a delegate to receive events from L.CanvasLayer
.addTo(leafletMap);

function onDrawLayer(info) {
var ctx = info.canvas.getContext('2d');
ctx.clearRect(0, 0, info.canvas.width, info.canvas.height);
ctx.fillStyle = "rgba(255,116,0, 0.2)";
for (var i = 0; i < data.length; i++) {
var d = data[i];
if (info.bounds.contains([d[0], d[1]])) {
dot = info.layer._map.latLngToContainerPoint([d[0], d[1]]);
ctx.beginPath();
ctx.arc(dot.x, dot.y, 3, 0, Math.PI * 2);
ctx.fill();
ctx.closePath();
}
}
};
```

### Custom layer
```javascript

myCustomCanvasDraw= function(){
Expand All @@ -44,7 +68,8 @@ note : events will be called only if presented on the 'subclass'
myLayer.addTo(leafletMap);
```


Other useful full view Leaflet Canvas sources here:
- [leaflet.heat](https://github.com/Leaflet/Leaflet.heat)
- [Full Canvas] (https://github.com/cyrilcherian/Leaflet-Fullcanvas)
- [CartoDb Leaflet.Canvas] (https://github.com/CartoDB/Leaflet.CanvasLayer)

0 comments on commit 7ff7fd3

Please sign in to comment.