Put a map on your own website

Export a map as a file, keep the file on your own server, and paste a few lines of code into your page's HTML. The GeoCanvas viewer draws the map from your file.

How it works

You keep the map file on your own website. The embed code puts a frame on your page, and the GeoCanvas viewer in that frame loads your file and draws the map. Your readers' browsers fetch the file, and every service it uses, straight from where they live, not through GeoCanvas.

The free viewer shows what you bring: features you drew or uploaded, which travel inside the file, and your own map services and tiles over https. It does not serve layers from the GeoCanvas catalogue or a library, other GeoCanvas data, or services only reachable through GeoCanvas.

The viewer always draws its own Natural Earth basemap, from GeoCanvas's static data host. A basemap in an OpenFreeMap style is different: your readers' browsers fetch it from that third party.

Register your website

  1. Open Embed sites in your account. You need a confirmed e-mail address to register a website.
  2. Enter the Website address, for example https://www.example.org, without a path. If the map file will be on another server, such as a CDN or GitHub Pages, enter that server as the Data address.
  3. Choose the Projection the key may show, whether to Let readers move and zoom the map, and the Theme, then Add site. The Site key appears; the embed code carries it. You can change the settings later and Save them.

Let readers move and zoom the map switches all reader interaction: dragging, wheel and pinch zoom, rotation, the zoom buttons and the compass. Switched off, the map is a still picture.

The map only shows on pages of the registered website address. Anywhere else, the browser refuses to show the frame.

Export for embedding

  1. Open your map in GeoCanvas and go to the Export tab. Under Save, choose Sources and licences: give each layer of your own a source and a licence, and confirm the rights. The export needs this.
  2. At the top of the Export tab, beside the Designer, choose Embed map, then Export for embedding. Pick your website if you have registered more than one. For a Creator, the button there reads Publish, and the free way is the link Or host the map file on your own website in its dialog.
  3. The dialog lists every layer the embed leaves out, and why. The rest of your map goes into the file.
  4. Download file saves the map as a .json file named after your map, in lowercase letters, digits and hyphens, with a short code at the end that tells maps with the same name apart (for example world-rivers-3fa9c1d2.json). The dialog builds the file's address from your website and that name, so you type nothing. Only if you upload the file into a subfolder, enter its path under Folder. Exporting the same saved map again gives the same file name, so the new file replaces the old one, unless you renamed the map (its name is the readable part of the file name); a map that is not saved gets a new name when it changes.

A layer is left out when the free viewer cannot serve it: catalogue layers, library datasets, GeoCanvas data other than the basemap, services only reachable through GeoCanvas, and sources without a full https address. To keep such a layer, use your own copy of the data. If nothing of your own map would be left, the dialog offers no file.

Why?

With the free way, the map file lives on your website and your server delivers it. GeoCanvas only supplies the viewer that draws it, so your own data travels with the file.

Catalogue layers and Workspace datasets would have to come from GeoCanvas, for every reader of every registered website. That is hosting the map for you: each reader costs us traffic, the loads have to be counted and limited per map, and some catalogue licences must be checked before a map goes public.

That is what publishing with GeoCanvas Creator does: we host the map on maps.geocanvas.app with the catalogue layers and your Workspace data, readers can switch projections, and you see the views.

To keep a layer on the free way, use your own copy of the data, if its licence allows.

If your map uses another projection than the one your key allows, the file shows it in the key's projection, and the dialog says so.

The file also leaves out the Designer's page layout and the globe setting, so the viewer draws the map flat.

Export for embedding is not offered in phone and tablet browsers. Use a computer.

Put the file on your website

Upload the file exactly as it was downloaded, to the website's root (or the folder you entered in the dialog). Do not rename it: the embed code uses that name. Upload the file over https to your website or its data address. The viewer fetches it from https://embed.geocanvas.app without cookies, so the server has to allow that with a CORS header: Access-Control-Allow-Origin: https://embed.geocanvas.app, or *. Without it, the browser blocks the file and the map does not show.

