Maps | On-Premise | 2GIS Documentation
On-Premise

MapGL JS API

The MapGL JS API service implements a JavaScriptAPI for displaying 2GIS maps in web applications and websites.

The service is an nginx server that allows you to download the main library file (api.js) and the default (light) style for the map (the style directory).

Parameter Recommended value
Number of CPU cores (per pod) 2
Amount of RAM (per pod) 2 GB
Minimum number of pods (for basic fault tolerance) 2

It is recommended to use the Helm chart to install the service.

Caution! The MapGL JS API service must be available for client requests, since the JavaScript library and map style are downloaded directly by the browser.

Before installing the service, you need to specify the repository that stores the downloaded Docker image of the service. To do this, create a YAML file with the following content:

settings.yaml

image:
    repository: your-docker-hub/2gis/mapgl-js-api
    tag: 1.0.0

You can also specify additional settings in this file, such as resource limits, use of Ingress, etc.

image:
    repository: your-docker-hub/2gis/mapgl-js-api
    tag: 1.0.0

resources:
    requests:
        cpu: 30m
        memory: 32M
    limits:
        cpu: 100m
        memory: 64M

Values from this file will be substituted into the configuration templates from the templates directory.

After creating the YAML file, call the helm install command and specify the name of the created file:

helm install mapgl . -f settings.yaml

To update the service after changing the settings or after updating the Docker image, call the helm upgrade command:

helm upgrade mapgl . -f settings.yaml

In addition to the library and style files provided by the MapGL JS API service, you need tiles to display the map. Tiles are square images that form the map (see example). Using tiles allows maps to load dynamically as you move or zoom the map.

Tiles are provided by a separate service called Tileserver API. This service is currently under development and not yet available. Temporarily, the main 2GIS tile servers (tile[0-3].maps.2gis.com) are used to process requests.

To test that the service is working, you can create the following HTML file and open it in a browser. Replace the mapgl.service.published.host string with the URL of the published MapGL JS API service.

<html>
    <head>
        <title>MapGL JS API. On-Premise</title>
        <style>
            #map {
                width: 100%;
                height: 100%;
            }
        </style>
    </head>

    <body>
        <div id="map"></div>
        <script src="http://mapgl.service.published.host/api.js"></script>
        <script>
            const map = new mapgl.Map('map', {
                key: 'your key',
                center: [55.31878, 25.23584],
                style: 'http://mapgl.service.published.host/style/',
                styleOptions: {
                    iconsPath: 'http://mapgl.service.published.host/style/images/',
                    fontsPath: 'http://mapgl.service.published.host/style/fonts/',
                },
                zoom: 13,
            });
        </script>
    </body>
</html>