Source: api/GPXLayer.js

Retour à la documentation
define([
        "dojo/_base/declare", "spw/api/DataLayer", "esri/request",
        "dojo/_base/array", "dojo/_base/lang",
        "spw/api/GeometryConverter", "esri/InfoTemplate"
    ],
    function(declare, DataLayer, request, array, lang, GeometryConverter, InfoTemplate) {

        /**
         * @class spw.api.GPXLayer
         * @classdesc Layer construit sur base d'un fichier GPX (précisé par une URL ou par son contenu)
         * @extends {spw.api.DataLayer}
         */
        return declare("spw.api.GPXLayer", [DataLayer], /** @lends spw.api.GPXLayer.prototype */ {

            /**
             * Récupère les données et les transforme en features
             * @memberOf spw.api.DataLayer
             */
            fetchData: function(map, surface) {
                if (this.url) {
                    request({
                        url: this.url,
                        handleAs: 'xml'
                    }).then(
                        lang.hitch(this, function(doc) {
                            if (doc == null) {
                                this.emit('error', lang.mixin(new Error('not a valid GPX file'), {
                                    type: 'loadError'
                                }));
                                return;
                            }

                            this.geoJSON = GeometryConverter.gpxToGeoJSON(doc);
                            this.features = this.geoJSON.features;

                            this.processFeatures();
                        }),
                        lang.hitch(this, function(err) {
                            this.emit('error', lang.mixin(err, {
                                type: 'loadError'
                            }));
                        })
                    );
                }
                else if (this.rawData) {
                    var parser = new DOMParser();

                    this.geoJSON = GeometryConverter.gpxToGeoJSON(parser.parseFromString(this.rawData, 'text/xml'));
                    this.features = this.geoJSON.features;

                    this.processFeatures();
                }
                else if (this.features) {
                    this.processFeatures();
                }
            },

            /**
             * Traite les features et les transforme en graphics
             * @memberOf spw.api.DataLayer
             */
            processFeatures: function() {
                if (this.showTemplate) {
                    this.infoTemplate = new InfoTemplate("Description", "${*}");
                }

                this.inherited(arguments);
            }

        });
    });