From a1506c9d8f77f20ef2cd98ebed409cd1aa5846a8 Mon Sep 17 00:00:00 2001 From: lgrd Date: Thu, 7 May 2020 14:05:57 +0200 Subject: [PATCH 01/14] feat(isochrone): appel au nouveau service d'isochrone --- package.json | 4 +- src/Services/DefaultUrlService.js | 10 +- .../ProcessIsoCurve/ProcessIsoCurve.js | 133 +++++++++---- .../Request/ProcessIsoCurveRequest.js | 178 +++++------------- .../Request/model/ProcessIsoCurveParam.js | 144 ++++++++------ src/Services/Services.js | 16 +- 6 files changed, 245 insertions(+), 240 deletions(-) diff --git a/package.json b/package.json index e13353ba..1c3ddf8d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "geoportal-access-lib", - "version": "2.1.6", - "date": "03/10/2019", + "version": "2.1.8-alpha.1", + "date": "04/05/2020", "description": "French Geoportal resources access library", "module": "src/Gp.js", "main": "dist/GpServices-src.js", diff --git a/src/Services/DefaultUrlService.js b/src/Services/DefaultUrlService.js index b2e84a72..7b2f7414 100644 --- a/src/Services/DefaultUrlService.js +++ b/src/Services/DefaultUrlService.js @@ -108,20 +108,14 @@ var DefaultUrlService = { * @property {Function} url (key) - Returns isocurve service default urls with or without geoportal access key given as a parameter. The result is a javascript object with different urls given used protocols ("iso-json" or "iso-xml"). */ ProcessIsoCurve : { - _key : { - "iso-json" : "/isochrone/isochrone.json", // rest (geoconcept) - "iso-xml" : "/isochrone/isochrone.xml" // rest (geoconcept) - }, + _key : "simple/1.0.0/isochrone", /** * url * @param {String} key - key * @returns {String} url */ url : function (key) { - return { - "iso-json" : DefaultUrlService.url(key, this._key["iso-json"]), - "iso-xml" : DefaultUrlService.url(key, this._key["iso-xml"]) - }; + return DefaultUrlService.url(key, this._key); } }, /** diff --git a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js index bb9ecbbc..fa4032ed 100644 --- a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js +++ b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js @@ -6,6 +6,7 @@ import CommonService from "../CommonService"; import DefaultUrlService from "../DefaultUrlService"; import ProcessIsoCurveRequest from "./Request/ProcessIsoCurveRequest"; import ProcessIsoCurveResponseFactory from "./Response/ProcessIsoCurveResponseFactory"; +import TileMatrixSet from "../AutoConf/Response/model/TileMatrixSet"; /** * @classdesc @@ -17,11 +18,10 @@ import ProcessIsoCurveResponseFactory from "./Response/ProcessIsoCurveResponseFa * @extends {Gp.Services.CommonService} * @alias Gp.Services.ProcessIsoCurve * @param {Object} options - options spécifiques au service (+ les options heritées) + * + * @param {String} options.resource - La ressource utilisée pour le calcul. Ce paramètre devrait être obligatoire car il l'est dans l'appel au service. Mais il ne l'est pas pour des raisons de rétrocompatibilité. * - * @param {String} options.outputFormat - Le format de la réponse du service iso : 'xml' ou 'json'. - * Ce paramètre déterminera l'extension '.xml' ou '.json' du service. - * Nécessaire si serverUrl est renseigné pour connaître le format dans lequel sera fournie la réponse (pour son traitement). - * Par défaut, ce paramètre vaut 'json'. + * @param {String} options.outputFormat - Le format de la réponse du service iso : 'json' uniquement et par défaut. * * @param {Object} options.position - Point de départ du calcul. * Coordonnées exprimées en longitudes, latitudes (EPSG:4326) @@ -36,14 +36,25 @@ import ProcessIsoCurveResponseFactory from "./Response/ProcessIsoCurveResponseFa * @param {String} [options.graph = "voiture"] - Nom du graphe à utiliser pour le calcul (« Pieton » ou « Voiture »). * La valeur par défaut est : «voiture» * - * @param {Array.} [options.exclusions] - Critères d'exclusions à appliquer pour le calcul. + * @param {Array.} [options.exclusions] - DEPRECATED: Ce paramètre est conservé pour une rétrocompatibilité de l'api. Le nouveau paramètre à utiliser est options.constraints. + * Critères d'exclusions à appliquer pour le calcul. * On précise ici le type de tronçons que l'on ne veut pas que l'isochrone/distance emprunte * (valeurs possibles : « toll » (éviter les péages), « bridge », « tunnel »). * + * @param {Object[]} [options.constraints] - Critères de contraintes à appliquer sur un itinéraire. Les valeurs disponibles dépendent de la ressource utilisée. Il est donc utile de regarder le getCapabilities. + * @param {String} [options.constraints.constraintType] - Type de la contrainte. Généralement "banned". + * @param {String} [options.constraints.key] - Clé de la contrainte. Généralement "wayType". + * @param {String} [options.constraints.operator] - Opérateur de la contrainte. Généralement "=". + * @param {String} [options.constraints.value] - Valeur de la contrainte. Généralement "autoroute". + * * @param {String} [options.method = "time"] - Méthode utilisée pour le calcul de la courbe iso. * Les valeurs possible sont "time" pour un calcul d'isochrone, "distance" pour un calcul d'isodistance. * Pas de valeur spécifié équivaut à un calcul d'isochrone. - * + * + * @param {String} [options.distanceUnit = "km"] - Indique si la distance doit être exprimée en km ou m dans la réponse ("m" or "km"). + * + * @param {String} [options.timeUnit = "standard"] - Indique si la durée doit être exprimée en seconde, minute ou heure dans la réponse ("standard", "second", "minute", "hour"). Il peut-être formatté hh:mm::ss avec la valeur standard. + * * @param {Float} options.time - Durée maximum (exprimée en secondes) à utiliser pour le calcul de la courbe à partir du ou jusqu'au point « location ». * Ce paramètre doit être renseigné si l'option "méthod" a la valeur "time". * Si l'option method n'est pas renseignée, ce paramètre doit être renseigné. @@ -82,11 +93,8 @@ import ProcessIsoCurveResponseFactory from "./Response/ProcessIsoCurveResponseFa * distance : 200, * [time : ] * method : "distance", - * exclusions : ["Bridge", "Tunnel", "Toll"], * graph : "voiture", - * reverse : false, - * smoothing : false, - * holes : false + * reverse : false * }; * @private */ @@ -149,22 +157,98 @@ function ProcessIsoCurve (options) { this.options.method = this.options.method || "time"; // options par defaut du service + // TODO: modifier lors de la mise en production du service + this.options.resource = options.resource || "bduni-idf-osrm"; this.options.exclusions = options.exclusions || null; - this.options.graph = options.graph || "Voiture"; // TODO test de la valeur à faire ! this.options.reverse = options.reverse || false; - this.options.smoothing = options.smoothing || false; - this.options.holes = options.holes || false; this.options.srs = options.srs || "EPSG:4326"; + this.options.distanceUnit = options.distanceUnit || "km"; + this.options.timeUnit = options.timeUnit || "standard"; + + //options depreciees + if (options.smoothing) { + this.logger.warn("options.smoothing is DEPRECATED"); + } + this.options.smoothing = false; + if (options.holes) { + this.logger.warn("options.holes is DEPRECATED"); + } + this.options.holes = false; + + // Gestion du graphe + if (options.graph) { + if (options.graph === "Voiture") { + this.options.graph = "car"; + } + if (options.graph === "Pieton") { + this.options.graph = "pedestrian"; + } + } else { + this.options.graph = "car"; + } + + // Gestions des contraintes + this.options.constraints = []; + if (options.constraints) { + if (Array.isArray(options.constraints)) { + for (var k = 0; k < options.constraints.length; k++) { + this.options.constraints.push(options.constraints[k]); + } + } else { + throw new Error(_.getMessage("PARAM_TYPE", "constraints")); + } + } + + // Gestion de l'ancien paramètre exclusions + var constraintTunnel = {}; + var constraintPont = {}; + var constraintAutoroute = {}; + if (options.exclusions) { + if (options.exclusions.length !== 0) { + this.logger.warn("options.exclusions is DEPRECATED !!"); + for(var c = 0; c < options.exclusions.length; c++) { + if (typeof options.exclusions[c] === "string") { + options.exclusions[c] = options.exclusions[c].toLowerCase(); + } else { + // on ne crée pas une erreur pour rétro-compatibilité avec les anciennes versions + continue; + } + if (options.exclusions[c] === "toll") { + constraintAutoroute.constraintType = "banned"; + constraintAutoroute.key = "wayType"; + constraintAutoroute.operator = "="; + constraintAutoroute.value = "autoroute"; + this.options.constraints.push(constraintAutoroute); + } + if (options.exclusions[c] === "tunnel") { + constraintTunnel.constraintType = "banned"; + constraintTunnel.key = "wayType"; + constraintTunnel.operator = "="; + constraintTunnel.value = "tunnel"; + this.options.constraints.push(constraintTunnel); + } + if (options.exclusions[c] === "bridge") { + constraintPont.constraintType = "banned"; + constraintPont.key = "wayType"; + constraintPont.operator = "="; + constraintPont.value = "pont"; + this.options.constraints.push(constraintPont); + } + } + } + } // on passe l'option outputFormat en minuscules afin d'éviter des exceptions. this.options.outputFormat = (typeof options.outputFormat === "string") ? options.outputFormat.toLowerCase() : "json"; + if (options.outputFormat && options.outputFormat !== "json") { + this.logger.warn("options.outputFormat could only be json"); + } + this.options.outputFormat = "json"; // gestion de l'url du service par defaut // si l'url n'est pas renseignée, il faut utiliser les urls par defaut if (!this.options.serverUrl) { - var lstUrlByDefault = DefaultUrlService.ProcessIsoCurve.url(this.options.apiKey); - - var urlFound = lstUrlByDefault["iso" + "-" + this.options.outputFormat]; + var urlFound = DefaultUrlService.ProcessIsoCurve.url(this.options.apiKey); if (!urlFound) { throw new Error("Url by default not found !"); } @@ -172,23 +256,6 @@ function ProcessIsoCurve (options) { this.logger.trace("Serveur URL par defaut : " + this.options.serverUrl); } - // gestion du type de service - // si l'extension de l'url est .json ou .xml, on surcharge le format de sortie (outputFormat) - var idx = this.options.serverUrl.lastIndexOf("."); - if (idx !== -1) { - var extension = this.options.serverUrl.substring(idx + 1); - if (extension && extension.length < 5) { // FIXME extension de moins de 4 car. ... - this.logger.trace("Serveur Extension URL : " + extension); - switch (extension.toLowerCase()) { - case "json": - case "xml": - this.options.outputFormat = extension.toLowerCase(); - break; - default: - throw new Error("type of service : unknown or unsupported (json or xml) !"); - } - } - } } /** diff --git a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js index eb81af40..8df2a870 100644 --- a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js +++ b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js @@ -7,7 +7,7 @@ import ProcessIsoCurveParam from "./model/ProcessIsoCurveParam"; * @classdesc * Classe de gestion des requêtes sur le service de calcul d'isoschrone/isodistance. * Les requêtes peuvent être en mode GET ou POST, - * et le format de sorti est en JSON ou en XML. + * et le format de sorti est en JSON. * * @constructor * @alias Gp.Services.ProcessIsoCurve.Request.ProcessIsoCurveRequest @@ -17,17 +17,14 @@ import ProcessIsoCurveParam from "./model/ProcessIsoCurveParam"; * var options = { * httpMethod : 'GET', // GET|POST * // spécifique au service - * exclusions : ['Bridge', 'Tunnel'], * position : { * x : 2.3242664298058053, * y : 48.86118017324745 * }, - * graph : "Voiture", + * graph : "car", * method : 'time', * time : 1000, //distance : 200 * reverse : false, - * smoothing : false, - * holes : false, * srs : 'EPSG:4326' * }; * @@ -88,87 +85,35 @@ ProcessIsoCurveRequest.prototype = { */ constructor : ProcessIsoCurveRequest, - /** - * Template de la requête (POST) - * * __X__ __Y__ __SRS__ __GRAPHNAME__ __METHOD__ (obligatoire) - * * __REVERSE__ __SMOOTHING__ __HOLES__ (par defaut) - * * __TIME__ __TIMEVALUE__ (choix) - * * __DISTANCE__ __DISTANCEVALUE__ (choix) - * * __EXCLUSIONS__ __EXCLUSIONFEATURE__ __EXCLUSIONVALUE__ (optionnel) - * * __PROFIL__ __PROFILID__ __PROFILNAME__ (très optionnel) - * * __ID__ __IDVALUE__ (très optionnel) - */ - template : { - container : "\n" + - "\n" + - "__ID__" + - "\t\n" + - "\t\t__X__\n" + - "\t\t__Y__\n" + - "\t\n" + - "\t__SRS__\n" + - "\t__GRAPHNAME__\n" + - "__PROFIL__" + - "__EXCLUSIONS__" + - "\t__METHOD__\n" + - "__TIME__" + - "__DISTANCE__" + - "\t__REVERSE__\n" + - "\t__SMOOTHING__\n" + - "\t__HOLES__\n" + - "", - id : "\t__IDVALUE__\n", - profil : "\t__PROFILID__\n" + "\t__PROFILNAME__\n", - exclusions : { - container : "\t\n" + - "__EXCLUSIONFEATURE__\n" + - "\t\n", - feature : "\t\t__EXCLUSIONVALUE__" - }, - time : "\t\n", - distance : "\t__DISTANCEVALUE__\n" - }, - /** * Construction de la requête. * * @example * // GET out : - * // (http://wxs.ign.fr/KEY/isochrone/isochrone.json?) - * // location=& - * // time=& ou distance=& - * // method="DISTANCE|TIME"& - * // graph=Pieton& - * // graphName=Pieton& - * // exclusions=& - * // reverse=10& - * // smoothing=& - * // holes=& - * // srs= + * // (http://wxs.ign.fr/KEY/isochrone?) + * // resource=& + * // point=& + * // costValue=& + * // costType=& + * // profile=& + * // constraints=& + * // direction=& + * // crs= * * // POST out : - * // - * // - * // 1 - * // - * // -1.557189 - * // 47.217122 - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // - * // + * { + * resource: "bduni-idf-pgr", + * point: "2.337306,48.849319", + * costValue: 100, + * costType: "time", + * profile: "car", + * constraints: [{ + * constraintType: "banned", + * key: "ways_type", + * operator: "=", + * value: "autoroute" + * }] + * } * * @returns {String} request */ @@ -196,64 +141,39 @@ ProcessIsoCurveRequest.prototype = { case "POST": this.logger.trace("Process POST Request"); + // creation du JSON + var postRequest = {}; - request = this.template.container; + postRequest.resource = this.settings.resource; - // options non prises en compte car non implémentées ! - // clean : id - request = request.replace(/__ID__/g, ""); - // clean : profil - request = request.replace(/__PROFIL__/g, ""); + postRequest.point = this.settings.position.x + "," + this.settings.position.y; + + if (this.options.method === "distance") { + this.costType = "distance"; + this.costValue = this.options.distance; + } else { + this.costType = "time"; + this.costValue = this.options.time; + } + + postRequest.profile = this.settings.graph; - // options obligatoires - request = request.replace(/__X__/g, this.settings.position.x); - request = request.replace(/__Y__/g, this.settings.position.y); - request = request.replace(/__GRAPHNAME__/g, this.settings.graph); + if (this.settings.reverse) { + postRequest.direction = "arrival"; + } else { + postRequest.direction = "departure"; + } - // options par defaut - request = request.replace(/__SRS__/g, this.settings.srs); - request = request.replace(/__SMOOTHING__/g, this.settings.smoothing); - request = request.replace(/__HOLES__/g, this.settings.holes); - request = request.replace(/__REVERSE__/g, this.settings.reverse); + postRequest.constraints = this.settings.constraints; - // options conditionnelles + postRequest.distanceUnit = this.settings.distanceUnit; - // exclusions - if (this.settings.exclusions) { - var tmplExclusions = this.template.exclusions.container; - var exclusions = []; - for (i = 0; i < this.settings.exclusions.length; i++) { - var tmplFeature = this.template.exclusions.feature; - tmplFeature = tmplFeature.replace(/__EXCLUSIONVALUE__/, this.settings.exclusions[i]); - exclusions.push(tmplFeature); - } - tmplExclusions = tmplExclusions.replace(/__EXCLUSIONFEATURE__/, exclusions.join("\n")); - request = request.replace(/__EXCLUSIONS__/g, tmplExclusions); - } - // clean exclusions - request = request.replace(/__EXCLUSIONS__/g, ""); + postRequest.timeUnit = this.settings.timeUnit; - // distance - if (this.settings.distance) { - var tmplDistance = this.template.distance; - tmplDistance = tmplDistance.replace(/__DISTANCEVALUE__/g, this.settings.distance); - request = request.replace(/__DISTANCE__/g, tmplDistance); - // method - request = request.replace(/__METHOD__/g, "distance"); - } - // clean - request = request.replace(/__DISTANCE__/g, ""); + postRequest.crs = this.settings.srs; - // time - if (this.settings.time) { - var tmplTime = this.template.time; - tmplTime = tmplTime.replace(/__TIMEVALUE__/g, this.settings.time); - request = request.replace(/__TIME__/g, tmplTime); - // method - request = request.replace(/__METHOD__/g, "time"); - } - // clean - request = request.replace(/__TIME__/g, ""); + // conversion en chaîne de caractères + request = JSON.stringify(postRequest); break; default: diff --git a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js index 9aa419fb..bc1f2470 100644 --- a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js +++ b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js @@ -31,49 +31,40 @@ function ProcessIsoCurveParam (options) { /** Identifiant de l’isochrone */ this.id = this.options.id; + /** Resource */ + this.resource = this.options.resource; + /** Coordonnées de départ (ou arrivée si le reverse est à true). */ - this.location = this.options.position; + this.point = this.options.position; /** projection (code EPSG comme epsg:4326 ou wgs84) */ - this.srs = this.options.srs; + this.crs = this.options.srs; /** * Profil de véhicule à utiliser pour le calcul. * Voiture ou Pieton */ - this.graphName = this.options.graph; - - /** - * Identifiant et nom du véhicule - * FIXME non utilisé - */ - this.profileId = this.options.profileId || null; // TODO ! - this.profileName = this.options.profileName || null; // TODO ! + this.profile = this.options.graph; /** Liste des règles de restrictions à utiliser */ - this.exclusions = this.options.exclusions; + this.constraints = this.options.constraints; this.reverse = this.options.reverse; - this.smoothing = this.options.smoothing; - this.holes = this.options.holes; + + this.timeUnit = this.options.timeUnit; + + this.distanceUnit = this.options.distanceUnit; /** * "time" pour isochrone ou "distance" for isodistance. * Par defaut, time... */ - var value = this.options.method; - switch (value) { - case "time": - this.method = "time"; - this.time = this.options.time; - break; - case "distance": - this.method = "distance"; - this.distance = this.options.distance; - break; - default: - this.logger.warn("Par defaut, on calcule un isochrone !"); - this.method = "time"; + if (this.options.method === "distance") { + this.costType = "distance"; + this.costValue = this.options.distance; + } else { + this.costType = "time"; + this.costValue = this.options.time; } } @@ -94,19 +85,52 @@ ProcessIsoCurveParam.prototype = { constructor : ProcessIsoCurveParam, /** - * Retourne la liste des exclusions + * Retourne le point * @returns {String} x,y */ getLocation : function () { - return this.location.x + "," + this.location.y; + return this.point.x + "," + this.point.y; + }, + + /** + * Retourne l'unité de temps + * @returns {String} + */ + getTimeUnit : function () { + if (this.distanceUnit === "m") { + return "meter"; + } + if (this.distanceUnit === "km") { + return "kilometer"; + } + return ""; + }, + + /** + * Retourne la liste des contraintes + * @returns {String} + */ + getConstraints : function () { + var constraintArray = []; + + if (this.constraints.length !== 0) { + for (var k = 0; k < this.constraints.length; k++) { + constraintArray.push(JSON.stringify(this.constraints[k])); + } + } + return constraintArray.join("|"); }, /** - * Retourne la liste des exclusions - * @returns {String} exclusions + * Retourne la direction + * @returns {String} */ - getExclusions : function () { - return this.exclusions.join(";"); + getDirection : function () { + if (this.reverse) { + return "arrival"; + } else { + return "departure"; + } } }; @@ -119,60 +143,56 @@ ProcessIsoCurveParam.prototype.getParams = function () { var map = []; map.push({ - k : "location", - v : this.getLocation() + k : "resource", + v : this.resource }); map.push({ - k : "smoothing", - v : this.smoothing + k : "point", + v : this.getLocation() }); map.push({ - k : "holes", - v : this.holes + k : "direction", + v : this.getDirection() }); map.push({ - k : "reverse", - v : this.reverse + k : "costType", + v : this.costType }); map.push({ - k : "method", - v : this.method + k : "costValue", + v : this.costValue }); - if (this.time) { - map.push({ - k : "time", - v : this.time - }); - } + map.push({ + k : "profile", + v : this.profile + }); - if (this.distance) { - map.push({ - k : "distance", - v : this.distance - }); - } + map.push({ + k : "timeUnit", + v : this.timeUnit + }); map.push({ - k : "graphName", - v : this.graphName + k : "distanceUnit", + v : this.getDistanceUnit() }); - if (this.exclusions) { + if (this.crs) { map.push({ - k : "exclusions", - v : this.getExclusions() + k : "crs", + v : this.crs }); } - if (this.srs) { + if (this.constraints) { map.push({ - k : "srs", - v : this.srs + k : "constraints", + v : this.getConstraints() }); } diff --git a/src/Services/Services.js b/src/Services/Services.js index 476f5ea0..253c53bb 100644 --- a/src/Services/Services.js +++ b/src/Services/Services.js @@ -228,19 +228,23 @@ var Services = { * @method isoCurve * @param {Object} options - Options for function call. * @param {String} options.apiKey - Access key to Geoportal platform, obtained [here]{@link http://professionnels.ign.fr/ign/contrats}. + * @param {String} options.resource - Resource used to compute the route. Available values are in the GetCapabilities. * @param {Gp.Point} options.position - Start or Arrival (options.reverse===true) Point for the computing. Expressed in CRS:84 coordinates system (position.x corresponds to longitude, position.y corresponds to latitude). - * @param {String} [options.graph = "Voiture"] - User profile to use to compute the isoCurve : "Voiture" (using a vehicule) or "Pieton" (pedestrian). Has an influence on the kind of roads to use and the average speed. - * @param {Array.} [options.exclusions] - Indicates if route has to avoid some features ("toll", "bridge" or "tunnel"). - * @param {String} [options.method = "time"] - Computing method to use : "time" (using a duration as a constraint) or "distance" (using a distance as a constraint). + * @param {String} [options.graph = "Voiture"] - User profile to use to compute the isoCurve : "Voiture" (using a vehicule) or "Pieton" (pedestrian). Has an influence on the kind of roads to use and the average speed. Available values are in the GetCapabilities. + * @param {Array.} [options.exclusions] - DEPRECATED: use options.constraints. Indicates if route has to avoid some features ("toll", "bridge" or "tunnel"). + * @param {Array.} [options.constraints] - Constraints used ({'constraintType':'banned','key':'ways_type','operator':'=','value':'autoroute'}). Available values are in the GetCapabilities. + * @param {String} [options.method = "time"] - Computing method to use : "time" (using a duration as a constraint) or "distance" (using a distance as a constraint). Available values are in the GetCapabilities. * @param {Float} options.time - Maximum duration (expressed in seconds) to use when options.method is set to "time". * @param {Float} options.distance - Maximum distance (expressed in meters) to use when options.method is set to "distance". * @param {Boolean} [options.reverse = false] - Set this parameter to true if you want options.position to be the destination (instead of departure) for the computing. - * @param {Boolean} [options.smoothing = false] - Set this parameter to true if you want the resulting geometry to be smoothed. - * @param {Boolean} [options.holes = false] - Set this parameter to true if you want the resulting geometry (polygon) to have holes if pertinent. + * @param {String} [options.distanceUnit = "km"] - The unit used to provide distances in the response ("m" or "km"). + * @param {String} [options.timeUnit = "standard"] - The unit used to provide duration in the response ("standard", "second", "minute", "hour"). + * @param {Boolean} [options.smoothing = false] - DEPRECATED: Set this parameter to true if you want the resulting geometry to be smoothed. + * @param {Boolean} [options.holes = false] - DEPRECATED: Set this parameter to true if you want the resulting geometry (polygon) to have holes if pertinent. * @param {Function} options.onSuccess - Callback function for getting successful service response. Takes a {@link Gp.Services.IsoCurveResponse} object as a parameter except if "rawResponse" is set to true. * @param {Function} [options.onFailure] - Callback function for handling unsuccessful service responses (timeOut, missing rights, ...). Takes a {@link Gp.Error} object as parameter. * @param {Number} [options.timeOut=0] - Number of milliseconds above which a timeOut response will be returned with onFailure callback (see above). Default value is 0 which means timeOut will not be handled. - * @param {String} [options.outputFormat='json'] - Output format ("json" or "xml") to use for underlying webService. Only use if you know what you are doing. + * @param {String} [options.outputFormat='json'] - Output format ("json") to use for underlying webService. Only use if you know what you are doing. * @param {String} [options.serverUrl=http (s)://wxs.ign.fr/APIKEY/isochrone/isochrone.json] - Web service URL. If used, options.apiKey parameter is ignored. Only use if you know what you're doing. * @param {Boolean} [options.ssl = true] - Use of HTTPS or HTTP protocol to request the services. HTTPS by default (ssl=true). * @param {String} [options.protocol=XHR] - Protocol used to handle dialog with web service. Possible values are 'JSONP' ({@link https://en.wikipedia.org/wiki/JSONP}) and 'XHR' ({@link https://en.wikipedia.org/wiki/XMLHttpRequest}). Only XHR protocol is supported in a NodeJS environment. Only use if you know what you're doing. From 28860ac5828719019ca0cbe13b7370c6f10b26da Mon Sep 17 00:00:00 2001 From: lgrd Date: Thu, 14 May 2020 12:28:43 +0200 Subject: [PATCH 02/14] test(isochrone): MAJ des tests en cours --- src/Services/DefaultUrlService.js | 2 +- .../ProcessIsoCurve/ProcessIsoCurve.js | 6 +- .../Request/ProcessIsoCurveRequest.js | 10 +- .../Request/model/ProcessIsoCurveParam.js | 4 +- .../ProcessIsoCurveResponseFactory.js | 130 ++++-------- .../test_processisocurve-jsonp.js | 196 ------------------ .../spec-functional/test_processisocurve.js | 58 +----- .../test_Services_ProcessIsoCurve.js | 4 +- .../test_Services_ProcessIsoCurve_JSONP.js | 139 ------------- test/spec/test_Services_DefaultUrlServices.js | 3 +- .../test_Services_ProcessIsoCurveRequest.js | 77 ++++--- .../test_Services_ProcessIsoCurveResponse.js | 1 - 12 files changed, 89 insertions(+), 541 deletions(-) delete mode 100644 test/end-to-end/spec-functional/test_processisocurve-jsonp.js delete mode 100644 test/end-to-end/spec-messages/test_Services_ProcessIsoCurve_JSONP.js diff --git a/src/Services/DefaultUrlService.js b/src/Services/DefaultUrlService.js index 7b2f7414..9e889c61 100644 --- a/src/Services/DefaultUrlService.js +++ b/src/Services/DefaultUrlService.js @@ -108,7 +108,7 @@ var DefaultUrlService = { * @property {Function} url (key) - Returns isocurve service default urls with or without geoportal access key given as a parameter. The result is a javascript object with different urls given used protocols ("iso-json" or "iso-xml"). */ ProcessIsoCurve : { - _key : "simple/1.0.0/isochrone", + _key : "/simple/1.0.0/isochrone", /** * url * @param {String} key - key diff --git a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js index fa4032ed..75b80e49 100644 --- a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js +++ b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js @@ -157,9 +157,9 @@ function ProcessIsoCurve (options) { this.options.method = this.options.method || "time"; // options par defaut du service - // TODO: modifier lors de la mise en production du service - this.options.resource = options.resource || "bduni-idf-osrm"; - this.options.exclusions = options.exclusions || null; + // TODO: modifier la ressource lors de la mise en production du service + this.options.resource = options.resource || "bduni-idf-pgr"; + this.options.exclusions = options.exclusions || []; this.options.reverse = options.reverse || false; this.options.srs = options.srs || "EPSG:4326"; this.options.distanceUnit = options.distanceUnit || "km"; diff --git a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js index 8df2a870..ddef74dd 100644 --- a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js +++ b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js @@ -148,12 +148,12 @@ ProcessIsoCurveRequest.prototype = { postRequest.point = this.settings.position.x + "," + this.settings.position.y; - if (this.options.method === "distance") { - this.costType = "distance"; - this.costValue = this.options.distance; + if (this.settings.method === "distance") { + postRequest.costType = "distance"; + postRequest.costValue = this.settings.distance; } else { - this.costType = "time"; - this.costValue = this.options.time; + postRequest.costType = "time"; + postRequest.costValue = this.settings.time; } postRequest.profile = this.settings.graph; diff --git a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js index bc1f2470..a3719a4a 100644 --- a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js +++ b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js @@ -93,10 +93,10 @@ ProcessIsoCurveParam.prototype = { }, /** - * Retourne l'unité de temps + * Retourne l'unité de la distance * @returns {String} */ - getTimeUnit : function () { + getDistanceUnit : function () { if (this.distanceUnit === "m") { return "meter"; } diff --git a/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js b/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js index a959e09c..4e1dc0f9 100644 --- a/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js +++ b/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js @@ -1,5 +1,5 @@ /** - * Factory pour générer une reponse JSON à partir d'un XML ou d'un JSON + * Factory pour générer une reponse JSON à partir d'un JSON * (Factory) * * @module ProcessIsoCurveResponseFactory @@ -9,9 +9,6 @@ import Logger from "../../../Utils/LoggerByDefault"; import MRes from "../../../Utils/MessagesResources"; import ErrorService from "../../../Exceptions/ErrorService"; -import XML from "../../../Formats/XML"; -import WKT from "../../../Formats/WKT"; -import ProcessIsoCurveResponseReader from "../Formats/ProcessIsoCurveResponseReader"; import ProcessIsoCurveResponse from "./model/ProcessIsoCurveResponse"; var ProcessIsoCurveResponseFactory = { @@ -46,99 +43,50 @@ var ProcessIsoCurveResponseFactory = { logger.trace("analyze response : raw"); data = options.response; } else { - switch (options.outputFormat) { - case "xml": - logger.trace("analyze response : xml"); - - try { - var p = new XML({ - reader : ProcessIsoCurveResponseReader - }); - - // FIXME : mode XHR ne retourne que des string ? JSONP aussi à ce niveau ? - if (typeof options.response === "string") { - p.setXMLString(options.response); - } else { - p.setXMLDoc(options.response); - } - - data = p.parse(); - - if (!data) { - throw new Error(MRes.getMessage("SERVICE_RESPONSE_EXCEPTION_2")); - } - } catch (e) { - var message = e.message; - message += "\n (raw response service : '" + options.response + "')"; - options.onError.call(options.scope, new ErrorService({ - message : MRes.getMessage("SERVICE_RESPONSE_EXCEPTION", message), - status : 200, - type : ErrorService.TYPE_SRVERR - })); - return; - } - - break; + + logger.trace("analyze response : json"); + + var JSONResponse; + if (typeof options.response === "string") { + JSONResponse = JSON.parse(options.response); + } else { + JSONResponse = options.response; + } - case "json": - logger.trace("analyze response : json"); + // analyse de la reponse + if (JSONResponse.status === "OK" || JSONResponse.status === "ok") { + // création de l'objet de réponse + data = new ProcessIsoCurveResponse(); - var JSONResponse; - if (typeof options.response === "string") { - JSONResponse = JSON.parse(options.response); + // remplissage de l'objet créé avec les attribtuts de la réponse du service + if (data) { + if (data.costValue === "distance") { + data.time = ""; + data.distance = JSONResponse.distance; } else { - JSONResponse = options.response; + data.time = JSONResponse.time; + data.distance = ""; } - - // analyse de la reponse - if (JSONResponse.status === "OK" || JSONResponse.status === "ok") { - // création de l'objet de réponse - data = new ProcessIsoCurveResponse(); - - // remplissage de l'objet créé avec les attribtuts de la réponse du service - if (data) { - data.time = JSONResponse.time; - data.distance = JSONResponse.distance; - data.message = JSONResponse.message; - data.id = JSONResponse.id; - data.srs = JSONResponse.srs; - // callback de la reponse - var onWKTSuccess = function (json) { - data.geometry = json; - }; - // callback d'erreur - var onWKTError = function () { - options.onError.call(options.scope, new ErrorService({ - message : MRes.getMessage("PARAM_FORMAT", "wktGeometry") - })); - }; - if (data.hasOwnProperty("geometry")) { - WKT.toJson(JSONResponse.wktGeometry, onWKTSuccess, onWKTError); - if (!data.geometry) { - return; - } - } - var coords = JSONResponse.location.split(","); - if (data.location) { - data.location.x = coords[0]; - data.location.y = coords[1]; - } - } else { - options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_ANALYSE", options.response))); - return; - } - } else if (JSONResponse.status === "ERROR" || JSONResponse.status === "error") { - // JSHint bug if var message is used !? - var mess = JSONResponse.message; - mess += "\n (raw response service : '" + JSONResponse + "')"; - options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_EXCEPTION", mess))); - return; + + data.message = ""; + data.id = ""; + data.srs = JSONResponse.crs; + data.geometry = JSONResponse.geometry; + var coords = JSONResponse.point.split(","); + if (data.location) { + data.location.x = coords[0]; + data.location.y = coords[1]; } - break; - - default: - options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_FORMAT", "json", "xml"))); + } else { + options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_ANALYSE", options.response))); return; + } + } else if (JSONResponse.status === "ERROR" || JSONResponse.status === "error") { + // JSHint bug if var message is used !? + var mess = JSONResponse.message; + mess += "\n (raw response service : '" + JSONResponse + "')"; + options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_EXCEPTION", mess))); + return; } // info : en cas de problèmes de droits (clé invalide ou autre), la réponse est au format XML !! diff --git a/test/end-to-end/spec-functional/test_processisocurve-jsonp.js b/test/end-to-end/spec-functional/test_processisocurve-jsonp.js deleted file mode 100644 index f36fca60..00000000 --- a/test/end-to-end/spec-functional/test_processisocurve-jsonp.js +++ /dev/null @@ -1,196 +0,0 @@ -/** -* FIXME avec le JSONP, l'erreur est au niveau du html (execution de la balise script), -* et il est difficile de la levée..., afin de la faire apparaitre dans les tests... -*/ - -import Gp from "../../../dist/GpServices-src.js"; - -import sinon from "sinon"; -import { assert } from "chai"; -import { expect } from "chai"; -import { should } from "chai"; -should(); - -// pass this option from webpack -var mock = __MOCK__; - -describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistances : JSONP --", function () { - - var myKey = (mock) ? "CLE" : "jhyvi0fgmnuxvfv0zjzorvdn"; - - describe('Service.isoCurve : SUCCESS', function () { - - this.timeout(15000); - - describe("Test sur l'utilisation basique du service (paramètres par défaut) ", function () { - - // options par defaut (à surcharger) - var options = { - apiKey: myKey, - protocol: 'JSONP', - callbackSuffix: "", - onSuccess: function (response) { - console.log(response); - }, - onFailure: function (error) { - console.log(error); - }, - // spécifique au service - position: { - x: 2.3242664298058053, - y: 48.86118017324745 - }, - time: 200 - }; - - it("paramètres position, time, et les callbacks onSuccess et onFailure", function (done) { - // description du test - // requête GET du service REST en json, - // calcul d'isochrone (time), se basant sur le graphe "voiture", sans paramètres spécifiques - // requête envoyée : http://wxs.ign.fr/jhyvi0fgmnuxvfv0zjzorvdn/isochrone/isochrone.json?location=2.3242664298058053,48.86118017324745&smoothing=false&holes=false&reverse=false&method=time&time=200&graphName=Voiture&srs=EPSG:4326&callback=callback - - if (mock) { options.serverUrl = 'test/end-to-end/spec-functional/fixtures/jsonp/callback-iso-json-default'; } - - options.onSuccess = function (response) { - console.log(response); - should().exist(response); - expect(response).to.be.an("Object"); - - expect(response).to.have.property("location"); - expect(response.location).to.be.an("object"); - expect(response.location).to.have.property("x"); - expect(response.location).to.have.property("y"); - - expect(response).to.have.property("geometry"); - expect(response.geometry).to.be.an("object"); - expect(response.geometry).to.have.property("coordinates"); - expect(response.geometry.coordinates).to.be.an("array"); - - expect(response).to.have.property("message"); - expect(response).to.have.property("srs"); - expect(response).to.have.property("time"); - done(); - }; - options.onFailure = function (error) { - console.log(error); - done(error); - }; - options.onTimeOut = function () { - var error = "Reception d'un Time out (json) !"; - console.log(error); - done(error); - }; - Gp.Services.isoCurve(options); - }) - }); - - describe("Test sur les options du Protocole", function (done) { - - var options; - - beforeEach(function () { - // options par defaut (à surcharger) - options = { - apiKey: myKey, - serverUrl: null, - protocol: 'JSONP', // à surcharger : JSONP|XHR - callbackSuffix: "", - - httpMethod: 'GET', // à surcharger : GET|POST - timeOut: 10000000000, - rawResponse: false, - onSuccess: null, // à surcharge - onFailure: null, // à surcharge - // spécifique au service - outputFormat: 'json', // à surcharger : json|xml - exclusions: ['Toll', 'Bridge', 'Tunnel'], - position: { - x: 2.3242664298058053, - y: 48.86118017324745 - }, - graph: "Voiture", - method: "time", - time: 200, - srs: "EPSG:4326", - reverse: false, - smoothing: false, - holes: false - }; - }); - - afterEach(function () { - - }); - - // fonction contenant les tests de la reponse - var functionAssert = function (response) { - console.log(response); - should().exist(response); - expect(response).to.be.an("Object"); - expect(response).to.have.property("location"); - expect(response.location).to.be.an("object"); - expect(response.location).to.have.property("x"); - expect(response.location).to.have.property("y"); - expect(response).to.have.property("geometry"); - expect(response).to.have.property("message"); - expect(response).to.have.property("srs"); - expect(response).to.have.property("time"); - }; - - xit("FIXME : Appel du service en mode 'JSONP'" + - " pour un format de sortie en 'xml'", function (done) { - // FIXME le service ne renvoie pas la bonne reponse (XML dans un callback) !? - // description du test - // requête GET du service en xml - // la reponse du service de production en JSONP est un xml encapsulé dans JSON avec un callback - // var urlGet = "http://wxs.ign.fr/jhyvi0fgmnuxvfv0zjzorvdn/isochrone/isochrone.xml?output=json&location=2.3242664298058053,48.86118017324745&smoothing=false&holes=false&reverse=false&method=time&time=200&graphName=Voiture&exclusions=Toll;Bridge;Tunnel&srs=EPSG:4326&callback=callback"; - // var okResponse =[200, { 'Content-type': 'application/javascript' }, 'callback({{"http":{"status":200,"error":null},"xml":""}})']; - - if (mock) { options.serverUrl = 'test/end-to-end/spec-functional/fixtures/jsonp/callback-iso-xml'; } - options.outputFormat = 'xml'; - options.onSuccess = function (response) { - functionAssert(response); - done(); - }; - options.onFailure = function (error) { - console.log(error); - done(error); - }; - options.onTimeOut = function () { - var error = "Reception d'un Time out (isoCurve) !"; - console.log(error); - done(error); - }; - - Gp.Services.isoCurve(options); - }); - - it("Appel du service en mode 'JSONP'" + - " pour un format de sortie en 'json'", function (done) { - // description du test - // requête GET du service en json - // la reponse du service de production en JSONP est un json avec un callback - // var urlGet = "http://wxs.ign.fr/jhyvi0fgmnuxvfv0zjzorvdn/isochrone/isochrone.json?location=2.3242664298058053,48.86118017324745&smoothing=false&holes=false&reverse=false&method=time&time=200&graphName=Voiture&exclusions=Toll;Bridge;Tunnel&srs=EPSG:4326&callback=callback"; - // var okResponse =[200, { 'Content-type': 'application/javascript' }, 'callback({})']; - - if (mock) { options.serverUrl = 'test/end-to-end/spec-functional/fixtures/jsonp/callback-iso-json'; } - options.outputFormat = 'json'; - options.onSuccess = function (response) { - functionAssert(response); - done(); - }; - options.onFailure = function (error) { - console.log(error); - done(error); - }; - options.onTimeOut = function () { - var error = "Reception d'un Time out (isoCurve) !"; - console.log(error); - done(error); - }; - - Gp.Services.isoCurve(options); - }); - }); - }); -}); diff --git a/test/end-to-end/spec-functional/test_processisocurve.js b/test/end-to-end/spec-functional/test_processisocurve.js index 4a608caa..2c40b462 100644 --- a/test/end-to-end/spec-functional/test_processisocurve.js +++ b/test/end-to-end/spec-functional/test_processisocurve.js @@ -7,7 +7,6 @@ import Gp from "../../../dist/GpServices-src.js"; import Logger from "../../../src/Utils/LoggerByDefault"; import sinon from "sinon"; -import { assert } from "chai"; import { expect } from "chai"; import { should } from "chai"; should(); @@ -17,18 +16,10 @@ var mock = __MOCK__; var logger = Logger.getLogger("test-isocurve"); -// xml load... -var processisocurveResponseXml, -processisocurveResponseJson; +var processisocurveResponseJson; if (mock) { - fetch('test/end-to-end/spec-functional/fixtures/processisocurve-response.xml') - .then(response => response.text()) - .then((data) => { - logger.warn(data); - processisocurveResponseXml = data; - }); fetch('test/end-to-end/spec-functional/fixtures/processisocurve-response.json') .then(response => response.text()) .then((data) => { @@ -71,7 +62,7 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc // options par defaut (à surcharger) var options = { apiKey: myKey, - serverUrl: null, + serverUrl: "https://itineraire.ign.fr/simple/1.0.0/isochrone", protocol: 'XHR', // à surcharger : JSONP|XHR httpMethod: 'GET', // à surcharger : GET|POST @@ -122,29 +113,6 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc if (mock) { server.respond(); } }); - it("Appel du service en mode 'XHR' avec la méthode 'GET' au format de sortie 'xml'", function (done) { - // description du test - // - var urlXGet = "http://wxs.ign.fr/" + myKey + "/isochrone/isochrone.xml?gp-access-lib=" + version + "&location=2.3242664298058053,48.86118017324745&smoothing=false&holes=false&reverse=false&method=time&time=200&graphName=Voiture&exclusions=Toll;Bridge;Tunnel&srs=EPSG:4326"; - var okResponseXml = [200, { 'Content-type': 'application/xml' }, processisocurveResponseXml]; - if (mock) { server.respondWith('GET', urlXGet, okResponseXml); } - - options.protocol = 'XHR'; - options.httpMethod = 'GET'; - options.outputFormat = 'xml'; - options.onSuccess = function (response) { - functionAssert(response); - done(); - }; - options.onFailure = function (error) { - console.log(error); - done(error); - }; - - Gp.Services.isoCurve(options); - if (mock) { server.respond(); } - }); - it("Appel du service en mode 'XHR' avec la méthode 'POST' au format de sortie 'json'", function (done) { // description du test // @@ -168,28 +136,6 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc if (mock) { server.respond(); } }); - it("Appel du service en mode 'XHR' avec la méthode 'POST' au format de sortie 'xml'", function (done) { - // description du test - // - var urlXPost = "http://wxs.ign.fr/" + myKey + "/isochrone/isochrone.xml?gp-access-lib=" + version; - var okResponseXml = [200, { 'Content-type': 'application/xml' }, processisocurveResponseXml]; - if (mock) { server.respondWith('POST', urlXPost, okResponseXml); } - - options.protocol = 'XHR'; - options.httpMethod = 'POST'; - options.outputFormat = 'xml'; - options.onSuccess = function (response) { - functionAssert(response); - done(); - }; - options.onFailure = function (error) { - console.log(error); - done(error); - }; - - Gp.Services.isoCurve(options); - if (mock) { server.respond(); } - }); }); describe("Test sur les options spécifiques du service", function () { diff --git a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js index e9940efb..9b8c4655 100644 --- a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js +++ b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js @@ -1,7 +1,5 @@ import Gp from "../../../dist/GpServices-src.js"; -import sinon from "sinon"; -import { assert } from "chai"; import { expect } from "chai"; import { should } from "chai"; should(); @@ -19,7 +17,7 @@ describe("-- Test sur les messages d'erreur spécifiques du Service de calcul d' // options par defaut du geocodage direct options = { apiKey : 'jhyvi0fgmnuxvfv0zjzorvdn', - serverUrl : null, + serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", protocol : 'JSONP', // proxyURL : (window.proxy) ? 'spec-messages/proxy/php/proxy.php?url=' : null, // ex. 'spec-messages/proxy/php/proxy.php?url=' httpMethod : 'GET', diff --git a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve_JSONP.js b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve_JSONP.js deleted file mode 100644 index 4c75568e..00000000 --- a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve_JSONP.js +++ /dev/null @@ -1,139 +0,0 @@ -// FIXME service très instable, souvent en 500 Internal Server Error -import Gp from "../../../dist/GpServices-src.js"; - -import sinon from "sinon"; -import { assert } from "chai"; -import { expect } from "chai"; -import { should } from "chai"; -should(); - -// pass this option from webpack -var mock = __MOCK__; - -describe("-- Test sur les messages d'erreur spécifiques du Service de calcul d'iso : JSONP --", function() { - - var myKey = (mock) ? "CLE" : "jhyvi0fgmnuxvfv0zjzorvdn"; - var Services = null; - var options = {}; - - beforeEach(function() { - - // options par defaut du geocodage direct - options = { - apiKey : myKey, - serverUrl : null, - protocol : 'JSONP', - callbackSuffix : "", - httpMethod : 'GET', - timeOut : 10000, - rawResponse : false, - onSuccess : function (response) { console.log('onSuccess() :', response); }, - onFailure : function (error) {console.log("onFailure() : ", error.message, error.type, error.status);}, - // spécifique au service - position : { - x: 2.3242664298058053, - y: 48.86118017324745 - }, - outputFormat : 'json', - exclusions : ['Bridge', 'Tunnel'], - graph : "Voiture", - method : 'distance', - distance : 200, //time : 200 - reverse : false, - smoothing : false, - holes : false, - srs : 'EPSG:4326' - }; - - }); - - it("[FIXME] Erreur de clef API : clef inconnue du service", function (done) { - // Exception de type ErrorService - // Levée par le protocole (XHR) - // Renvoyer pour le callback onFailure() - // Message : Errors Occured on Http Request (status : 'Forbidden (...) - // Type : SERVICE_ERROR - // Status : 403 - if (mock) { - options.serverUrl = 'test/end-to-end/spec-messages/fixtures/jsonp/callback-bad-key'; - } else { - this.skip(); - } - options.apiKey = "bidon"; - options.onFailure = function (e) { - console.log(e.message); - expect(e).not.to.be.null; - expect(e.message).to.contain("Key does not exist or has expired"); // Key does not exist or has expired - expect(e.type).to.be.equal("SERVICE_ERROR"); - expect(e.status).to.be.equal(403); - done(); - }; - options.onSuccess = function (response) { - expect(false).to.be.true; - done(response); - }; - - Gp.Services.isoCurve(options); - }); - - it("[FIXME] Erreur sur les exclusions : valeur inconnue", function (done) { - // Exception de type ErrorService - // Levée par XHR() - // Renvoyer pour le callback onFailure() - // Message : (...) ServiceException (...) - // Type : ERROR_UNKNOWN - // Status : -1 - // ex. de message du service : - // {"message":"ServiceException: Error in route computation\nError in smartrouting\nFailed to execute calculateRoute\nunknown reject flag 'BIDON'","status":"ERROR"} - - if (mock) { - options.serverUrl = 'test/end-to-end/spec-messages/fixtures/jsonp/callback-iso-bad-exclusions'; - } else { - this.skip(); - } - options.exclusions = ['BIDON']; - options.onFailure = function (e) { - console.log(e); - expect(e).not.to.be.null; - expect(e.message).to.contain("ServiceException"); - expect(e.type).to.be.equal("UNKNOWN_ERROR"); - expect(e.status).to.be.equal(-1); - done(); - }; - options.onSuccess = function (response) { - done(response); - }; - - Gp.Services.isoCurve(options); - }); - - it("[FIXME] Erreur sur le graphe : valeur inconnue", function (done) { - // Exception de type ErrorService - // Levée par XHR() - // Renvoyer pour le callback onFailure() - // Message : (...) ServiceException (...) - // Type : ERROR_UNKNOWN - // Status : -1 - // ex. de message du service : - // {"message":"ServiceException: Error in route computation\nError in smartrouting\nFailed to execute calculateRoute\nunknown reject flag 'BIDON'","status":"ERROR"} - if (mock) { - options.serverUrl = 'test/end-to-end/spec-messages/fixtures/jsonp/callback-iso-bad-graph'; - } else { - this.skip(); - } - options.graph = 'BIDON'; - options.onFailure = function (e) { - console.log(e); - expect(e).not.to.be.null; - expect(e.message).to.contain("ServiceException"); - expect(e.type).to.be.equal("UNKNOWN_ERROR"); - expect(e.status).to.be.equal(-1); - done(); - }; - options.onSuccess = function (response) { - done(response); - }; - - Gp.Services.isoCurve(options); - }); -}); diff --git a/test/spec/test_Services_DefaultUrlServices.js b/test/spec/test_Services_DefaultUrlServices.js index 36adb754..ae12139d 100644 --- a/test/spec/test_Services_DefaultUrlServices.js +++ b/test/spec/test_Services_DefaultUrlServices.js @@ -23,8 +23,7 @@ describe("-- Test DefaultUrlService --", function () { expect(DefaultUrlService.Alti.url(key)["profil-json"]).to.be.equal("https://wxs.ign.fr/CLE/alti/rest/elevationLine.json"); expect(DefaultUrlService.Alti.url(key)["profil-xml"]).to.be.equal("https://wxs.ign.fr/CLE/alti/rest/elevationLine.xml"); expect(DefaultUrlService.Alti.url(key)["wps"]).to.be.equal("https://wxs.ign.fr/CLE/alti/wps"); - expect(DefaultUrlService.ProcessIsoCurve.url(key)["iso-json"]).to.be.equal("https://wxs.ign.fr/CLE/isochrone/isochrone.json"); - expect(DefaultUrlService.ProcessIsoCurve.url(key)["iso-xml"]).to.be.equal("https://wxs.ign.fr/CLE/isochrone/isochrone.xml"); + expect(DefaultUrlService.ProcessIsoCurve.url(key)).to.be.equal("https://wxs.ign.fr/CLE/simple/1.0.0/isochrone"); expect(DefaultUrlService.AutoComplete.url(key)).to.be.equal("https://wxs.ign.fr/CLE/ols/apis/completion" ); expect(DefaultUrlService.ReverseGeocode.url(key)).to.be.equal("https://wxs.ign.fr/CLE/geoportail/ols"); expect(DefaultUrlService.AutoConf.url(key)["apiKey"]).to.be.equal("https://wxs.ign.fr/CLE/autoconf"); diff --git a/test/spec/test_Services_ProcessIsoCurveRequest.js b/test/spec/test_Services_ProcessIsoCurveRequest.js index 2ec54fa1..6950e901 100644 --- a/test/spec/test_Services_ProcessIsoCurveRequest.js +++ b/test/spec/test_Services_ProcessIsoCurveRequest.js @@ -1,12 +1,10 @@ /* * Tests de la construction d"une requête de calcul d"isochrones, par la classe ProcessIsoCurveRequest. */ -import { assert } from "chai"; import { expect } from "chai"; import { should } from "chai"; should(); -import XML from "../../src/Formats/XML"; import ProcessIsoCurveRequest from "../../src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest"; describe("-- Test ProcessIsoCurveRequest --", function () { @@ -17,18 +15,19 @@ describe("-- Test ProcessIsoCurveRequest --", function () { var options = { httpMethod : "GET", // GET|POST // spécifique au service - exclusions : ["Bridge", "Tunnel"], + resource: "bduni-idf-osrm", position : { x : 2.3242664298058053, y : 48.86118017324745 }, - graph : "Voiture", + graph : "car", method : "time", - time : 1000, // distance : 200 + time : 1000, reverse : false, - smoothing : false, - holes : false, - srs : "EPSG:4326" + srs : "EPSG:4326", + timeUnit:"standard", + distanceUnit: "km", + constraints: {constraintType:'banned',key:'ways_type',operator:'=',value:'autoroute'} }; try { @@ -40,8 +39,8 @@ describe("-- Test ProcessIsoCurveRequest --", function () { var request = oIsoCurve.requestString; expect(request).not.to.be.null; - - // location=2.3242664298058053,48.86118017324745&smoothing=false&holes=false&reverse=false&method=time&time=1000&graphName=Voiture&exclusions=Bridge;Tunnel&srs=EPSG:4326 + console.log(request); + // point=2.3242664298058053,48.86118017324745&direction=departure&costType=time&costValue=1000&profile=car&constraints=...&crs=EPSG:4326 var values = request.split(/&/); var map = {}; for (var i = 0; i < values.length; i++) { @@ -49,15 +48,14 @@ describe("-- Test ProcessIsoCurveRequest --", function () { map[val[0]] = val[1]; } - expect(map).to.have.property("location"); - expect(map).to.have.property("smoothing"); - expect(map).to.have.property("holes"); - expect(map).to.have.property("reverse"); - expect(map).to.have.property("method"); - expect(map).to.have.property("time"); - expect(map).to.have.property("graphName"); - expect(map).to.have.property("exclusions"); - expect(map).to.have.property("srs"); + expect(map).to.have.property("resource"); + expect(map).to.have.property("point"); + expect(map).to.have.property("direction"); + expect(map).to.have.property("costValue"); + expect(map).to.have.property("costType"); + expect(map).to.have.property("profile"); + expect(map).to.have.property("constraints"); + expect(map).to.have.property("crs"); } catch (e) { console.log(e); @@ -71,40 +69,35 @@ describe("-- Test ProcessIsoCurveRequest --", function () { var options = { httpMethod : "POST", // GET|POST // spécifique au service - exclusions : ["Bridge", "Tunnel"], + resource: "bduni-idf-osrm", position : { x : 2.3242664298058053, y : 48.86118017324745 }, - graph : "Pieton", + graph : "pedestrian", method : "distance", distance : 200, reverse : true, - smoothing : true, - holes : true, - srs : "EPSG:4326" + srs : "EPSG:4326", + timeUnit:"standard", + distanceUnit: "km", + constraints: {constraintType:'banned',key:'ways_type',operator:'=',value:'autoroute'} }; /** validation */ var valide = function (result) { - var p = new XML(); - p.setXMLString(result); - var data = p.parse(); - should().exist(data); - // console.log(data); - - var req = data["isochroneRequest"]; - expect(req).to.have.property("distance"); - expect(req).to.have.property("exclusions"); - expect(req).to.have.property("graphName"); - expect(req).to.have.property("holes"); - expect(req).to.have.property("location"); - expect(req["location"]).to.have.property("x"); - expect(req["location"]).to.have.property("y"); - expect(req).to.have.property("method"); - expect(req).to.have.property("reverse"); - expect(req).to.have.property("smoothing"); - expect(req).to.have.property("srs"); + var req = JSON.parse(result); + should().exist(req); + // console.log(req); + + expect(req).to.have.property("resource"); + expect(req).to.have.property("constraints"); + expect(req).to.have.property("profile"); + expect(req).to.have.property("point"); + expect(req).to.have.property("costType"); + expect(req).to.have.property("costValue"); + expect(req).to.have.property("direction"); + expect(req).to.have.property("crs"); }; diff --git a/test/spec/test_Services_ProcessIsoCurveResponse.js b/test/spec/test_Services_ProcessIsoCurveResponse.js index 611939ec..b7938ae3 100644 --- a/test/spec/test_Services_ProcessIsoCurveResponse.js +++ b/test/spec/test_Services_ProcessIsoCurveResponse.js @@ -1,7 +1,6 @@ /* * Tests sur les propriétés de la classe de réponse de calcul d'isochrones (ProcessIsoCurveResponse). */ -import { assert } from "chai"; import { expect } from "chai"; import { should } from "chai"; should(); From 0e4bb042cd0d7de04c22126259bdaf2f723ea270 Mon Sep 17 00:00:00 2001 From: lgrd Date: Wed, 27 May 2020 16:31:55 +0200 Subject: [PATCH 03/14] feat(isochrone): gestion des erreurs pour outputFormat, maj des tests et samples --- .../pages-isochrone-bundle-default.html | 2 + .../pages-isodistance-bundle-default.html | 2 + .../pages/ProcessIsoCurve/pages-jsfiddle.html | 1 + .../ProcessIsoCurve/ProcessIsoCurve.js | 2 +- .../ProcessIsoCurveResponseFactory.js | 50 ++++++++----------- .../spec-functional/test_processisocurve.js | 4 +- .../test_Services_ProcessIsoCurve.js | 2 +- 7 files changed, 29 insertions(+), 34 deletions(-) diff --git a/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html b/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html index 73209bc4..a55872d5 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html +++ b/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html @@ -15,6 +15,7 @@

Avec les paramètres obligatoires seulement

var options = { apiKey : "{{ apikey }}", + serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", onSuccess : function (response) { print(response); }, @@ -32,6 +33,7 @@

Avec les paramètres obligatoires seulement

{{#content "js"}} var options = { apiKey : "{{ apikey }}", + serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", onSuccess : function (response) { print(response); }, diff --git a/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html b/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html index 99aaa3ca..ece9e52f 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html +++ b/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html @@ -15,6 +15,7 @@

Avec les paramètres obligatoires seulement

var options = { apiKey : "{{ apikey }}", + serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", onSuccess : function (response) { print(response); }, @@ -32,6 +33,7 @@

Avec les paramètres obligatoires seulement

{{#content "js"}} var options = { apiKey : "{{ apikey }}", + serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", onSuccess : function (response) { print(response); }, diff --git a/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html b/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html index 7de3cc4d..01063f56 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html +++ b/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html @@ -94,6 +94,7 @@

Utilisation de Gp.Services.isoCurve() avec modulation des paramètres " }, diff --git a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js index 75b80e49..3a25d7b3 100644 --- a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js +++ b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js @@ -241,7 +241,7 @@ function ProcessIsoCurve (options) { // on passe l'option outputFormat en minuscules afin d'éviter des exceptions. this.options.outputFormat = (typeof options.outputFormat === "string") ? options.outputFormat.toLowerCase() : "json"; if (options.outputFormat && options.outputFormat !== "json") { - this.logger.warn("options.outputFormat could only be json"); + throw new Error(_.getMessage("PARAM_NOT_SUPPORT", "outputFormat")); } this.options.outputFormat = "json"; diff --git a/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js b/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js index 4e1dc0f9..b16932dd 100644 --- a/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js +++ b/src/Services/ProcessIsoCurve/Response/ProcessIsoCurveResponseFactory.js @@ -54,38 +54,30 @@ var ProcessIsoCurveResponseFactory = { } // analyse de la reponse - if (JSONResponse.status === "OK" || JSONResponse.status === "ok") { - // création de l'objet de réponse - data = new ProcessIsoCurveResponse(); + // création de l'objet de réponse + data = new ProcessIsoCurveResponse(); - // remplissage de l'objet créé avec les attribtuts de la réponse du service - if (data) { - if (data.costValue === "distance") { - data.time = ""; - data.distance = JSONResponse.distance; - } else { - data.time = JSONResponse.time; - data.distance = ""; - } - - data.message = ""; - data.id = ""; - data.srs = JSONResponse.crs; - data.geometry = JSONResponse.geometry; - var coords = JSONResponse.point.split(","); - if (data.location) { - data.location.x = coords[0]; - data.location.y = coords[1]; - } + // remplissage de l'objet créé avec les attribtuts de la réponse du service + if (data) { + if (data.costValue === "distance") { + data.time = ""; + data.distance = JSONResponse.distance; } else { - options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_ANALYSE", options.response))); - return; + data.time = JSONResponse.time; + data.distance = ""; } - } else if (JSONResponse.status === "ERROR" || JSONResponse.status === "error") { - // JSHint bug if var message is used !? - var mess = JSONResponse.message; - mess += "\n (raw response service : '" + JSONResponse + "')"; - options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_EXCEPTION", mess))); + + data.message = ""; + data.id = ""; + data.srs = JSONResponse.crs; + data.geometry = JSONResponse.geometry; + var coords = JSONResponse.point.split(","); + if (data.location) { + data.location.x = coords[0]; + data.location.y = coords[1]; + } + } else { + options.onError.call(options.scope, new ErrorService(MRes.getMessage("SERVICE_RESPONSE_ANALYSE", options.response))); return; } diff --git a/test/end-to-end/spec-functional/test_processisocurve.js b/test/end-to-end/spec-functional/test_processisocurve.js index 2c40b462..3153e6d3 100644 --- a/test/end-to-end/spec-functional/test_processisocurve.js +++ b/test/end-to-end/spec-functional/test_processisocurve.js @@ -85,9 +85,7 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc method: "time", time: 200, srs: "EPSG:4326", - reverse: false, - smoothing: false, - holes: false + reverse: false }; it("Appel du service en mode 'XHR' avec la méthode 'GET' au format de sortie 'json'", function (done) { diff --git a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js index 9b8c4655..74c13410 100644 --- a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js +++ b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js @@ -146,7 +146,7 @@ describe("-- Test sur les messages d'erreur spécifiques du Service de calcul d' } catch (e) { console.log(e.message); expect(e).not.to.be.null; - expect(e.message).to.be.equal("Url by default not found !"); + expect(e.message).to.be.equal("Value(s) for parameter(s) 'outputFormat' not supported"); } finally {} }); From a76354551e1655f8e343bba52f48d55be0941ca9 Mon Sep 17 00:00:00 2001 From: lgrd Date: Wed, 10 Jun 2020 16:19:41 +0200 Subject: [PATCH 04/14] fix(test): ajouter du contentType pour un test --- test/end-to-end/spec-functional/test_processisocurve.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/end-to-end/spec-functional/test_processisocurve.js b/test/end-to-end/spec-functional/test_processisocurve.js index 3153e6d3..962c6123 100644 --- a/test/end-to-end/spec-functional/test_processisocurve.js +++ b/test/end-to-end/spec-functional/test_processisocurve.js @@ -120,6 +120,7 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc options.protocol = 'XHR'; options.httpMethod = 'POST'; + options.contentType = 'application/json', options.outputFormat = 'json'; options.onSuccess = function (response) { functionAssert(response); From 8268ced58639a09d4430f83c29c368d3ccbd090a Mon Sep 17 00:00:00 2001 From: "amaury.zarzelli" Date: Tue, 30 Nov 2021 10:52:23 +0100 Subject: [PATCH 05/14] Please enable auto-trim for trailing whitespaces --- .../ProcessIsoCurve/ProcessIsoCurve.js | 22 +++++++++---------- .../Request/ProcessIsoCurveRequest.js | 4 ++-- .../Request/model/ProcessIsoCurveParam.js | 8 +++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js index 3a25d7b3..7aa35ba3 100644 --- a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js +++ b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js @@ -6,7 +6,6 @@ import CommonService from "../CommonService"; import DefaultUrlService from "../DefaultUrlService"; import ProcessIsoCurveRequest from "./Request/ProcessIsoCurveRequest"; import ProcessIsoCurveResponseFactory from "./Response/ProcessIsoCurveResponseFactory"; -import TileMatrixSet from "../AutoConf/Response/model/TileMatrixSet"; /** * @classdesc @@ -18,7 +17,7 @@ import TileMatrixSet from "../AutoConf/Response/model/TileMatrixSet"; * @extends {Gp.Services.CommonService} * @alias Gp.Services.ProcessIsoCurve * @param {Object} options - options spécifiques au service (+ les options heritées) - * + * * @param {String} options.resource - La ressource utilisée pour le calcul. Ce paramètre devrait être obligatoire car il l'est dans l'appel au service. Mais il ne l'est pas pour des raisons de rétrocompatibilité. * * @param {String} options.outputFormat - Le format de la réponse du service iso : 'json' uniquement et par défaut. @@ -46,15 +45,15 @@ import TileMatrixSet from "../AutoConf/Response/model/TileMatrixSet"; * @param {String} [options.constraints.key] - Clé de la contrainte. Généralement "wayType". * @param {String} [options.constraints.operator] - Opérateur de la contrainte. Généralement "=". * @param {String} [options.constraints.value] - Valeur de la contrainte. Généralement "autoroute". - * + * * @param {String} [options.method = "time"] - Méthode utilisée pour le calcul de la courbe iso. * Les valeurs possible sont "time" pour un calcul d'isochrone, "distance" pour un calcul d'isodistance. * Pas de valeur spécifié équivaut à un calcul d'isochrone. - * + * * @param {String} [options.distanceUnit = "km"] - Indique si la distance doit être exprimée en km ou m dans la réponse ("m" or "km"). - * + * * @param {String} [options.timeUnit = "standard"] - Indique si la durée doit être exprimée en seconde, minute ou heure dans la réponse ("standard", "second", "minute", "hour"). Il peut-être formatté hh:mm::ss avec la valeur standard. - * + * * @param {Float} options.time - Durée maximum (exprimée en secondes) à utiliser pour le calcul de la courbe à partir du ou jusqu'au point « location ». * Ce paramètre doit être renseigné si l'option "méthod" a la valeur "time". * Si l'option method n'est pas renseignée, ce paramètre doit être renseigné. @@ -165,14 +164,14 @@ function ProcessIsoCurve (options) { this.options.distanceUnit = options.distanceUnit || "km"; this.options.timeUnit = options.timeUnit || "standard"; - //options depreciees + // options depreciees if (options.smoothing) { this.logger.warn("options.smoothing is DEPRECATED"); - } + } this.options.smoothing = false; if (options.holes) { this.logger.warn("options.holes is DEPRECATED"); - } + } this.options.holes = false; // Gestion du graphe @@ -187,7 +186,7 @@ function ProcessIsoCurve (options) { this.options.graph = "car"; } - // Gestions des contraintes + // Gestions des contraintes this.options.constraints = []; if (options.constraints) { if (Array.isArray(options.constraints)) { @@ -206,7 +205,7 @@ function ProcessIsoCurve (options) { if (options.exclusions) { if (options.exclusions.length !== 0) { this.logger.warn("options.exclusions is DEPRECATED !!"); - for(var c = 0; c < options.exclusions.length; c++) { + for (var c = 0; c < options.exclusions.length; c++) { if (typeof options.exclusions[c] === "string") { options.exclusions[c] = options.exclusions[c].toLowerCase(); } else { @@ -255,7 +254,6 @@ function ProcessIsoCurve (options) { this.options.serverUrl = urlFound; this.logger.trace("Serveur URL par defaut : " + this.options.serverUrl); } - } /** diff --git a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js index ddef74dd..b353be51 100644 --- a/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js +++ b/src/Services/ProcessIsoCurve/Request/ProcessIsoCurveRequest.js @@ -93,7 +93,7 @@ ProcessIsoCurveRequest.prototype = { * // (http://wxs.ign.fr/KEY/isochrone?) * // resource=& * // point=& - * // costValue=& + * // costValue=& * // costType=& * // profile=& * // constraints=& @@ -155,7 +155,7 @@ ProcessIsoCurveRequest.prototype = { postRequest.costType = "time"; postRequest.costValue = this.settings.time; } - + postRequest.profile = this.settings.graph; if (this.settings.reverse) { diff --git a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js index a3719a4a..e358018d 100644 --- a/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js +++ b/src/Services/ProcessIsoCurve/Request/model/ProcessIsoCurveParam.js @@ -31,7 +31,7 @@ function ProcessIsoCurveParam (options) { /** Identifiant de l’isochrone */ this.id = this.options.id; - /** Resource */ + /** Resource */ this.resource = this.options.resource; /** Coordonnées de départ (ou arrivée si le reverse est à true). */ @@ -94,7 +94,7 @@ ProcessIsoCurveParam.prototype = { /** * Retourne l'unité de la distance - * @returns {String} + * @returns {String} */ getDistanceUnit : function () { if (this.distanceUnit === "m") { @@ -108,7 +108,7 @@ ProcessIsoCurveParam.prototype = { /** * Retourne la liste des contraintes - * @returns {String} + * @returns {String} */ getConstraints : function () { var constraintArray = []; @@ -123,7 +123,7 @@ ProcessIsoCurveParam.prototype = { /** * Retourne la direction - * @returns {String} + * @returns {String} */ getDirection : function () { if (this.reverse) { From b732ec288b03a88df5a4b738532a892c41d99fde Mon Sep 17 00:00:00 2001 From: "amaury.zarzelli" Date: Fri, 3 Dec 2021 10:18:51 +0100 Subject: [PATCH 06/14] update URLs --- .../pages/ProcessIsoCurve/pages-isochrone-bundle-default.html | 4 ++-- .../ProcessIsoCurve/pages-isodistance-bundle-default.html | 4 ++-- samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html | 2 +- src/Services/DefaultUrlService.js | 2 +- src/Services/ProcessIsoCurve/ProcessIsoCurve.js | 2 +- test/end-to-end/spec-functional/test_processisocurve.js | 2 +- .../end-to-end/spec-messages/test_Services_ProcessIsoCurve.js | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html b/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html index a55872d5..bae52f13 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html +++ b/samples-src/pages/ProcessIsoCurve/pages-isochrone-bundle-default.html @@ -15,7 +15,7 @@

Avec les paramètres obligatoires seulement

var options = { apiKey : "{{ apikey }}", - serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl : "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", onSuccess : function (response) { print(response); }, @@ -33,7 +33,7 @@

Avec les paramètres obligatoires seulement

{{#content "js"}} var options = { apiKey : "{{ apikey }}", - serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl : "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", onSuccess : function (response) { print(response); }, diff --git a/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html b/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html index ece9e52f..ace4057b 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html +++ b/samples-src/pages/ProcessIsoCurve/pages-isodistance-bundle-default.html @@ -15,7 +15,7 @@

Avec les paramètres obligatoires seulement

var options = { apiKey : "{{ apikey }}", - serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl : "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", onSuccess : function (response) { print(response); }, @@ -33,7 +33,7 @@

Avec les paramètres obligatoires seulement

{{#content "js"}} var options = { apiKey : "{{ apikey }}", - serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl : "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", onSuccess : function (response) { print(response); }, diff --git a/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html b/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html index 01063f56..b728da97 100644 --- a/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html +++ b/samples-src/pages/ProcessIsoCurve/pages-jsfiddle.html @@ -94,7 +94,7 @@

Utilisation de Gp.Services.isoCurve() avec modulation des paramètres " }, diff --git a/src/Services/DefaultUrlService.js b/src/Services/DefaultUrlService.js index a83b26a1..badedc0a 100644 --- a/src/Services/DefaultUrlService.js +++ b/src/Services/DefaultUrlService.js @@ -108,7 +108,7 @@ var DefaultUrlService = { * @property {Function} url (key) - Returns isocurve service default urls with or without geoportal access key given as a parameter. The result is a javascript object with different urls given used protocols ("iso-json" or "iso-xml"). */ ProcessIsoCurve : { - _key : "/simple/1.0.0/isochrone", + _key : "/geoportail/isochrone/rest/1.0.0/isochrone", /** * url * @param {String} key - key diff --git a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js index 7aa35ba3..6582d8fd 100644 --- a/src/Services/ProcessIsoCurve/ProcessIsoCurve.js +++ b/src/Services/ProcessIsoCurve/ProcessIsoCurve.js @@ -157,7 +157,7 @@ function ProcessIsoCurve (options) { // options par defaut du service // TODO: modifier la ressource lors de la mise en production du service - this.options.resource = options.resource || "bduni-idf-pgr"; + this.options.resource = options.resource || "bdtopo-iso"; this.options.exclusions = options.exclusions || []; this.options.reverse = options.reverse || false; this.options.srs = options.srs || "EPSG:4326"; diff --git a/test/end-to-end/spec-functional/test_processisocurve.js b/test/end-to-end/spec-functional/test_processisocurve.js index 962c6123..74496b06 100644 --- a/test/end-to-end/spec-functional/test_processisocurve.js +++ b/test/end-to-end/spec-functional/test_processisocurve.js @@ -62,7 +62,7 @@ describe("-- Tests fonctionnels du Service de Calcul d’isochrones / isodistanc // options par defaut (à surcharger) var options = { apiKey: myKey, - serverUrl: "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl: "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", protocol: 'XHR', // à surcharger : JSONP|XHR httpMethod: 'GET', // à surcharger : GET|POST diff --git a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js index 74c13410..9b8831de 100644 --- a/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js +++ b/test/end-to-end/spec-messages/test_Services_ProcessIsoCurve.js @@ -17,7 +17,7 @@ describe("-- Test sur les messages d'erreur spécifiques du Service de calcul d' // options par defaut du geocodage direct options = { apiKey : 'jhyvi0fgmnuxvfv0zjzorvdn', - serverUrl : "https://itineraire.ign.fr/simple/1.0.0/isochrone", + serverUrl : "https://wxs.ign.fr/calcul/geoportail/isochrone/rest/1.0.0/isochrone", protocol : 'JSONP', // proxyURL : (window.proxy) ? 'spec-messages/proxy/php/proxy.php?url=' : null, // ex. 'spec-messages/proxy/php/proxy.php?url=' httpMethod : 'GET', From 7ef9b703651b27f8211b46a06dd70130601e649a Mon Sep 17 00:00:00 2001 From: elias couppe Date: Mon, 31 Jan 2022 11:17:48 +0100 Subject: [PATCH 07/14] fix(doc): coquille GpServices path dans tutorial getConfig --- DRAFT_CHANGELOG.md | 9 +++------ doc/tutorials/optimize-getconfig-english.md | 2 +- doc/tutorials/optimize-getconfig.md | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/DRAFT_CHANGELOG.md b/DRAFT_CHANGELOG.md index 37e111ce..d0f5ce31 100644 --- a/DRAFT_CHANGELOG.md +++ b/DRAFT_CHANGELOG.md @@ -1,26 +1,23 @@ # Bibliothèque d'accès aux services Géoportail, version 3.0.6 -**25/01/2022 : 3.0.6** +**xx/xx/2022 : 3.0.x** > release of geoportal access library ## Summary -Mise à jour de la documentation pour utilisation de clefs génériques multiples - ## Changelog * [Added] * [Changed] - - refactorisation de la page de documentation pour récupérer l'autoconf en local (#78) - - mise à jour du readme et de la jsdoc (#79 et #80) - * [Removed] * [Fixed] + - fix coquille chemin vers GpServices dans le tutorial getconfig locale + * [Deprecated] * [Security] diff --git a/doc/tutorials/optimize-getconfig-english.md b/doc/tutorials/optimize-getconfig-english.md index 10f77ef9..8a875c84 100644 --- a/doc/tutorials/optimize-getconfig-english.md +++ b/doc/tutorials/optimize-getconfig-english.md @@ -31,7 +31,7 @@ Click the "Get Config File" button.

- + +