Universal Map2web

Universal Map2web

A QGIS plugin that exports your project as an interactive Leaflet web map

v1.4.0

Live example

See what an export looks like before installing anything. This map was produced with Universal Map2web from a QGIS project: legend built from the QGIS symbology, popups, attribute table, filter panel and map tools are all part of the exported page.

Open the exported example map →

Try the table icon in front of a layer in the legend to open its attribute table, and the filter panel to query the data.

Installation

From the QGIS plugin repository

In QGIS, go to Plugins → Manage and Install Plugins, search for "Universal Map2web" and click Install. The plugin page is also available at plugins.qgis.org/plugins/universal_map2web.

From GitHub

Download the ZIP from the GitHub repository, then use Plugins → Install from ZIP in QGIS and pick the file. Restart QGIS if it asks you to.

QGIS 3.0 or higher is required (it also runs on QGIS 4.x). The plugin follows the language of your QGIS installation, French or English.

Usage

Start the plugin from its toolbar icon or from the Web menu. The dialog is split into tabs.

General

  • Choose the web library used to render the map (Leaflet).
  • Choose a basemap: OpenStreetMap, Google Satellite, or your own tile URL, for example https://{s}.tile.example.com/{z}/{x}/{y}.png.
  • Tick the tools you want in the exported map (see Tools & options).

Customization

  • The map title, shown in the browser tab and in the header.
  • An optional logo for the header.
  • The header color.
  • One of the four UI themes (see Themes).

Layers

  1. Tick the layers to export. "Select all", "Deselect all" and "Invert" save some clicks.
  2. For each layer, pick the attribute fields that should appear in the popup.
  3. Layers connected to a WFS service are detected and loaded live. WMS layers are listed separately (see Live WFS / WMS).

Advanced

  • Simplify geometries: fewer vertices, faster loading.
  • Compress JSON data: smaller GeoJSON files.
  • Round coordinates: fewer decimals.
  • Load PostGIS layers dynamically from PostgreSQL: layers already connected to PostgreSQL/PostGIS in QGIS stay live instead of being frozen into static GeoJSON (see PostGIS dynamic mode).
  • Export as ZIP: puts the whole export in one archive.
  • Open automatically in browser: starts a local server and opens the map when the export is done.

Wiki

A short built-in reference, in French or English depending on your QGIS language.

Exporting

When everything is set, click OK and choose the destination folder. If the option is enabled, the map then opens in your default browser.

Tools & options

Each tool can be switched on or off in the General tab before exporting.

OptionWhat it adds to the exported map
Address searchA search bar to find an address
GPS geolocationA button that centers the map on the visitor's position
MeasureDistance and area measurement
Print buttonOpens the browser's print dialog
Fullscreen modeA control to expand the map to fullscreen
Overview (MiniMap)A small overview map in a corner
Scale barA graphic scale (on by default)
Cursor positionLatitude and longitude under the mouse pointer
AttributionMap and library credits (on by default)
Advanced filterThe attribute filter panel, see Filtering

Managing layers on the exported map

  • Show or hide a layer with its checkbox in the legend.
  • Point layers can be clustered; enable "Cluster points" for the layer.
  • The legend is built from your QGIS symbology. Simple, Categorized, Graduated and Rule-based renderers are supported.
  • "Expand / Collapse all" folds or unfolds every group in the legend.
  • The table icon in front of a vector layer opens its attribute table (see Attribute table).
  • The magnifier icon next to it zooms to the layer's extent.

Themes

Four themes are available: Light, Dark (easier on the eyes with satellite basemaps), Professional (neutral, for institutional maps) and Colorful (stronger accent colors, for public-facing maps).

The header color, title and logo are set separately from the theme, so you can put your organization's branding on any of them.

Filtering

With the advanced filter enabled, the exported map gets a filter panel in its sidebar. Visitors can query the data without QGIS.

  1. Pick a layer.
  2. Pick a field.
  3. Pick an operator.
  4. Type or select a value.
  5. Click Apply. Matching features are highlighted on the map.

Click Reset to clear the filter and show everything again.

OperatorMeaning
=equal to
≠different from
⊃contains
starts withtext starts with the value
>greater than
<less than
≥greater than or equal to
≤less than or equal to

Attribute table since 1.4.0

