Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot marker support #1328

Merged
merged 4 commits into from
Dec 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions web/client/components/map/leaflet/snapshot/GrabMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ let GrabLMap = React.createClass({
var leftString = window.getComputedStyle(this.mapDiv).getPropertyValue("left");

// get all the informations needed to snap svg before
let svgs = this.mapDiv.getElementsByTagName("svg");
let mapPanes = this.mapDiv.getElementsByClassName("leaflet-map-pane");
let mapPane = mapPanes && mapPanes[0];
let objectPanes = mapPane && mapPane.getElementsByClassName("leaflet-objects-pane");
let objectDiv = objectPanes && objectPanes[0];
let svgs = objectDiv && objectDiv.getElementsByTagName("svg");
let svg = svgs && svgs[0];
let svgH;
let svgW;
Expand Down Expand Up @@ -196,8 +200,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