GitHub Pages

  1. Create a public repository on GitHub and upload the downloaded file to it, as it was downloaded.
  2. Under Settings, Pages, publish the branch. The file is then at https://your-name.github.io/your-repository/world-rivers.json (with the name of your downloaded file). In the export dialog, enter your-repository under Folder.
  3. If your website is itself on GitHub Pages, the page and the file can share one address, and you need no data address. Otherwise register https://your-name.github.io as the data address.
  4. Before you paste the embed code, check that the file comes with an Access-Control-Allow-Origin header, as described under Check the header below.

Your own web server

nginx, in the location that serves the file:

add_header Access-Control-Allow-Origin https://embed.geocanvas.app;

Apache, in the site configuration or a .htaccess file (it needs mod_headers):

Header set Access-Control-Allow-Origin "https://embed.geocanvas.app"

On Apache hosting, you can also add this to a .htaccess file in the folder of the map file, so the header goes only to the .json files in that folder. It is not always enough: where the web server serves static files itself, as with the option "Intelligente Bearbeitung statischer Dateien" (intelligent handling of static files) at Netcup, .htaccess headers are not applied to .json files. Turn that option off for the domain.

<FilesMatch "\.json$">
  Header set Access-Control-Allow-Origin "https://embed.geocanvas.app"
</FilesMatch>

Check the header

Ask the server for the file’s headers and look for access-control-allow-origin in the answer:

curl -sI -H "Origin: https://embed.geocanvas.app" https://www.example.org/maps/map.json

Without a terminal: open the file’s address in your browser, open the developer tools (F12), reload on the Network tab, pick the file and read its response headers.

Paste the embed code

Paste the code into your page's HTML, where the map should appear: in a page editor, use its HTML or custom code block. In the dialog, Copy gives you the Embed code, with the file's address already in it. It looks like this:

<iframe src="https://embed.geocanvas.app/?k=YOUR_SITE_KEY&amp;src=https%3A%2F%2Fwww.example.org%2Fmaps%2Fmap.json" title="Map" loading="lazy" style="width:100%;border:0;aspect-ratio:1.5 / 1" data-geocanvas-embed data-aspect-ratio="1.5"></iframe>
<script>
(function () {
  function size() {
    document.querySelectorAll('iframe[data-geocanvas-embed]').forEach(function (frame) {
      var ratio = parseFloat(frame.getAttribute('data-aspect-ratio')) || 16 / 9;
      frame.style.height = frame.offsetWidth / ratio + 'px';
    });
  }
  window.addEventListener('load', size);
  window.addEventListener('resize', size);
  size();
})();
</script>

The address carries two things: k, your site key, and src, the address of your file. The short script that comes with it sets each frame's height from the map's aspect ratio, also when the page changes width. The frame also has a CSS aspect-ratio, so it keeps its shape when your site strips scripts.

Readers zoom with the mouse wheel while holding Ctrl or Cmd, and on a touch screen they move the map with two fingers, so the map does not trap scrolling on your page.

Sizing the frame yourself

To size the frame with your own code, leave the script out and remove aspect-ratio from the style attribute. Once the map has loaded, the viewer sends your page a message with its aspect ratio (width divided by height). Check that it comes from https://embed.geocanvas.app before you use it:

window.addEventListener('message', (event) => {
  const message = event.data;
  if (event.origin === 'https://embed.geocanvas.app' && message?.source === 'geocanvas-embed' && message.type === 'size') {
    const frame = [...document.querySelectorAll('iframe')].find((f) => f.contentWindow === event.source);
    if (frame) frame.style.height = frame.offsetWidth / message.aspectRatio + 'px';
  }
});

The message comes once. If your layout changes width later, keep the ratio and work out the height again.

Test it

A map shows only on pages of the registered https website address. A page on localhost or a file opened from your disk is refused, so put a test page on the registered website itself, open it, and look at the map.