Every vector layer in the exported map (static shapefile/GeoJSON, WFS or PostgreSQL/PostGIS) has a small table icon before its name in the legend. Clicking it opens the attribute table in a floating window.

  • The window can be moved (drag the title bar) and resized (bottom-right corner). You can have several tables open at once.
  • Click a column header to sort.
  • Filter a column by typing in the field under its header, or search all columns with the global search box.
  • Hovering a row highlights the feature on the map. Hold Ctrl while hovering, or click the row, to zoom to it.
  • Export to CSV gives you the rows currently displayed, after filtering and sorting. The file uses ; as separator and UTF-8 with BOM, so Excel shows accents correctly.
  • Large layers are paged, 100 rows per page.

The table only lists features that are loaded in the page. In PostGIS dynamic mode with bounding-box filtering, that means the features of the area currently loaded. Internal styling fields are hidden automatically. WMS layers are rasters, so they have no attribute table.

PostGIS dynamic mode since 1.2.1

By default, a layer is exported as a GeoJSON snapshot taken at export time. For layers connected to PostgreSQL/PostGIS in QGIS, you can instead keep them live: the web map queries the database every time it needs data.

Enabling it

  1. In the export dialog, check "Load PostGIS layers dynamically from PostgreSQL (instead of a static export)".
  2. The plugin reuses the connection already set up in QGIS. You don't enter any credentials again.
  3. Export as usual. Layers that are not from PostgreSQL, or that you leave unchecked, are still exported as static GeoJSON.

What is generated

  • get_data.php, the endpoint that serves feature data to the map.
  • db_config.php, which holds the database connection details.
  • A random API key, new for each export, that restricts access to get_data.php.
  • An .htaccess file that blocks direct access to db_config.php.

The map can filter by bounding box, so only the visible area is requested. Layers left in static mode behave exactly as before.

This mode needs a PHP web server with the pdo_pgsql extension enabled. A plain static host (GitHub Pages, a simple file share) won't work for dynamic layers. In that case, use the static GeoJSON export.

Leave db_config.php and .htaccess as generated. They are what keeps your database credentials from being read directly.

Live WFS / WMS since 1.4.0

A layer connected to an OGC service in QGIS (a GeoServer, for example) can stay live on the exported map. The browser asks the server for the data instead of reading a file produced at export time.

ServiceTypeBehavior on the exported map
WFS Vector Detected automatically from the QGIS layer. The map sends a GetFeature request (application/json) to the WFS server at each load. No PHP backend and no GeoJSON file. Symbology, popups, the advanced filter and the attribute table work as for any other vector layer.
WMS Raster Listed separately in the export dialog and displayed as tiles requested from the server. Clicking the map sends a GetFeatureInfo request and shows the answer in a popup.

Setting it up

  1. Add the WFS or WMS layer to QGIS as usual (Layer > Add Layer).
  2. Open Universal Map2web and select the layer in the Layers tab. The connection settings are read from the layer.
  3. Export.
  4. Check that CORS is enabled on the server (see CORS on GeoServer).

Things the server must satisfy:

  • It has to be reachable from the visitor's browser, not just from your computer. A server on localhost or on a private network won't work for people online.
  • If the map is served over https://, the OGC server must use https:// too, otherwise the browser blocks the requests (mixed content).
  • CORS must be enabled.
  • For WFS, the application/json output format must be available. GeoServer enables it by default.

CORS on GeoServer

The exported map is opened from a different origin than your GeoServer: your own website, or http://localhost:PORT when you use the built-in local server. The browser only lets the page read GeoServer's answers if GeoServer sends the Access-Control-Allow-Origin header. The built-in local server doesn't change that for remote WFS/WMS services.

ServiceWithout CORS
WFSThe layer can't be loaded and the legend shows a "blocked by CORS" message.
WMSTiles still display, since they are loaded as images. Click-to-query (GetFeatureInfo as JSON) is blocked and falls back to an HTML frame.

Option A: GeoServer web administration

Recent GeoServer versions have a CORS setting in the web administration interface (look for "Enable CORS" in the GeoServer documentation, under Container Considerations). Turn it on and restart GeoServer.

Option B: web.xml

This works on all versions. Edit webapps/geoserver/WEB-INF/web.xml, uncomment or add the CORS <filter> and its <filter-mapping>, then restart.

