Documentation
Reference
2.1.50 (current version)
collection
interactivityModel
Interfaces

geoXml.load

Static function.

Loads an XML file with geographic data and converts it into a GeoObjectCollection. The generated collection can be passed to the specified function for subsequent processing. Supported XML data formats: YMapsML, KML, GPX. For the topmost collection of geo objects from a GPX file, the following presets are available:

  • 'gpx#interactive' - Provides outputting information about a point on a route when clicked. Additionally, when this preset is used, the following geo object properties become available in the balloon layout: time, velocity, trackName, trackDescription, pointName, pointDescription, lon, lat, sym. Used by default.
  • 'gpx#plain' - Items in GPX collections behave like normal geo objects.

Returns Promise object. If the XML file at the specified URL is downloaded successfully, the promise will be resolved and will get an object with the following fields (as parameters):

.

{ vow.Promise } geoXml.load(url)

Parameters:

ParameterDefault valueDescription
url*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: String

The URL of a file with geographical data.

* Mandatory parameter/option.

Example:

// Creating and initializing map...

// Loading and displaying a ymapsml file from the My Maps service
ymaps.geoXml.load('http://maps.yandex.ru/export/usermaps/HNQ5uTUgbjy6L0dW2uReUjSoXb1Ad7jw/')
     .then(function (res) {
         // Adding elements of the ymapsml file to the map
         map.geoObjects.add(res.geoObjects);
         // Setting the map boundaries and type.
         // res.mapState.getBounds() boundaries are applied to the map asynchronously,
         // because we need to get information about available zoom levels for these bounds
         // res.mapState.getType() is applied to the map synchronously.
         if (res.mapState) {
             res.mapState.applyToMap(map).then(function () {
                 alert('Boundaries applied to the map ' + res.mapState.getBounds().toString());
             });
         }
         // If information about boundaries isn't provided in repr:View in the YMapsML file,
         // we can apply gml:boundedBy for the top ymaps:GeoObjectCollection element
         else if (res.geoObjects.properties.get('boundedBy')) {
             map.setBounds(res.geoObjects.properties.get('boundedBy'), {
                 checkZoomRange: true
             });
         }
    });

// Loading and displaying a KML file
ymaps.geoXml.load('http://api.yandex.ru/maps/doc/jsapi/1.x/examples/kml/demonstration.xml')
     .then(function (res) {
         map.geoObjects.add(res.geoObjects);
    });

// Loading and displaying a GPX file
ymaps.geoXml.load('http://karmatsky.narod2.ru/MskChel2.xml')
     .then(function (res) {
         res.geoObjects.options.set({
             balloonContentBodyLayout: ymaps.templateLayoutFactory.createClass(
             // The balloon will only show the geo object's name property and the speed
             '<b>{{ properties.name }}</b> {{ properties.velocity }}'
             )
        });

         map.geoObjects.add(res.geoObjects);
         // Metadata about boundaries from a GPX file is stored in properties of the res.geoObjects collection.
         // Applying these boundaries to the map.
         if (res.geoObjects.properties.get('boundedBy')) {
             map.setBounds(res.geoObjects.properties.get('boundedBy'), {
                 checkZoomRange: true
             });
         }
     });