Comments (6)
We can do this using html2canvas. It would be nice to see a community owned project provide this functionality.
from maplibre-gl-export.
@whittaker007 I was trying to add attribution from style.json before, but at that time, I could not manage to add it. However, any PR to this repository is most welcome, feel free to fork it and pull request, please.
from maplibre-gl-export.
Also interested in this enhancement - particularly a 'legend' element. Any update on this?
from maplibre-gl-export.
@zbyte64 Thank you for the comment. Please feel free to create a PR to this repo. I am happy to merge it.
from maplibre-gl-export.
I'm a bit hesitant to make a PR, mainly concerned over how it changes the API interface being offered. Here are some broad strokes though so we can get a concrete discussion going (and to help others):
We have an async function that calls html2canvas to copy everything from the "map container" (this includes the Canvas as well as the mapbox controls) into a new canvas element:
async function draw(): Promise<HTMLCanvasElement> {
return html2canvas(map.getContainer(), {
ignoreElements,
});
}
html2canvas
takes a function that lets us filter out elements we don't want (ie interactive elements). We could let the user pass in a function or make some convenience factory that filters by classnames:
export function ignoreElementsFactory(hiddenClassNames: string[]) {
const hiddenClassNamesSet = new Set(hiddenClassNames);
return (element: Element) => {
// Remove all elements with class in hiddenClassNames
// eslint-disable-next-line no-restricted-syntax
for (const hiddenClassName of element.classList) {
if (hiddenClassNamesSet.has(hiddenClassName)) {
return true;
}
}
return false;
}
}
Also, most of the time the attribution isn't optimized for print (ie might be underlined to indicate it's a link), so we may want to also allow the user to easily provide additional HTML elements.
To recap, my questions are:
- how should the user specify which elements to ignore? is there any affordances we want to add (eg filter by class names)?
- how should the user specify elements to inject? maybe a callback to generate html elements, which then get called to html2canvas and blitted over the map result?
from maplibre-gl-export.
Related Issues (13)
- Non metric (US) Paper size support HOT 1
- No icons or images are output HOT 3
- The markers should be included in the exported files HOT 8
- Spanish translation HOT 3
- 3D Terrain with MapLibre v.2.2.0-pre.3 HOT 6
- maplibre-gl-export and maplibre-gl-legend HOT 6
- ESLint didn't fix all typescript files in lib directory
- Lib / dist file error HOT 3
- ReferenceError: Size is not defined HOT 2
- Uncaught TypeError: MaplibreExportControl is not a constructor HOT 2
- PDF export for A3 size produces incorrect crop HOT 3
- Export is not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maplibre-gl-export.