Skip to content

Commit

Permalink
Introduced Support for marker snapshot in leaflet
Browse files Browse the repository at this point in the history
There is still a problem when the map is panned.
When possible, you have to parse the transform inline style of the mapdiv to properly shift the clonded marker div to snap (or properly set the canvas).
  • Loading branch information
offtherailz committed Dec 6, 2016
1 parent 47d1a7c commit a5a34bb
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions web/client/components/map/leaflet/snapshot/GrabMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,30 @@ let GrabLMap = React.createClass({

});
let finialize = () => {
this.props.onStatusChange("READY", this.isTainted(finalCanvas));
this.props.onSnapshotReady(canvas, null, null, null, this.isTainted(finalCanvas));
// TODO parse map-div transform to shift all markers toghether properly
let markers = this.mapDiv.getElementsByClassName("leaflet-marker-pane");
if ( markers && markers.length > 0) {
let newCanvas = this.refs.canvas.cloneNode();
newCanvas.width = newCanvas.width + left;
html2canvas(markers, {
// you have to provide a canvas to avoid html2canvas to crop the image
canvas: newCanvas,
logging: false,
proxy: this.proxy,
allowTaint: props && props.allowTaint,
// TODO: improve to useCORS if every source has CORS enabled
useCORS: props && props.allowTaint
}).then( (c) => {
let cx = finalCanvas.getContext("2d");
cx.globalAlpha = 1;
cx.drawImage(c, -1 * left, 0);
this.props.onStatusChange("READY", this.isTainted(finalCanvas));
this.props.onSnapshotReady(canvas, null, null, null, this.isTainted(finalCanvas));
});
} else {
this.props.onStatusChange("READY", this.isTainted(finalCanvas));
this.props.onSnapshotReady(canvas, null, null, null, this.isTainted(finalCanvas));
}
};

if (svg) {
Expand Down

0 comments on commit a5a34bb

Please sign in to comment.