Connecting and publishing styles
You can connect a style that you configured in the Style editor to a map added to a web page or mobile application. If you change the style in the Style editor after connecting, publish style changes to apply them to maps.
You can also share a created style with other users of the Style editor.
Connecting a style
MapGL JS API
To connect a style to a MapGL JS API map:
-
Open the Style editor.
-
In the My styles block, open a card of the required style.
-
Click Share in the top menu.
-
In the Style ID field, copy a style identifier.
-
Add the identifier to the map code using the
style
parameter of theMap
class and specify the starting scale of the map in thestyleZoom
parameter:const map = new mapgl.Map('container', { center: [55.31878, 25.23584], key: 'Your API access key', style: 'Your Style ID', styleZoom: 13, });
For detailed examples, see the Map styles instruction.
iOS SDK
To connect a style to a map in iOS SDK:
-
Open the Style editor.
-
In the My styles block, open a card of the required style.
-
Click Share in the top menu.
-
Click Export the style.
-
Select the required styles from the list, specify style codes to make it easier to switch them in the code of the mobile application (e.g.,
day
,night
, and others), and select an SDK version. -
Click Export.
-
In the new History tab, select the generated archive and click Download the style.
-
Move the downloaded styles to the folder of the mobile application and link them:
var mapOptions = MapOptions.default let styleFactory = sdk.makeStyleFactory() mapOptions.styleFuture = styleFactory.loadResource(name: "styles.2gis", bundle: .main) let mapFactory = sdk.makeMapFactory(options: mapOptions) let map = mapFactory.map
For detailed examples, see the Map styles instruction.
Android SDK
To connect a style to a map in Android SDK:
-
Open the Style editor.
-
In the My styles block, open a card of the required style.
-
Click Share in the top menu.
-
Click Export the style.
-
Select the required styles from the list, specify style codes to make it easier to switch them in the code of the mobile application (e.g.,
day
,night
, and others), and select an SDK version. -
Click Export.
-
In the new History tab, select the generated archive and click Download the style.
-
Move the downloaded styles to the folder of the mobile application and link them:
val mapContainer = findViewById<LinearLayout>(R.id.map_container) val mapOptions = MapOptions().apply { styleFile = ru.dgis.sdk.File("style.2gis") // If there are two themes named day and night, they switch automatically according to the system settings // If you use other names, specify them: setTheme("light", "dark") // If you want to switch themes on your own, use: setTheme("cool theme") } mapView = MapView(this, mapOptions) mapContainer.addView(mapView)
Publishing style changes
In the Style editor, you work with a draft of the project. All changes are saved automatically, but are not published in services that use the style.
To update the style in all services to which the map is connected:
-
Open the Style editor.
-
In the My styles block, open a card of the required style.
-
Click Publish in the top menu.
Share a link to a style
To share a link to a project with a style with other users of the Style editor:
-
Open the Style editor.
-
In the My styles block, open a card of the required style.
-
Click Share in the top menu.
-
Copy a link to a style:
- Link for preview — another user can view the style, but cannot duplicate it.
- Link for copying — another user can both view the style and duplicate it for further work. Use this link if you want to allow users to create their own styles based on your copy: see the Creating a style from a copy of another user instruction.