Skip to content

Instantly share code, notes, and snippets.

@nedSaf
Last active April 4, 2021 03:29
Show Gist options
  • Save nedSaf/41fb11d4413b2a307266 to your computer and use it in GitHub Desktop.
Save nedSaf/41fb11d4413b2a307266 to your computer and use it in GitHub Desktop.
Adding Leaflet-image to Leaflet-angular-directive
L_PREFER_CANVAS = true;
leafletData.getMap().then(function(map) {
leafletImage(map, function(err, canvas) {
var img = document.createElement('img');
var dimensions = map.getSize();
img.width = dimensions.x;
img.height = dimensions.y;
img.src = canvas.toDataURL();
var data = {
map: img.src,
period: $scope.period.value,
map_width: img.width,
map_height: img.height
// Here you can add this image to any element you want, or send it to the server for saving.
};
});
});
@pedrorocha-net
Copy link

GREEEEEEEEAAAAT! Really thanks man. Helped me a lot.

BTW: need to remove the "period: $scope.period.value," line from the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment