Documentation
Reference
2.1.38 (current version)
collection
interactivityModel
Interfaces

Geo XML

The Yandex.Maps API can load XML files with geographical data in YMapsML, KML, and GPX formats.

The geoXml.load function is used for loading data; it is passed the URL of the XML file. Data is loaded asynchronously (similar to geocoding), and the format of the loaded file is automatically detected by the geoXml.load file. Data about geo objects is converted to a GeoObjectCollection collection and inserted in the geoObjects field of the object to be passed to the handler function. This object can be placed on the map.

ymaps.geoXml.load('http://openflights.org/demo/openflights-sample.kml').then(function (res) {
    myMap.geoObjects.add(res.geoObjects);
});

The Yandex server loads the XML data from the source with the specified URL. This means that XML data should be stored on a resource that has public access available (or make sure that the Yandex server loader can get access to it).

The YMapsML format allows for describing not only coordinates, geometric properties of geo objects and their visual display, but also for including a description of map parameters. Map parameters (if they are set) are in the mapState field as an object that allows to apply these parameters to any map.

ymaps.geoXml.load('http://maps.yandex.ru/export/usermaps/93jfWjoXws37exPmKH-OFIuj3IQduHal/').then(function (res) {
    myMap.geoObjects.add(res.geoObjects);
    if (res.mapState) {
        res.mapState.applyToMap(myMap);
    }
});

For collections that are formed from GPX tracks during loading, there are two presets defined, with the keys gpx#interactive and gpx#plain. The first one replaces the properties of polylines that are connected by GPX points, so that when any of these points is clicked on, additional information is shown (time, speed, and so on). This preset is used by default. For the second one, additional information is not produced.

ymaps.geoXml.load('http://karmatsky.narod2.ru/MskChel2.xml').then(function (res) {
    res.geoObjects.options.set({'preset':'gpx#plain'});
    myMap.geoObjects.add(res.geoObjects);
});