Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Fix thumbnail generation and update images #395

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ In content area of the markdown page include an extended description of the exam

In the `.html` file, write the HTML and JavaScript constituting the example.

* Do **not** include an access token in the example code. The access token will be inserted automatically by the template, using the current logged in user's default public token, or a placeholder `<insert token here>` string if the user is not logged in.
* Do **not** include a MapTiler access token in the example code. The access token will be inserted automatically by the template, using the current logged in user's default public token, or a placeholder `<insert token here>` string if the user is not logged in.
* On commit, Prettier will format the code for all files, including HTML.

Every example **must** have an accompanying image. To get an image, run the site locally and take a screenshot of the rendered map in the example:
Every example **must** have an accompanying image.

1. Run `npm run create-image <example-file-name> <mapbox-access-token>`. The script will take a screenshot of the map in the example and save it to `docs/img/src/`. Commit the image.
2. Run `npm start` to verify that your example image is loading as expected.
1. Ensure that you have a build of the latest `maplibre-gl-js` in the neighboring directory (see below).
2. Run `npm run create-image <example-file-name>`. The script will take a screenshot of the map in the example and save it to `docs/img/src/`. Commit the image.
3. Run `npm start` to verify that your example image is loading as expected.

💡 If `npm run create-image` does not generate an ideal image. You can also take a screenshot of it yourself by running the site locally with `npm start` and taking a screenshot of the example map in PNG format. Resize it to 1200 x 500 pixels and save it in the `docs/img/src` folder.
For some examples, `npm run create-image` does not generate an ideal image. In these cases, you can interact with the map after running `ncreate-image`, or take a screenshot yourself by running the site locally with `npm start`, take a screenshot and save it in the `docs/img/src` folder.

To regenerate all images, run `npm run create-image all`. Note that this doesn't support interaction and examples that require manual interaction (e.g. popups). will need to be manually redone afterward. This feature is experimental and may crash before sucessfully generating all examples.

## Running the Documentation Server Locally

Expand All @@ -77,7 +80,7 @@ The command will print the URL you can use to view the documentation.
💡 If you receive an error related to `@mapbox/appropriate-images`, try `nvm use && npm start`.

The examples section of the locally run documentation will use the GL JS version located in `../maplibre-gl-js/dist`,
so make sure to have a working minified build in your local copy of the `maplibre-gl-js` repo (not the submodule; clone `maplibre-gl-js` into the same directory as `maplibre-gl-js-docs` and run `npm build-dist` there).
so make sure to have a working minified build in your local copy of the `maplibre-gl-js` repo (not the submodule; clone `maplibre-gl-js` into the same directory as `maplibre-gl-js-docs` and run `npm run build-dist` there).


## Committing and Publishing Documentation
Expand Down
101 changes: 101 additions & 0 deletions docs/bin/create-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// eslint-disable-line
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
import pack from 'maplibre-gl/package.json' assert { type: 'json' };
import puppeteer from 'puppeteer';

const exampleName = process.argv[2];
const binPath = path.dirname(fileURLToPath(import.meta.url));
const examplePath = path.resolve(binPath, '..', 'pages', 'example');

const browser = await puppeteer.launch({ headless: exampleName === 'all' });

let page = await browser.newPage();
// set viewport and double deviceScaleFactor to get a closer shot of the map
await page.setViewport({
width: 600,
height: 600,
deviceScaleFactor: 2
});

