Setting the visual appearance of displayed objects

YMapsML lets you determine the visual appearance of objects displayed on a map. Since visualization of YMapsML elements is performed using geo objects that have a preset appearance, we are basically talking about changing the standard method of displaying geo objects.

To change the visual appearance of displayed objects via YMapsML, styles are used. Styles let you set certain parameters for displaying geo objects and create a custom HTML representation using templates.

To define styles, use the repr:Style element. For templates, use repr:Template. To specify which style should be applied when displaying a geographical object or collection, use the ymaps:style element.

<ymaps:GeoObject>
  <gml:style>#customStyle</gml:name>
  <gml:Point>
    <gml:pos>27.431259 38.621162</gml:pos>
  </gml:Point>
</ymaps:GeoObject>

Here, #customStyle is a link to the ID of the repr: Style element containing a style description. The link to the style ID is always prefixed by the “#” symbol.

The link can reference a style located not only in the current file, but also in external YMapsML files that can be accessed over HTTP. In this case, the link to the style is shown as <YMapsML file URL>#<style identifier>:

<repr:style>
    https://sandbox.api.maps.yandex.net/examples/ru/2.1/ymapsml_loadstyles/overlays_styles.xml#rostov
</repr:style>

The sandbox has an example of loading a style from an external file.

When defining a geographical object or collection, you can link to a style, but not to a template. In other words, it is incorrect to link to the element repr:Template. Templates are used to define the HTML representation of geo objects that use styles. Techniques for using templates are described in the section Templates.