SuperMap iClient for MapLibreGL
This guide will quickly get you started on SuperMap iClient for MapLibreGL. You can get detailed interface parameters on the API page.
Preparing your page
Get MapLibreGL and SuperMap iClient for MapLibreGL
MapLibreGL and SuperMap iClient for MapLibreGL are needed for development.Among them, MapLibreGL includes CSS files and JS files. You can get these documents in the following way:
MapLibreGL
- Download CSS file from MapLibreGL Official Website
- Download JS file from MapLibreGL Official Website
SuperMap iClient for MapLibreGL
- Download the latest version from SuperMap iClient JavaScript Official Website
- Download the release version from SuperMap iClient for MapLibreGL GitHub
Import
Import files
The following is detailed account of how to import MapLibreGL files online via CDN, and how to import SuperMap iClient for MapLibreGL through online sites.
Create a new HTML file, import MapLibreGL CSS file and JS file in < head> tag, and fill in UNPKG's hosting address, as follows:
Introduce the iclient-maplibregl CSS file and JS file, and fill in the SuperMap iClient for MapLibreGL online site address:
npm
Before using this method, please check if the application Node.js,is installed on your computer. If it is not installed, you can install it by downloading the installer Then install SuperMap iClient for MapLibreGL by entering the following command on the command line:
Import the CSS files
Create a new HTML file and import the MapLibreGL CSS file and the iclient-maplibregl CSS file into the <head> tag as follows:
Modular Development
ES6
You need to use npm to install dependencies before development, and then import the corresponding modules through ES6's import module loading syntax.
On demand
First,install @supermap/babel-plugin-import:
Then edit .babelrc:
Next, if you need QueryByBoundsParameters, QueryService, edit:
Import all modules
CommonJS
CommonJS is a JavaScript modular specification based on the Node.js environment. Use npm to install dependencies before development, and then introduce the corresponding modules via the require method.
Import partial modules
Import all modules
AMD
The following example uses the RequireJS library to implement; Download maplibre-gl.js and iclient-maplibregl.js through " Get MapLibreGL and SuperMap iClient for MapLibreGL " and place them in the directory where the entry master file specified by RequireJS is located.
Import all modules
CMD
The following example uses the SeaJS library to implement; Download maplibre-gl.js and iclient-maplibregl.js through " Get MapLibreGL and SuperMap iClient for MapLibreGL " and place them in the directory where the entry master file specified by SeaJS is located.
Import all modules
Package configuration
Because iClient uses ES6, to be compatible with browsers that do not support ES6 syntax, some configuration, including syntax conversion, needs to be done during the packaging process.
The packaged configuration here is for ES6 and CommonJS modular development, and for projects developed for AMD and CMD modules, there is no need to utilize packaging tools.
Take webpack4 as an example. Since the different package managers will cause the structure of the installation package to be different, the following examples describe the npm and cnpm configurations:
If you use npm install
or cnpm install --by=npm
to install
dependencies, you need to add the following configuration items
in the webpack.config.js.
If you use cnpm install
to install dependencies, you need to add the
following configuration items
in the webpack.config.js.
Creating a map
Map published by SuperMap iServer
In the Preparing Your Page section, a new HTML page has been created, and continue to add code to create maps in the page, as follows:
Taking the world map published in SuperMap iServer as an example, add code to
Enjoy the result.
Adding controls
By adding controls to the map, you can achieve interactive operations such as zooming in and zooming out. Commonly used controls:
Control | Class name | Introduction |
---|---|---|
Navigation | maplibregl.NavigationControl | The default is in the top left corner of the map |
Scale | maplibregl.ScaleControl | The default is at the bottom left corner of the map |
Fullscreen | maplibregl.FullscreenControl | The default is in the top right corner of the map |
Locate | maplibregl.GeolocateControl | The default is in the top left corner of the map |
Copyright | maplibregl.AttributionControl | The default is in the lower right corner of the map |
When adding a control, you should initialize the map first, and then add the control to the map via the addControl() method, for example:
Navigation control
Enjoy the result.
Scale control
Enjoy the result.
Using vector tiles
Vector tiles organize and define vector data through different description files, analyze data in real time and complete rendering on the client. SuperMap iServer provides vector tile layers
Enjoy the result.
Web Symbol
Web symbols cover SuperMap iDesktop, SuperMap iDesktopX part of the point line polygon symbols, users can quickly add symbols to the map by Web Symbol ID . At the same time, you can also customize the symbols according to the symbol specification. This section mainly introduces the introductory usage of Web symbols, please refer to the API page for detailed interface.
Import
Import files
First, import MaplibreGL and SuperMap iClient for MaplibreGL .
Then, set the basePath to the absolute or relative path to the resources folder, depending on the following two scenarios.
-
Default resources folder path
If the resources folder is placed in the same level as the entry HTML file, you do not need to configure the basePath and can just use the default value.
-
Customize the resources folder path
First, download the SuperMap iClient for MaplibreGL package, move the resources folder to any location in the project.
Then, set basePath to the resources folder absolute or relative to the entry HTML path.
npm
First, npm install @supermap/iclient-maplibregl .
Then, move the resources folder under the @supermap/iclient-maplibregl installation package to any folder in the project root directory.
Next, set basePath to the absolute or relative root path to the resources folder.
Get Started Quickly
Symbol Specification
Web symbols are symbol objects consisting of paint , layout (except visibility property) in Maplibre Layers.
Using Web Symbols
First, get Web Symbol ID.
Then, initialize the Web symbol with new maplibregl.supermap.WebSymbol().init, specify the symbol resource path.
And then, use the interface loadSymbol to load Web symbols.
Next, use the interface addSymbol to add symbols to the map.
Finally, the layer is added using the interface addLayer while the layer sets the Web symbol.
Example code.
Enjoy the result.
Using Custom Web Symbols
First, use the new maplibregl.supermap.WebSymbol().init to initial Web symbol.
Then, use the interface addSymbol to add symbols to the map.
Next, use the interface addLayer to add the layer and set the Web symbol for the layer.
Example code.
Enjoy the result.