async function createImage(nameWithExtension) {
const exampleName = nameWithExtension
.replace('.html', '')
.replace('.js', '');
// get the example contents/snippet
const snippet = fs.readFileSync(
path.resolve(examplePath, `${exampleName}.html`),
'utf-8'
);
// create an HTML page to display the example snippet
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<script src='https://unpkg.com/maplibre-gl@${pack.version}/dist/maplibre-gl.js'></script>
<link href='https://unpkg.com/maplibre-gl@${pack.version}/dist/maplibre-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position: absolute; top:0; bottom:0; width: 600px; max-height: 300px; }
</style>
</head>
<body>
${snippet}
</body>
</html>`;

// eslint-disable-next-line xss/no-mixed-html
await page.setContent(html);

// Wait for map to load, then wait two more seconds for images, etc. to load.
await page
.waitForFunction('map.loaded()')
.then(async () => {
// Wait for 5 seconds on 3d model examples, since this takes longer to load.
const waitTime = exampleName.includes('3d-model') ? 5000 : 1500;
// eslint-disable-next-line es/no-promise
await new Promise(function (resolve) {
console.log(`waiting for ${waitTime} ms`);
setTimeout(resolve, waitTime);
});
})
// map.loaded() does not evaluate to true within 3 seconds, it's probably an animated example.
// In this case we take the screenshot immediately.
.catch(() => {
console.log(`Timed out waiting for map load on ${exampleName}.`);
});

await page
.screenshot({
path: `./docs/img/src/${exampleName}.png`,
type: 'png',
clip: {
x: 0,
y: 0,
width: 600,
height: 250
}
})
.then(() => console.log(`Created ./docs/img/src/${exampleName}.png`))
.catch((err) => {
console.log(err);
});
}

if (exampleName === 'all') {
const allFiles = fs.readdirSync(examplePath);
const files = allFiles.filter((file) => /\.html$/.test(file));
console.log(`Generating ${files.length} images.`);
for (const file of files) {
await createImage(file);
}
} else if (exampleName) {
await createImage(exampleName);
} else {
throw new Error(
'\n Usage: npm run create-image <file-name>\nExample: npm run create-image 3d-buildings'
);
}

await browser.close();
80 changes: 0 additions & 80 deletions docs/bin/create-image.ts

This file was deleted.

Binary file modified docs/img/src/3d-buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/3d-extrusion-floorplan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/3d-terrain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-3d-model-babylon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-3d-model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-a-marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-image-animated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-image-generated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-image-missing-generated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-image-stretchable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/add-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/src/adjust-layer-opacity.png
Binary file not shown.
Binary file modified docs/img/src/animate-a-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/animate-camera-around-point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/animate-images.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/animate-marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/animate-point-along-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/animate-point-along-route.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/attribution-position.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/camera-animation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/canvas-source.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/center-on-symbol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/change-building-color-based-on-zoom-level.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/change-case-of-labels.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/check-for-support.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/src/cluster-html.png
Binary file modified docs/img/src/cluster.png
Binary file modified docs/img/src/color-switcher.png
Binary file modified docs/img/src/custom-marker-icons.png
Binary file removed docs/img/src/custom-style-id.png
Diff not rendered.
Binary file modified docs/img/src/custom-style-layer.png
Binary file removed docs/img/src/dancing-buildings.png
Diff not rendered.
Binary file removed docs/img/src/data-driven-circle-colors.png
Diff not rendered.
Binary file modified docs/img/src/data-driven-lines.png
Binary file removed docs/img/src/data-join.png
Diff not rendered.
Binary file modified docs/img/src/disable-rotation.png
Binary file modified docs/img/src/disable-scroll-zoom.png
Binary file modified docs/img/src/display-and-style-rich-text-labels.png
Binary file modified docs/img/src/drag-a-marker.png
Binary file modified docs/img/src/drag-a-point.png
Binary file modified docs/img/src/fallback-image.png
Binary file modified docs/img/src/fill-pattern.png
Binary file removed docs/img/src/filter-features-within-map-view.png
Diff not rendered.
Binary file modified docs/img/src/filter-markers-by-input.png
Binary file modified docs/img/src/filter-markers.png
Binary file modified docs/img/src/fitbounds.png
Binary file modified docs/img/src/flyto-options.png
Binary file modified docs/img/src/flyto.png
Binary file removed docs/img/src/forward-geocode-custom-data.png
Diff not rendered.
Binary file modified docs/img/src/fullscreen.png
Binary file modified docs/img/src/game-controls.png
Binary file modified docs/img/src/geocoder.png
Binary file modified docs/img/src/geojson-layer-in-stack.png
Binary file modified docs/img/src/geojson-line.png
Binary file modified docs/img/src/geojson-markers.png
Binary file modified docs/img/src/geojson-polygon.png
Binary file modified docs/img/src/heatmap-layer.png
Binary file removed docs/img/src/hillshade.png
Diff not rendered.
Binary file modified docs/img/src/hover-styles.png
Binary file removed docs/img/src/image-on-a-map.png
Diff not rendered.
Binary file modified docs/img/src/interactive-false.png
Binary file modified docs/img/src/jump-to.png
Binary file modified docs/img/src/language-switch.png
Binary file removed docs/img/src/layer-background.png
Diff not rendered.
Binary file removed docs/img/src/layer-circle.png
Diff not rendered.
Binary file removed docs/img/src/layer-fill-extrusion.png
Diff not rendered.
Binary file removed docs/img/src/layer-fill.png
Diff not rendered.
Binary file removed docs/img/src/layer-heatmap.png
Diff not rendered.
Binary file removed docs/img/src/layer-hillshade.png
Diff not rendered.
Binary file removed docs/img/src/layer-line.png
Diff not rendered.
Binary file removed docs/img/src/layer-raster.png
Diff not rendered.
Binary file removed docs/img/src/layer-symbol.png
Diff not rendered.
Binary file modified docs/img/src/line-across-180th-meridian.png
Binary file modified docs/img/src/line-gradient.png
Binary file modified docs/img/src/live-geojson.png
Binary file modified docs/img/src/live-update-feature.png
Binary file added docs/img/src/local-geojson-experimental.png
Binary file modified docs/img/src/local-geojson.png
Binary file modified docs/img/src/local-ideographs.png
Binary file modified docs/img/src/locate-user.png
Binary file modified docs/img/src/map-tiles.png
Binary file removed docs/img/src/mapbox-gl-compare.png
Diff not rendered.
Binary file modified docs/img/src/mapbox-gl-draw.png
Binary file modified docs/img/src/mapbox-gl-rtl-text.png
Binary file removed docs/img/src/marker-from-geocode.png
Diff not rendered.
Binary file modified docs/img/src/measure.png
Binary file modified docs/img/src/mouse-position.png
Binary file modified docs/img/src/multiple-geometries.png
Binary file modified docs/img/src/navigation.png
Binary file modified docs/img/src/offset-vanishing-point-with-padding.png
Binary file removed docs/img/src/placeholder.png
Diff not rendered.
Binary file removed docs/img/src/playback-locations.png
Diff not rendered.
Binary file removed docs/img/src/point-from-geocoder-result.png
Diff not rendered.
Binary file modified docs/img/src/polygon-popup-on-click.png
Binary file modified docs/img/src/popup-on-click.png
Binary file modified docs/img/src/popup-on-hover.png
Binary file modified docs/img/src/popup.png
Binary file removed docs/img/src/query-similar-features.png
Diff not rendered.
Binary file removed docs/img/src/queryrenderedfeatures-around-point.png
Diff not rendered.
Binary file modified docs/img/src/queryrenderedfeatures.png
Binary file modified docs/img/src/render-world-copies.png
Binary file modified docs/img/src/restrict-bounds.png
Binary file modified docs/img/src/satellite-map.png
Binary file modified docs/img/src/scroll-fly-to.png
Binary file modified docs/img/src/set-perspective.png
Binary file modified docs/img/src/set-popup.png
Binary file removed docs/img/src/setstyle.png
Diff not rendered.
Binary file modified docs/img/src/simple-map.png
Binary file removed docs/img/src/style-ocean-depth-data.png
Diff not rendered.
Binary file modified docs/img/src/third-party.png
Binary file modified docs/img/src/timeline-animation.png
Binary file modified docs/img/src/toggle-interaction-handlers.png
Binary file removed docs/img/src/toggle-layers.png
Diff not rendered.
Binary file removed docs/img/src/toggle-worldviews.png
Diff not rendered.
Binary file removed docs/img/src/updating-choropleth.png
Diff not rendered.
Binary file removed docs/img/src/using-box-queryrenderedfeatures.png
Diff not rendered.
Binary file modified docs/img/src/variable-label-placement.png
Binary file modified docs/img/src/vector-source.png
Binary file modified docs/img/src/video-on-a-map.png
Binary file modified docs/img/src/visualize-population-density.png
Binary file modified docs/img/src/wms.png
Binary file modified docs/img/src/zoomto-linestring.png