In the export dialog, Check the file asks the viewer to fetch your file from its own address. It tells you whether the file is reachable, allowed for the viewer and importable, and it tests the CORS header from where the viewer really loads it.

Limits, credit and privacy

  • Up to 10,000 map loads a day per website. The limit applies in total to all accounts that register the website address. Another subdomain, www included, counts as another website. Over the limit, the viewer shows a notice instead of the map until the next day (UTC). Embed sites shows today's loads.
  • One website and one projection per account. GeoCanvas Creator keeps this free embed too.
  • The credit stays. The viewer shows the source credits, "Made with GeoCanvas", Imprint and a link to report a map under the map. Keep them visible.
  • Tell your readers. The viewer loads from GeoCanvas, so name the embedded map and GeoCanvas in your own privacy notice. If your map uses services of your own or an OpenFreeMap basemap, name those servers too.

When the map does not show

The viewer says in the frame why it cannot show the map. It speaks English and Tagalog; the messages here are the English ones. What each message means:

  • No project file given. The embed address needs src= with the address of the project file. The embed address has no src=. Copy the embed code from the dialog again.
  • The project file must be on an address registered for this site key. The file’s address is not https, or not on your registered website address or data address. Move the file there, or register its server as the data address.
  • Could not load the project file. Either the address is not the uploaded .json file, or the site does not allow GeoCanvas to read it (CORS). The browser could not get the file. Either the address is not the uploaded .json file (the file was renamed or not uploaded yet, or the server answered with an error page), or the site does not allow GeoCanvas to read it: it does not send the Access-Control-Allow-Origin header (CORS). Open the address in your browser, then check the header as described above.
  • The project file is not valid JSON. The address returns something other than your file, often an error page. Check the address, and upload the file again.
  • The project uses things the free embed does not serve: A file from Export for embedding passes this check, so this file was saved some other way or edited, or the key’s projection has changed since. Exporting the map again with Export for embedding fixes it. Most lines name a layer; two may concern the whole map: the projection does not match the key, or the rights are not confirmed. What to do about each:
    • Its projection is not the one granted to this site key.: Export again, which switches the map to the key’s projection, or change the key’s projection in Embed sites.
    • a layer from the GeoCanvas catalogue: Leave the layer out, or use your own copy of the data.
    • a dataset from a GeoCanvas library: Leave the layer out, or use your own copy of the data.
    • GeoCanvas data other than the basemap: Leave the layer out, or use your own copy of the data.
    • a service only reachable through GeoCanvas: Point the layer at the service’s own https address.
    • a source that is not https: Give the source an https address.
    • a source without a full https address: Give the source a full address starting with https://.
    • a kind of layer the embed cannot show: Leave the layer out.
    • no source and licence given (Export tab, Save group, Sources and licences): Open the Export tab, and under Save choose Sources and licences. Give each of your own layers a source and a licence, then save the map and export again.
    • The rights for this map are not confirmed (Export tab, Save group, Sources and licences): Open the Export tab, and under Save choose Sources and licences. Confirm the rights, then save the map and export again.
    • The map is saved on the 3D globe, which the embed does not show: Choose Back to the flat map, then save the map and export again. The embed shows flat maps only.
    • a kind of layer the embed viewer does not show yet: The embed viewer does not show this kind of layer yet: a WMS, WMTS, TMS or WFS service, a vector basemap, a raster styled by its values or one in a projected coordinate system. Leave the layer out, or for a raster use a plain image or a GeoTIFF in WGS 84 (EPSG:4326).
  • This map is not available right now. The site key is unknown, revoked or blocked, the site has used up its map loads for the day, or GeoCanvas cannot check the key at the moment. Check the key in Embed sites.
  • This map is shown on the website that embeds it. You opened the viewer’s address on its own. It only draws maps inside a frame on your website.
  • The frame stays empty, or the browser says it refused to connect: the page is not on the registered website address. Compare the address in Embed sites with your page’s, including www.
  • "This map cannot be shown" with any other message about the project file means the file did not import: it is damaged or from an older version. Export the map again.