Map Macro

Last modified by Thomas Mortagne on 2024/07/08 00:12

cogDisplays a geographical map provided by the Google Maps service, with which users can interact
TypeXAR
CategoryMacro
Developed by

Jean Vincent Drean, Sergiu Dumitriu, Ecaterina Moraru (Valica), Victor Rachieru, Gabriela Smeria, Zoubir Medjdoub, Guillaume Delhumeau, Stéphane Laurière

Active Installs191
Rating
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

You will need connectivity back and forth from the wiki to either OpenStreetMap or Google Maps servers for the macro to properly work. This might not be the case for a intranet in a corporate environment for example. 

Content

The content is optional and is used only with Google Maps for displaying information in a popup activated on click. With OpenStreetMap, a click leads to the OpenStreetMap routing service.

Parameters

NameMandatoryValuesDefaultDescription
locationYes*-Address of a place
widthNo[0-9]+px or % 500pxThe width in pixels or in percent the map container will take
heightNo[0-9]+px or %400pxThe height in pixels or in percent the map container will take
zoomNo[0-9]+15 (which is about the size of a block of houses)The initial zoom the map will be focused at. Please refer to your provider API reference for intelligible values.
errorsNoshow / hideshowDisplay a popup with the returned status code when it is anything other than "OK"
locationTypeNoaddress/latlngaddressSince 1.2.3 Specify the type of location, possible values : address (default) or latlng ( in this case the location should be a geographic coordinate like : 47.156427, 27.576387)
tilesNoOSM tile serverURL scheme of the tile provider. Example: https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png (default). See also: OpenStreetMap tile servers. The tile provider can be set either from the map macro administration page (see below) or at the macro level. 

Administration

Choose the map library (either Leaflet (default) or Google Maps) and the tile server directly from the map macro administration section. To use the Google Maps JavaScript API or the Mapbox tile server, you must register your app project on the Google API Console or on the Mapbox console and get a Google API key or a Mapbox token, which you can add to your app.

map-macro-administration.jpg

Examples

Map with default OpenStreetMap tiles

Code:

{{map location="35 rue Beaubourg, 75003 Paris, France" /}}

Result (as image):

map1.png

Map using geographic coordinates and percent width

Code:

{{map location="47.156427, 27.576387" locationType="latlng" width="40%" /}}

Result (as image):

map2.png

Map with custom tiles

Code:

{{map location="35 rue Beaubourg, 75003 Paris" tiles="http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg" /}}

Result (as image):

map3.png

Map with Google Maps tiles

In order to use the Google Maps tiles, head to the map macro administration section as explained above, and select "Google Maps" library. In that case, you don't need to fill in any tile server as it is automatically set to the Google Maps one.

{{map location="Rue des Thermopyles, 75014 Paris" width="400px" height="300px"}}
A beautiful street in Paris
{{/map}}

Result (as image):

map4.png

Google Maps Events

If you use the Google Maps library, the events listed below are available.

NameDescription
GMAPS:OKIndicates that no errors occurred; the address was successfully parsed and at least one geocode was returned
GMAPS:ZERO_RESULTSIndicates that the geocode was successful but returned no results. This may occur if the geocoder was passed a non-existent address.
GMAPS:OVER_QUERY_LIMITIndicates that you are over your quota.
GMAPS:REQUEST_DENIEDIndicates that your request was denied.
GMAPS:INVALID_REQUESTGenerally indicates that the query (address, components or latlng) is missing.
GMAPS:UNKNOWN_ERRORIndicates that the request could not be processed due to a server error. The request may succeed if you try again.

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

In case of an upgrade of this macro from version 1.2.5 to version 2.0 or greater in XWiki strictly lesser than 10.7-rc-1, you will need to restart XWiki after performing the upgrade.

Release Notes

v2.1.7

The following translations have been updated with this release:

v2.1.6

The following translations have been updated with this release:

v2.1.5

The following translations have been updated with this release:

v2.1.4

v2.1.3

v2.1.2

The following translations have been updated with this release:

v2.1.1

The following translations have been updated:

v2.1

v2.0

v1.2.5

v1.2.4

v1.2.3

v1.2.2

v1.2.1

v1.2

v1.1

  • Fixed wrong macro visibility (macro only worked for the Admin user)
  • Fixed "not an inline macro" errors in the macro description page
  • Bug: the Google Maps API is loaded more than once
  • Codestyle improvements, faster startup

v1.0

Initial release

Dependencies

Dependencies for this extension (org.xwiki.contrib:xwiki-macro-map 2.1.7):

  • org.webjars:leaflet 1.3.1

Get Connected