Standalone or binary installer (Jetty):

<filter>
  <filter-name>cross-origin</filter-name>
  <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>cross-origin</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

WAR deployed in Tomcat:

<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.methods</param-name>
    <param-value>GET,POST,HEAD,OPTIONS</param-value>
  </init-param>
  <init-param>
    <param-name>cors.allowed.headers</param-name>
    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

Use one method only. If CORS is enabled in the interface, in web.xml and/or in a reverse proxy (Apache, Nginx) at the same time, the server sends duplicate Access-Control-Allow-Origin values and browsers reject the response.

* allows any website. In production, replace it with your own site, for example https://maps.example.org.

Checking that it works

curl -I -H "Origin: https://maps.example.org" "https://your-geoserver/geoserver/ows?service=WFS&request=GetCapabilities"

The response headers must contain Access-Control-Allow-Origin.

Tips

  • Number of layers. Around 15 active layers is a good ceiling for the browser.
  • File size. Try to keep each layer under about 50 MB. For big datasets, turn on "Simplify geometries" and "Compress JSON data".
  • Coordinate system. Work in WGS84 (EPSG:4326). Leaflet basemaps expect geographic coordinates.
  • Check in QGIS first. The web map mirrors your current project styling, so fix symbology and labels before exporting.
  • Popups. Select only the fields visitors need. The popup stays shorter and easier to read.
  • Sharing. "Export as ZIP" gives you one archive to upload to a server or send to a colleague.

Troubleshooting

The map doesn't open after export

Check that "Open automatically in browser" is ticked in the Advanced tab, and that a firewall or antivirus isn't blocking the local port used for the preview. You can always open index.html from the export folder yourself.

The legend or some labels are in the wrong language

The language comes from QGIS, under Settings → Options → General. Restart QGIS after changing it so the plugin reloads its translations.

A layer is missing from the exported map

  • Make sure it is ticked in the Layers tab of the export dialog.
  • Make sure it is visible in the QGIS Layers panel.
  • Local raster files are not exported to Leaflet. Vector layers are, and WMS services are loaded live (see Live WFS / WMS).

Colors or categories don't match QGIS

Check that the renderer (Simple, Categorized, Graduated, Rule-based) is fully applied in QGIS, refresh the layer's symbology panel, and export again.

PostGIS layers are empty once online

It works locally but the dynamic layers stay empty on the server. Check the following:

  • The host must be a PHP server with the pdo_pgsql extension. A static-only host can't run get_data.php.
  • db_config.php and .htaccess must be uploaded with the rest of the export, unmodified.
  • The PostgreSQL server must accept remote connections from your web host, and its firewall must allow them.

A WFS layer won't load ("blocked by CORS" or "server unreachable")

The layer works in QGIS but stays empty on the exported map and the legend shows an error.

  • Enable CORS on the server (see CORS on GeoServer).
  • Open the WFS URL from a computer outside your network to confirm visitors can reach it.
  • If the map is served over https://, the WFS URL must be https:// too.
  • Check that the application/json output format is enabled.
  • If CORS is already on, make sure it isn't configured twice (interface plus web.xml or reverse proxy), which duplicates the header.

A WMS layer displays but clicking gives no popup

  • Tiles are images and don't need CORS, but click-to-query does. Enable it as described in CORS on GeoServer.
  • The layer must be queryable on the server (GetFeatureInfo enabled).
  • Without CORS the plugin falls back to an HTML frame, which looks different from the normal popup.

The attribute table has fewer rows than the layer

The table lists the features loaded in the page. In PostGIS dynamic mode with bounding-box filtering, only the features of the loaded area are there.

In most other cases, the cause is a permission issue with the local preview server, or a layer that was hidden or unselected in QGIS at export time.

Requirements

ComponentRequirement
QGIS3.0 or higher (up to 4.x)
BrowserChrome 90+, Firefox 88+, Edge 90+
Memory4 GB RAM minimum
InternetNeeded for basemaps and web libraries (Leaflet, plugins)
Hosting (PostGIS dynamic mode only)PHP web server with the pdo_pgsql extension enabled
OGC server (live WFS/WMS only)GeoServer or any WFS/WMS server reachable from visitors' browsers, with CORS enabled (and https if the map is served over https)

Contact

Questions, bug reports and suggestions are welcome.