diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c1a85afb..decb5146b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: Build project ... +name: Build on: pull_request: diff --git a/.github/workflows/release-itowns.yml b/.github/workflows/release-itowns.yml index b1c5677b2..f6e59798e 100644 --- a/.github/workflows/release-itowns.yml +++ b/.github/workflows/release-itowns.yml @@ -251,8 +251,8 @@ jobs: - name: Reset draft changelog run: | sed -i -e '/# Extension Geoportail Itowns/{:a; N; /---/!ba; r .github/CHANGELOG_TEMPLATE.md' -e 'd;}' DRAFT_CHANGELOG.md - sed -e 's/__UP_LIBRARY__/Itowns/' DRAFT_CHANGELOG.md - sed -e 's/__LO_LIBRARY__/itowns/' DRAFT_CHANGELOG.md + sed -i '0,/__UP_LIBRARY__/s/__UP_LIBRARY__/Itowns/' DRAFT_CHANGELOG.md + sed -i '0,/__LO_LIBRARY__/s/__LO_LIBRARY__/itowns/' DRAFT_CHANGELOG.md - name: Archive changelog run: | diff --git a/.github/workflows/release-leaflet.yml b/.github/workflows/release-leaflet.yml index a3b664c3b..569a09a55 100644 --- a/.github/workflows/release-leaflet.yml +++ b/.github/workflows/release-leaflet.yml @@ -251,8 +251,8 @@ jobs: - name: Reset draft changelog run: | sed -i -e '/# Extension Geoportail Leaflet/{:a; N; /---/!ba; r .github/CHANGELOG_TEMPLATE.md' -e 'd;}' DRAFT_CHANGELOG.md - sed -e 's/__UP_LIBRARY__/Leaflet/' DRAFT_CHANGELOG.md - sed -e 's/__LO_LIBRARY__/leaflet/' DRAFT_CHANGELOG.md + sed -i '0,/__UP_LIBRARY__/s/__UP_LIBRARY__/Leaflet/' DRAFT_CHANGELOG.md + sed -i '0,/__LO_LIBRARY__/s/__LO_LIBRARY__/leaflet/' DRAFT_CHANGELOG.md - name: Archive changelog run: | diff --git a/.github/workflows/release-ol.yml b/.github/workflows/release-ol.yml index 91e8bb304..1369a9efb 100644 --- a/.github/workflows/release-ol.yml +++ b/.github/workflows/release-ol.yml @@ -252,9 +252,9 @@ jobs: # cf. http://fahdshariff.blogspot.com/2012/12/sed-mutli-line-replacement-between-two.html - name: Reset draft changelog run: | - sed -i -e '/# Extension Geoportail OpenLayers/{:a; N; /---/!ba; r .github/CHANGELOG_TEMPLATE.md' -e 'd;}' DRAFT_CHANGELOG.md - sed -e 's/__UP_LIBRARY__/OpenLayers/' DRAFT_CHANGELOG.md - sed -e 's/__LO_LIBRARY__/openlayers/' DRAFT_CHANGELOG.md + sed -i '/# Extension Geoportail OpenLayers/{:a; N; /---/!ba; r .github/CHANGELOG_TEMPLATE.md' -e 'd;}' DRAFT_CHANGELOG.md + sed -i '0,/__UP_LIBRARY__/s/__UP_LIBRARY__/OpenLayers/' DRAFT_CHANGELOG.md + sed -i '0,/__LO_LIBRARY__/s/__LO_LIBRARY__/openlayers/' DRAFT_CHANGELOG.md - name: Archive changelog run: | diff --git a/DRAFT_CHANGELOG.md b/DRAFT_CHANGELOG.md index 1bce0b682..e43303716 100644 --- a/DRAFT_CHANGELOG.md +++ b/DRAFT_CHANGELOG.md @@ -1,8 +1,8 @@ -# Extension Geoportail __UP_LIBRARY__, version __VERSION__ +# Extension Geoportail OpenLayers, version __VERSION__ **__DATE__** -> Release Extension Geoportail __LO_LIBRARY__ +> Release Extension Geoportail openLayers ## Summary @@ -12,21 +12,26 @@ * [Changed] + - mise à jour de la jsDoc (95cff8206ef2e0fcfb7fee5989d2d74d236b9f9f) + * [Deprecated] * [Removed] * [Fixed] + - corrections des erreurs à partir de DeepScan (#288) + - corrections syntaxiques eslint (da275a284a07ddd8e32753eda57ad4ef283d34fb et 306506a2255b2f05558ddcb05210dce39135c804) + * [Security] --- -# Extension Geoportail __UP_LIBRARY__, version __VERSION__ +# Extension Geoportail Leaflet, version __VERSION__ **__DATE__** -> Release Extension Geoportail __LO_LIBRARY__ +> Release Extension Geoportail leaflet ## Summary @@ -42,27 +47,29 @@ * [Fixed] + - corrections des erreurs à partir de DeepScan (#288) + - corrections syntaxiques eslint (da275a284a07ddd8e32753eda57ad4ef283d34fb et 306506a2255b2f05558ddcb05210dce39135c804) + * [Security] --- -# Extension Geoportail Leaflet, version __VERSION__ + +# Extension Geoportail Itowns, version __VERSION__ **__DATE__** -> Release Extension Geoportail Leaflet +> Release Extension Geoportail itowns ## Summary -Nouveau widget de profil altimétrique par défaut, et correctif mineur - ## Changelog * [Added] * [Changed] - - nouvel affichage du profil altimétrique par défaut (DISPLAY_PROFILE_BY_DEFAULT) + - mise à jour d'iTowns en version 2.30 (#292) * [Deprecated] @@ -70,7 +77,10 @@ Nouveau widget de profil altimétrique par défaut, et correctif mineur * [Fixed] - - correctif sur l'export de la version en mode module + - corrections des erreurs à partir de DeepScan (#288) + - corrections syntaxiques eslint (da275a284a07ddd8e32753eda57ad4ef283d34fb et 306506a2255b2f05558ddcb05210dce39135c804) + - correction de la synchronisation des couches vecteur tuilé avec leurs labels (#290) + * [Security] diff --git a/README.md b/README.md index c81fbd122..2d0777b33 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Extensions Géoportail -[![CeCILL License](https://img.shields.io/badge/licence-CeCILL--B-blue.svg)](https://raw.githubusercontent.com/IGNF/geoportal-extensions/master/LICENCE.md) [![Build Status](https://img.shields.io/travis/IGNF/geoportal-extensions/master.svg)](https://travis-ci.org/IGNF/geoportal-extensions) +[![Build](https://github.com/IGNF/geoportal-extensions/actions/workflows/build.yml/badge.svg)](https://github.com/IGNF/geoportal-extensions/actions/workflows/build.yml) +[![CeCILL License](https://img.shields.io/badge/licence-CeCILL--B-blue.svg)](https://raw.githubusercontent.com/IGNF/geoportal-extensions/master/LICENCE.md) +[![DeepScan grade](https://deepscan.io/api/teams/12425/projects/15469/branches/309621/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=12425&pid=15469&bid=309621) Ce projet a pour but de fournir des extensions facilitant l'accès aux ressources de la plateforme Géoportail pour les bibliothèques cartographiques Leaflet, OpenLayers (versions 3 et supérieures) et iTowns. diff --git a/build/scripts/release/geoportal-extensions-itowns-2.3.0.tgz b/build/scripts/release/geoportal-extensions-itowns-2.3.0.tgz deleted file mode 100644 index 00351bac3..000000000 Binary files a/build/scripts/release/geoportal-extensions-itowns-2.3.0.tgz and /dev/null differ diff --git a/build/scripts/release/geoportal-extensions-itowns-2.3.1.tgz b/build/scripts/release/geoportal-extensions-itowns-2.3.1.tgz new file mode 100644 index 000000000..86a331151 Binary files /dev/null and b/build/scripts/release/geoportal-extensions-itowns-2.3.1.tgz differ diff --git a/build/scripts/release/geoportal-extensions-openlayers-3.0.13.tgz b/build/scripts/release/geoportal-extensions-openlayers-3.0.13.tgz deleted file mode 100644 index 89b0bbc3f..000000000 Binary files a/build/scripts/release/geoportal-extensions-openlayers-3.0.13.tgz and /dev/null differ diff --git a/build/scripts/release/geoportal-extensions-openlayers-3.0.14.tgz b/build/scripts/release/geoportal-extensions-openlayers-3.0.14.tgz new file mode 100644 index 000000000..e7a7fc635 Binary files /dev/null and b/build/scripts/release/geoportal-extensions-openlayers-3.0.14.tgz differ diff --git a/build/scripts/release/package-itowns.json b/build/scripts/release/package-itowns.json index d63aef024..d8a84cc59 100644 --- a/build/scripts/release/package-itowns.json +++ b/build/scripts/release/package-itowns.json @@ -1,20 +1,6 @@ { - "main" : "dist/GpPluginItowns-src.js", - "scripts" : {}, - "module" : "src/Itowns/index.js", - "dependencies" : { - "proj4" : "2.6.2", - "itowns" : "2.27.0", - "xmldom" : "^0.1.27", - "geoportal-access-lib" : "2.1.6", - "request" : "^2.83.0", - "three" : "0.121.1", - "loglevel" : "1.6.6", - "sortablejs" : "1.8.4" - }, - "author" : "IGNF", - "homepage" : "https://geoservices.ign.fr/documentation/utilisation_web/extension-itowns.html", - "bugs" : {}, + "directories" : {}, + "name" : "geoportal-extensions-itowns", "files" : [ "dist/", "src/", @@ -22,15 +8,28 @@ "README.md", "package.json" ], - "license" : "CECILL-B", - "version" : "2.3.0", + "bugs" : {}, "repository" : { "url" : "https://github.com/IGNF/geoportal-extensions.git", "type" : "git" }, - "description" : "French Geoportal Extensions for iTowns", + "module" : "src/Itowns/index.js", + "dependencies" : { + "three" : "0.124.0", + "loglevel" : "1.6.6", + "sortablejs" : "1.8.4", + "itowns" : "2.30.0", + "geoportal-access-lib" : "2.1.6", + "xmldom" : "^0.1.27", + "request" : "^2.83.0", + "proj4" : "2.7.0" + }, + "date" : "12/02/2021", + "main" : "dist/GpPluginItowns-src.js", + "peerDependencies" : {}, + "scripts" : {}, "bundleDependencies" : [], - "directories" : {}, + "version" : "2.3.1", "keywords" : [ "geoportail", "plugin", @@ -38,7 +37,8 @@ "Itowns" ], "devDependencies" : {}, - "peerDependencies" : {}, - "date" : "09/12/2020", - "name" : "geoportal-extensions-itowns" + "description" : "French Geoportal Extensions for iTowns", + "author" : "IGNF", + "homepage" : "https://geoservices.ign.fr/documentation/utilisation_web/extension-itowns.html", + "license" : "CECILL-B" } diff --git a/build/scripts/release/package-openlayers.json b/build/scripts/release/package-openlayers.json index 48395e4a7..e11391813 100644 --- a/build/scripts/release/package-openlayers.json +++ b/build/scripts/release/package-openlayers.json @@ -1,38 +1,39 @@ { - "devDependencies" : {}, - "name" : "geoportal-extensions-openlayers", - "peerDependencies" : {}, - "module" : "src/OpenLayers/index.js", - "directories" : {}, - "description" : "French Geoportal Extensions for OpenLayers", - "version" : "3.0.13", + "dependencies" : { + "proj4" : "2.6.0", + "geoportal-access-lib" : "2.1.6", + "xmldom" : "^0.1.27", + "sortablejs" : "1.8.4", + "request" : "^2.83.0", + "ol" : "5.3.0", + "@mapbox/mapbox-gl-style-spec" : "13.11.0", + "loglevel" : "1.6.6", + "eventbusjs" : "0.2.0", + "ol-mapbox-style" : "4.2.1" + }, "keywords" : [ "geoportail", "plugin", "javascript", "OpenLayers" ], + "scripts" : {}, + "name" : "geoportal-extensions-openlayers", + "author" : "IGNF", + "bugs" : {}, + "description" : "French Geoportal Extensions for OpenLayers", + "homepage" : "https://geoservices.ign.fr/documentation/utilisation_web/extension-openlayers.html", + "date" : "12/02/2021", + "module" : "src/OpenLayers/index.js", "license" : "CECILL-B", + "main" : "dist/GpPluginOpenLayers-src.js", + "directories" : {}, "repository" : { "type" : "git", "url" : "https://github.com/IGNF/geoportal-extensions.git" }, - "dependencies" : { - "ol" : "5.3.0", - "sortablejs" : "1.8.4", - "@mapbox/mapbox-gl-style-spec" : "13.11.0", - "proj4" : "2.6.0", - "loglevel" : "1.6.6", - "xmldom" : "^0.1.27", - "eventbusjs" : "0.2.0", - "geoportal-access-lib" : "2.1.6", - "request" : "^2.83.0", - "ol-mapbox-style" : "4.2.1" - }, "bundleDependencies" : [], - "main" : "dist/GpPluginOpenLayers-src.js", - "scripts" : {}, - "bugs" : {}, + "peerDependencies" : {}, "files" : [ "dist/", "src/", @@ -40,7 +41,6 @@ "README.md", "package.json" ], - "homepage" : "https://geoservices.ign.fr/documentation/utilisation_web/extension-openlayers.html", - "author" : "IGNF", - "date" : "09/12/2020" + "devDependencies" : {}, + "version" : "3.0.14" } diff --git a/doc/CHANGELOG-leaflet.md b/doc/CHANGELOG-leaflet.md index b4126bac5..f9b89e954 100644 --- a/doc/CHANGELOG-leaflet.md +++ b/doc/CHANGELOG-leaflet.md @@ -51,6 +51,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Extension Geoportail Leaflet, version 2.1.7](#extension-geoportail-leaflet-version-217) * [Summary](#summary-13) * [Changelog](#changelog-10) +- [Extension Geoportail Leaflet, version 2.1.8](#extension-geoportail-leaflet-version-218) + * [Summary](#summary-14) + * [Changelog](#changelog-11) @@ -418,3 +421,31 @@ Mise à jour de Leaflet en version 1.7.1 * [Security] --- +# Extension Geoportail Leaflet, version 2.1.8 + +**12/02/2021** +> Release Extension Geoportail Leaflet + +## Summary + +Nouveau widget de profil altimétrique par défaut, et correctif mineur + +## Changelog + +* [Added] + +* [Changed] + + - nouvel affichage du profil altimétrique par défaut (DISPLAY_PROFILE_BY_DEFAULT) + +* [Deprecated] + +* [Removed] + +* [Fixed] + + - correctif sur l'export de la version en mode module + +* [Security] + +--- diff --git a/doc/README-itowns.md b/doc/README-itowns.md index bd703cf35..4e2767cf6 100644 --- a/doc/README-itowns.md +++ b/doc/README-itowns.md @@ -317,7 +317,7 @@ Gp.Services.getConfig(...) ### Versions d'iTowns supportées -La dernière version de l'extension Géoportail pour iTowns peut s'utiliser avec la **version 2.15.3** d'iTowns. [Cliquer ici](https://github.com/iTowns/itowns/releases/) pour télécharger directement la version 2.15.3 de la librairie iTowns. [Cliquer ici](https://www.npmjs.com/package/itowns?activeTab=readme) pour accéder à la page du package npm iTowns. +La dernière version de l'extension Géoportail pour iTowns peut s'utiliser avec la **version 2.27.0** d'iTowns. [Cliquer ici](https://github.com/iTowns/itowns/releases/) pour télécharger directement la version 2.27.0 de la librairie iTowns. [Cliquer ici](https://www.npmjs.com/package/itowns?activeTab=readme) pour accéder à la page du package npm iTowns. ### Navigateurs supportés diff --git a/package.json b/package.json index cc622b3c8..ad17303e3 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { "name": "geoportal-extensions", "description": "French Geoportal Extensions for OpenLayers, Leaflet and iTowns libraries", - "version": "2.3.2", - "date": "12/02/2021", + "version": "2.3.3", + "date": "30/03/2021", "leafletExtName": "French Geoportal Extension for Leaflet", "leafletExtVersion": "2.1.8", "olExtName": "French Geoportal Extension for OpenLayers", "olExtVersion": "3.0.14", "itownsExtName": "French Geoportal Extension for Itowns", - "itownsExtVersion": "2.3.1", + "itownsExtVersion": "2.3.2", "main": "dist/leaflet/GpPluginLeaflet.js, dist/openlayers/GpPluginOpenLayers.js, dist/itowns/GpPluginItowns.js", "module": "src/Leaflet/index.js, src/OpenLayers/index.js, src/Itowns/index.js", "directories": {}, @@ -67,17 +67,17 @@ "@mapbox/mapbox-gl-style-spec": "13.11.0", "eventbusjs": "0.2.0", "geoportal-access-lib": "2.1.7", - "itowns": "2.27.0", + "itowns": "2.30.0", "leaflet": "1.7.1", "leaflet-draw": "1.0.4", "loglevel": "^1.6.7", "markdown-toc": "^1.2.0", "ol": "5.3.0", "ol-mapbox-style": "4.2.1", - "proj4": "^2.6.2", + "proj4": "2.7.0", "proj4leaflet": "1.0.2", "sortablejs": "1.8.4", - "three": "^0.121.1", + "three": "0.124.0", "whatwg-fetch": "3.0.0" }, "devDependencies": { diff --git a/src/Common/Controls/MousePositionDOM.js b/src/Common/Controls/MousePositionDOM.js index e24ce7352..4c1f2feb9 100644 --- a/src/Common/Controls/MousePositionDOM.js +++ b/src/Common/Controls/MousePositionDOM.js @@ -831,7 +831,7 @@ var MousePositionDOM = { */ GPdisplayCoords : function (coordinate) { // Compute coords in case of cursor position (desktop) - if (coordinate && coordinate != null) { + if (coordinate) { var labelLon = document.getElementById(this._addUID("GPmousePositionLonLabel")); var labelLat = document.getElementById(this._addUID("GPmousePositionLatLabel")); @@ -911,7 +911,7 @@ var MousePositionDOM = { var minThreshold = noDataValue - noDataValueTolerance; // Compute coords in case of cursor position (desktop) - if (coordinate && coordinate != null) { + if (coordinate) { // If no altitude panel, don't call altitude request if (document.getElementById(this._addUID("GPmousePositionAltitude"))) { altitudeTimeout = setTimeout(function () { diff --git a/src/Common/Controls/ProfileElevationPathDOM.js b/src/Common/Controls/ProfileElevationPathDOM.js index c78d8a411..fa66fd1d0 100644 --- a/src/Common/Controls/ProfileElevationPathDOM.js +++ b/src/Common/Controls/ProfileElevationPathDOM.js @@ -106,17 +106,19 @@ var ProfileElevationPathDOM = { displayProfileByDefault : function (data, container, context, className) { var self = context; - // on nettoie toujours... - if (container) { - while (container.firstChild) { - container.removeChild(container.firstChild); - } + if (!container) { + return; } if (!data) { return; } + // on nettoie toujours... + while (container.firstChild) { + container.removeChild(container.firstChild); + } + const margin = { top : 25, right : 15, @@ -639,14 +641,16 @@ var ProfileElevationPathDOM = { * @returns {DOMElement} profil container */ displayProfileRaw : function (data, container, context, className) { + if (!container) { + return; + } + // on nettoie toujours... - if (container) { - while (container.firstChild) { - container.removeChild(container.firstChild); - } + while (container.firstChild) { + container.removeChild(container.firstChild); } - var _points = data.points; + var _points = (data && data.points) ? data.points : {}; var div = document.createElement("textarea"); div.id = "profilElevationResults"; @@ -686,11 +690,17 @@ var ProfileElevationPathDOM = { displayProfileLibD3 : function (data, container, context, className) { var self = context; + if (!container) { + return; + } + + if (!data) { + return; + } + // on nettoie toujours... - if (container) { - while (container.firstChild) { - container.removeChild(container.firstChild); - } + while (container.firstChild) { + container.removeChild(container.firstChild); } var _points = data.points; @@ -916,6 +926,14 @@ var ProfileElevationPathDOM = { displayProfileLibAmCharts : function (data, container, context, className) { var self = context; + if (!container) { + return; + } + + if (!data) { + return; + } + var _points = data.points; var ballonText = "[[title]] : [[value]]m
"; diff --git a/src/Common/Utils/AutoLoadConfig.js b/src/Common/Utils/AutoLoadConfig.js index 36122b19b..d8143602d 100644 --- a/src/Common/Utils/AutoLoadConfig.js +++ b/src/Common/Utils/AutoLoadConfig.js @@ -7,7 +7,7 @@ import Gp from "geoportal-access-lib"; // in case of several keys if (key) { var splitKeys = key.split(/;|,|\|/); - if (key && splitKeys.length > 1) { + if (splitKeys.length > 1) { var keys = []; for (var i = 0; i < splitKeys.length; i++) { keys.push(splitKeys[i]); diff --git a/src/Common/Utils/CheckRightManagement.js b/src/Common/Utils/CheckRightManagement.js index e6c2a1b16..e23f983b1 100644 --- a/src/Common/Utils/CheckRightManagement.js +++ b/src/Common/Utils/CheckRightManagement.js @@ -35,7 +35,7 @@ export default { // si aucune information sur les ressources, // il est impossible de controler quelquechose !!! - if (!_resources || _resources.length === 0) { + if (_resources.length === 0) { // message orienté pour le developpeur ! logger.error("WARNING : " + "no parameter 'resources' specified !"); @@ -44,7 +44,7 @@ export default { // si aucune information sur les services, // il est impossible de controler quelquechose !!! - if (!_services || _services.length === 0) { + if (_services.length === 0) { // message orienté pour le developpeur ! logger.error("WARNING : " + "no parameter 'services' specified !"); @@ -152,7 +152,7 @@ export default { } } - if (!_rightManagement || Object.keys(_rightManagement).length === 0) { + if (Object.keys(_rightManagement).length === 0) { logger.warn("WARNING : " + "The contract key configuration has been loaded, " + "and the 'apiKey' parameter has been set, " + diff --git a/src/Common/Utils/LayerUtils.js b/src/Common/Utils/LayerUtils.js index 477f76da9..a49267540 100644 --- a/src/Common/Utils/LayerUtils.js +++ b/src/Common/Utils/LayerUtils.js @@ -217,7 +217,7 @@ var LayerUtils = { } // max zoom constraints - if (drawLogo && maxZoomLevel !== null && (maxZoomLevel < zoom)) { + if (drawLogo && maxZoomLevel && (maxZoomLevel < zoom)) { drawLogo = false; } diff --git a/src/Itowns/Controls/Attributions.js b/src/Itowns/Controls/Attributions.js index 315ade0df..e935c19fb 100644 --- a/src/Itowns/Controls/Attributions.js +++ b/src/Itowns/Controls/Attributions.js @@ -36,7 +36,7 @@ function Attributions (aOptions) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (options && typeof options !== "object") { + if (typeof options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } diff --git a/src/Itowns/Controls/BoostRelief.js b/src/Itowns/Controls/BoostRelief.js index 36f05b60d..85a854be4 100644 --- a/src/Itowns/Controls/BoostRelief.js +++ b/src/Itowns/Controls/BoostRelief.js @@ -37,7 +37,7 @@ function BoostRelief (brOptions) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (options && typeof options !== "object") { + if (typeof options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } diff --git a/src/Itowns/Controls/LayerSwitcher.js b/src/Itowns/Controls/LayerSwitcher.js index b251822c7..f49c44ff2 100644 --- a/src/Itowns/Controls/LayerSwitcher.js +++ b/src/Itowns/Controls/LayerSwitcher.js @@ -52,11 +52,11 @@ function LayerSwitcher (lsOptions) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (layers && !Array.isArray(layers)) { + if (!Array.isArray(layers)) { throw new Error("ERROR WRONG_TYPE : layers should be an array"); } - if (options && typeof options !== "object") { + if (typeof options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } @@ -316,7 +316,7 @@ LayerSwitcher.prototype.addLayer = function (layer, config) { this._updateLayerListContainer(); // user may also add a new configuration for an already added layer - } else if (this._layers[id] && config) { + } else { // add new configuration parameters to layer informations for (var prop in config) { if (config.hasOwnProperty(prop)) { @@ -799,11 +799,11 @@ LayerSwitcher.prototype._onDragAndDropLayerClick = function (e) { } var targetIndex = null; - if (!e.newIndex || e.newIndex === 0) { - targetIndex = globe.getColorLayers().length - 1; - } else { + if (e.newIndex) { var layerTargetID = this._resolveLayerId(e.from.childNodes[e.newIndex + (e.newIndex - e.oldIndex < 0 ? 1 : -1)].id); targetIndex = globe.getLayerById(layerTargetID).sequence; + } else { + targetIndex = globe.getColorLayers().length - 1; } var layerID = this._resolveLayerId(e.item.id); diff --git a/src/Itowns/Controls/MiniGlobe.js b/src/Itowns/Controls/MiniGlobe.js index 8c4c21ac8..3b0f5ea34 100644 --- a/src/Itowns/Controls/MiniGlobe.js +++ b/src/Itowns/Controls/MiniGlobe.js @@ -24,7 +24,7 @@ function MiniGlobe (options) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (options && typeof options !== "object") { + if (typeof options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } diff --git a/src/Itowns/Controls/MousePosition.js b/src/Itowns/Controls/MousePosition.js index ad4f24b2f..2b5eb3f7b 100644 --- a/src/Itowns/Controls/MousePosition.js +++ b/src/Itowns/Controls/MousePosition.js @@ -80,7 +80,7 @@ function MousePosition (options) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (options && typeof options !== "object") { + if (typeof options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } @@ -891,9 +891,9 @@ MousePosition.prototype._setCoordinate = function (coords) { // transforms the point in the wanted coords system var oSrs = this._currentProjectionSystems; - var crsProp = oSrs.crs; + var crsProp = (oSrs) ? oSrs.crs : null; - if (!oSrs || !crsProp) { + if (!crsProp) { logger.error("system crs not found"); return; } @@ -1080,7 +1080,7 @@ MousePosition.prototype.onRequestAltitude = function (coordinate, callback) { if (!options.rawResponse) { // in the general case options.onSuccess = function (results) { - if (results && Object.keys(results)) { + if (results && Object.keys(results).length) { callback.call(this, results.elevations[0].z); } }; @@ -1102,7 +1102,7 @@ MousePosition.prototype.onRequestAltitude = function (coordinate, callback) { if (typeof this.options.ssl === "boolean") { options.ssl = this.options.ssl; } - + Gp.Services.getAltitude(options); }; diff --git a/src/Itowns/GlobeViewExtended.js b/src/Itowns/GlobeViewExtended.js index 32610d4f1..49867b955 100644 --- a/src/Itowns/GlobeViewExtended.js +++ b/src/Itowns/GlobeViewExtended.js @@ -27,7 +27,7 @@ var logger = Logger.getLogger("GlobeViewExtended"); * @param {String} [options.position="relative"] - "absolute" or "relative" */ function GlobeViewExtended (viewerDiv, coordCarto, options) { - if (!viewerDiv.style.position || (options & options.position)) { + if (!viewerDiv.style.position || (options && options.position)) { viewerDiv.style.position = (!options || !options.position) ? "relative" : options.position; } @@ -338,6 +338,16 @@ GlobeViewExtended.prototype.setLayerOpacity = function (layerId, opacityValue) { GlobeViewExtended.prototype.setLayerVisibility = function (layerId, visible) { var layer = this.getColorLayerById(layerId); layer.visible = visible; + + // sync the vectorTiles layer visibility with its labels + if (layer.source.isVectorSource === true) { + if (layer.visible === true) { + layer.labelEnabled = true; + } else { + layer.labelEnabled = false; + } + } + this.getGlobeView().notifyChange(layer); }; diff --git a/src/Itowns/Layer/LayerElevation.js b/src/Itowns/Layer/LayerElevation.js index 887078424..b0162527d 100644 --- a/src/Itowns/Layer/LayerElevation.js +++ b/src/Itowns/Layer/LayerElevation.js @@ -60,7 +60,7 @@ function LayerElevation (options) { var config = {}; var wmtsParams = Config.getLayerParams(options.layer, "WMTS", options.apiKey); - if (wmtsParams.projection === "EPSG:3857" && wmtsParams.extent) { + if (wmtsParams.projection === "EPSG:3857") { wmtsParams.extent = new ItExtent("EPSG:4326", wmtsParams.extent.left, wmtsParams.extent.right, wmtsParams.extent.bottom, wmtsParams.extent.top).as("EPSG:3857"); } else { wmtsParams.projection = "EPSG:4326"; diff --git a/src/Itowns/Layer/LayerWMS.js b/src/Itowns/Layer/LayerWMS.js index 245b0815d..f17156a7a 100644 --- a/src/Itowns/Layer/LayerWMS.js +++ b/src/Itowns/Layer/LayerWMS.js @@ -59,7 +59,7 @@ function LayerWMS (options) { var config = {}; var wmsParams = Config.getLayerParams(options.layer, "WMS", options.apiKey); - if (wmsParams.projection === "EPSG:3857" && wmsParams.extent) { + if (wmsParams.projection === "EPSG:3857") { wmsParams.extent = new ItExtent("EPSG:4326", wmsParams.extent.left, wmsParams.extent.right, wmsParams.extent.bottom, wmsParams.extent.top).as("EPSG:3857"); } else { wmsParams.extent = new ItExtent("EPSG:4326", wmsParams.extent.left, wmsParams.extent.right, wmsParams.extent.bottom, wmsParams.extent.top); diff --git a/src/Itowns/Layer/LayerWMTS.js b/src/Itowns/Layer/LayerWMTS.js index d068a13ba..c74174d3b 100644 --- a/src/Itowns/Layer/LayerWMTS.js +++ b/src/Itowns/Layer/LayerWMTS.js @@ -59,7 +59,7 @@ function LayerWMTS (options) { var config = {}; var wmtsParams = Config.getLayerParams(options.layer, "WMTS", options.apiKey); - if (wmtsParams.projection === "EPSG:3857" && wmtsParams.extent) { + if (wmtsParams.projection === "EPSG:3857") { wmtsParams.extent = new ItExtent("EPSG:4326", wmtsParams.extent.left, wmtsParams.extent.right, wmtsParams.extent.bottom, wmtsParams.extent.top).as("EPSG:3857"); } else { wmtsParams.projection = "EPSG:4326"; diff --git a/src/Leaflet/CRS/EPSG27572.js b/src/Leaflet/CRS/EPSG27572.js index 89c757b11..38c43dd07 100644 --- a/src/Leaflet/CRS/EPSG27572.js +++ b/src/Leaflet/CRS/EPSG27572.js @@ -71,7 +71,7 @@ var EPSG27572 = { // resolutions issues de l'autoconf if (Config.isConfigLoaded()) { var o = Config.getTileMatrix("LAMB2E"); - if (o && Object.keys(o)) { + if (o && Object.keys(o).length) { resolutions = o.nativeResolutions; } } diff --git a/src/Leaflet/Controls/ElevationPath.js b/src/Leaflet/Controls/ElevationPath.js index 9d45cfc63..912709447 100644 --- a/src/Leaflet/Controls/ElevationPath.js +++ b/src/Leaflet/Controls/ElevationPath.js @@ -667,7 +667,7 @@ var ElevationPath = L.Control.extend(/** @lends L.geoportalControl.ElevationPath var _sampling = options.sampling; if (!_sampling) { // computing sampling - var _computeSampling = 50; + var _computeSampling; var _length = this._currentFeature._measurementRunningTotal; // FIXME !!! logger.trace("length", _length); var p = Math.floor(_length) / 5; // en mètre sur un pas moyen de 5m ! diff --git a/src/Leaflet/Controls/LayerSwitcher.js b/src/Leaflet/Controls/LayerSwitcher.js index c5f893303..cf6f48359 100644 --- a/src/Leaflet/Controls/LayerSwitcher.js +++ b/src/Leaflet/Controls/LayerSwitcher.js @@ -94,7 +94,7 @@ var LayerSwitcher = L.Control.Layers.extend(/** @lends L.geoportalControl.LayerS // de titre ou description ... // a ton une configuration des layers ? - this._hasLayersConfig = !((!this.options.layers || Object.keys(this.options.layers).length === 0)); + this._hasLayersConfig = !(!this.options.layers || Object.keys(this.options.layers).length === 0); // configuration des layers this._layersConfig = (this._hasLayersConfig) ? this.options.layers : []; @@ -302,7 +302,7 @@ var LayerSwitcher = L.Control.Layers.extend(/** @lends L.geoportalControl.LayerS }; // surcharge la config ci dessus avec les options de configuration saisies - if (layerConfig && Object.keys(layerConfig)) { + if (layerConfig && Object.keys(layerConfig).length) { L.Util.extend(this._layers[id], layerConfig); } @@ -506,11 +506,7 @@ var LayerSwitcher = L.Control.Layers.extend(/** @lends L.geoportalControl.LayerS this._update(); } - var type = (e.type === "layeradd") ? "overlayadd" : "overlayremove"; - - if (type) { - this._map.fire(type, obj); - } + this._map.fire((e.type === "layeradd") ? "overlayadd" : "overlayremove", obj); }, /** diff --git a/src/Leaflet/Controls/Logo.js b/src/Leaflet/Controls/Logo.js index 2f8c80e28..e5d8c2cfb 100644 --- a/src/Leaflet/Controls/Logo.js +++ b/src/Leaflet/Controls/Logo.js @@ -60,7 +60,7 @@ var Logo = L.Control.extend(/** @lends Logo.prototype */ { var container = null; container = L.DomUtil.create("div", "gp-control-logo", container); - var bLink = !!((this.options.url || this.options.text)); + var bLink = !!(this.options.url || this.options.text); var link = null; if (bLink) { diff --git a/src/Leaflet/Controls/MousePosition.js b/src/Leaflet/Controls/MousePosition.js index ac341525c..90648794c 100644 --- a/src/Leaflet/Controls/MousePosition.js +++ b/src/Leaflet/Controls/MousePosition.js @@ -886,7 +886,7 @@ var MousePosition = L.Control.extend(/** @lends L.geoportalControl.MousePosition } coordinate = format(this._project(oLatLng, oSrs)); - if (!coordinate || Object.keys(coordinate).lenght === 0) { + if (!coordinate || Object.keys(coordinate).length === 0) { return; } @@ -1027,7 +1027,7 @@ var MousePosition = L.Control.extend(/** @lends L.geoportalControl.MousePosition // callback onSuccess onSuccess : function (results) { logger.log(results); - if (results && Object.keys(results)) { + if (results && Object.keys(results).length) { // var context = this.options.scope; // context._setAltidude(results.elevations[0].z); callback.call(this, results.elevations[0].z); diff --git a/src/Leaflet/Controls/ReverseGeocoding.js b/src/Leaflet/Controls/ReverseGeocoding.js index faed7a581..575983b72 100644 --- a/src/Leaflet/Controls/ReverseGeocoding.js +++ b/src/Leaflet/Controls/ReverseGeocoding.js @@ -236,9 +236,7 @@ var ReverseGeocoding = L.Control.extend(/** @lends L.geoportalControl.ReverseGeo this.options.apiKey = rightManagementGeocode.key; } - if (rightManagementGeocode) { - this._servicesRightManagement["Geocode"] = rightManagementGeocode["Geocode"]; - } + this._servicesRightManagement["Geocode"] = rightManagementGeocode["Geocode"]; }, /** @@ -253,35 +251,37 @@ var ReverseGeocoding = L.Control.extend(/** @lends L.geoportalControl.ReverseGeo if (this.options.resources) { var resources = this.options.resources; // on vérifie que la liste des ressources de geocodage est bien un tableau - if (!Array.isArray(resources)) { + if (Array.isArray(resources)) { + var resourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; + for (i = 0; i < resources.length; i++) { + if (resourcesList.indexOf(resources[i]) === -1) { + // si la resource n'est pas référencée, on l'enlève + // resources.splice(i, 1); + logger.log("[ReverseGeocoding] options.resources : " + resources[i] + " is not a resource for reverse geocode"); + } + } + } else { logger.log("[ReverseGeocoding] 'options.resources' parameter should be an array"); resources = null; } - var resourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; - for (i = 0; i < resources.length; i++) { - if (resourcesList.indexOf(resources[i]) === -1) { - // si la resource n'est pas référencée, on l'enlève - // resources.splice(i, 1); - logger.log("[ReverseGeocoding] options.resources : " + resources[i] + " is not a resource for reverse geocode"); - } - } } // et le tableau des délimitations if (this.options.delimitations) { var delimitations = this.options.delimitations; // on vérifie que la liste des delimitations est bien un tableau - if (!Array.isArray(delimitations)) { + if (Array.isArray(delimitations)) { + var delimitationsList = ["Circle", "Point", "Extent"]; + for (i = 0; i < delimitations.length; i++) { + if (delimitationsList.indexOf(delimitations[i]) === -1) { + // si la delimitations n'est pas référencée, on l'enlève + // resources.splice(i, 1); + logger.log("[ReverseGeocoding] options.delimitations : " + delimitations[i] + " is not a delimitation for reverse geocode"); + } + } + } else { logger.log("[ReverseGeocoding] 'options.delimitations' parameter should be an array"); delimitations = null; } - var delimitationsList = ["Circle", "Point", "Extent"]; - for (i = 0; i < delimitations.length; i++) { - if (delimitationsList.indexOf(delimitations[i]) === -1) { - // si la delimitations n'est pas référencée, on l'enlève - // resources.splice(i, 1); - logger.log("[ReverseGeocoding] options.delimitations : " + delimitations[i] + " is not a delimitation for reverse geocode"); - } - } } }, diff --git a/src/Leaflet/Controls/Route.js b/src/Leaflet/Controls/Route.js index 1d06b3515..b7280d6f8 100644 --- a/src/Leaflet/Controls/Route.js +++ b/src/Leaflet/Controls/Route.js @@ -1033,7 +1033,7 @@ var Route = L.Control.extend(/** @lends L.geoportalControl.Route.prototype */ { } // existe t il une geometrie pour chaque troncon de route ? - var bGeometryInstructions = (instructions[0].geometry.length !== 0); + var bGeometryInstructions = (instructions && Array.isArray(instructions) && instructions[0].geometry.length !== 0); // Geometries des tronçon if (instructions && bGeometryInstructions) { diff --git a/src/Leaflet/Controls/SearchEngine.js b/src/Leaflet/Controls/SearchEngine.js index 5fb7e65e4..2e76641bf 100644 --- a/src/Leaflet/Controls/SearchEngine.js +++ b/src/Leaflet/Controls/SearchEngine.js @@ -770,10 +770,8 @@ var SearchEngine = L.Control.extend(/** @lends L.geoportalControl.SearchEngine.p // au cas où les options du services ne sont pas renseignées, on y ajoute // les tables de ressources - if (resources && L.Util.isArray(resources) && !options.filterOptions) { - if (!options.filterOptions) { - options.filterOptions = {}; - } + if (L.Util.isArray(resources) && !options.filterOptions) { + options.filterOptions = {}; options.filterOptions.type = resources; } @@ -880,10 +878,8 @@ var SearchEngine = L.Control.extend(/** @lends L.geoportalControl.SearchEngine.p // au cas où les options du services ne sont pas renseignées, on y ajoute // les tables de ressources - if (resources && L.Util.isArray(resources) && !options.filterOptions) { - if (!options.filterOptions) { - options.filterOptions = {}; - } + if (L.Util.isArray(resources) && !options.filterOptions) { + options.filterOptions = {}; options.filterOptions.type = resources; } diff --git a/src/Leaflet/Layers/LayerEvent.js b/src/Leaflet/Layers/LayerEvent.js index 421a83e59..ac436e7bc 100644 --- a/src/Leaflet/Layers/LayerEvent.js +++ b/src/Leaflet/Layers/LayerEvent.js @@ -130,9 +130,7 @@ var LayerEvent = { } // suppression des attributions de liste - if (this._attributions) { - this._attributions = []; - } + this._attributions = []; }, /** diff --git a/src/Leaflet/Layers/Layers.js b/src/Leaflet/Layers/Layers.js index 742428e0b..5e4228077 100644 --- a/src/Leaflet/Layers/Layers.js +++ b/src/Leaflet/Layers/Layers.js @@ -29,7 +29,7 @@ var Layers = { * initialize options */ _initOptions : function () { - if (!this.options || Object.keys(this.options) === 0) { + if (!this.options || Object.keys(this.options).length === 0) { throw new Error("PARAM_MISSING : options !"); } @@ -75,7 +75,7 @@ var Layers = { service : service }); - if (!this.params || Object.keys(this.params) === 0) { + if (!this.params || Object.keys(this.params).length === 0) { this.params = {}; if (!this.options.apiKey) { // FIXME on retire l'exception... diff --git a/src/OpenLayers/Controls/Drawing.js b/src/OpenLayers/Controls/Drawing.js index 9077b1b0f..1822b10ea 100644 --- a/src/OpenLayers/Controls/Drawing.js +++ b/src/OpenLayers/Controls/Drawing.js @@ -61,7 +61,7 @@ var logger = Logger.getLogger("Drawing"); * @param {Object} options - options for function call. * @param {Boolean} [options.collapsed = true] - Specify if Drawing control should be collapsed at startup. Default is true. * @param {Boolean} [options.draggable = false] - Specify if widget is draggable - * @param {ol.layer.Vector} [options.layer = null] - Openlayers layer that will hosts created features. If none, an empty vector layer will be created. + * @param {Object} [options.layer = {}] - Openlayers layer that will hosts created features. If none, an empty vector layer will be created. * @param {Object} [options.popup = {}] - Popup informations * @param {Boolean} [options.popup.display = true] - Specify if popup is displayed when create a drawing * @param {Function} [options.popup.function] - Function to display popup informations if you want to cutomise it. You may also provide your own function with params : {geomType / feature / saveFunc(message) / closeFunc()}. This function must return the DOM object of the popup content. @@ -100,7 +100,7 @@ var logger = Logger.getLogger("Drawing"); * @param {String} [options.labels.strokeWidth] - Label for stroke width. * @param {String} [options.labels.fillColor] - Label for fill color. * @param {String} [options.labels.fillOpacity] - Label for fillOpacity. - * @param {Array.} [options.markersList = [{src : "data:image/png;base64,xxxx", anchor : [0.5,1]}]] - List of markers src to be used for points with their anchor offsets See {@link http://openlayers.org/en/latest/apidoc/ol.style.Icon.html OpenLayers params} for anchor offset options. + * @param {Array.} [options.markersList = [{"src" : "data:image/png;base64,xxxx", "anchor" : [0.5,1]}]] - List of markers src to be used for points with their anchor offsets See {@link http://openlayers.org/en/latest/apidoc/ol.style.Icon.html OpenLayers params} for anchor offset options. * @param {Object} options.defaultStyles - Default styles applying to geometries (labels, lines and polygons). * @param {String} [options.defaultStyles.textFillColor = "#000000"] - Text fill color for labels (RGB hex value). * @param {String} [options.defaultStyles.textStrokeColor = "#FFFFFF"] - Text surrounding color for labels (RGB hex value). @@ -479,8 +479,9 @@ var Drawing = (function (Control) { this._exportName = "Croquis"; this._exportFormat = ".kml"; + options = options || {}; // Set default options - this.options = options || {}; + this.options = options; if (!this.options.layerDescription) { this.options.layerDescription = { diff --git a/src/OpenLayers/Controls/Editor.js b/src/OpenLayers/Controls/Editor.js index dd84a8cd9..db7cce2b7 100644 --- a/src/OpenLayers/Controls/Editor.js +++ b/src/OpenLayers/Controls/Editor.js @@ -681,7 +681,7 @@ Editor.prototype._getSprites = function (sprites) { .catch(error => { logger.warn("fetch image sprites exception :", error); }); - } else {} + } }) .catch(error => { logger.warn("fetch sprites exception :", error); @@ -701,7 +701,7 @@ Editor.prototype._getSprites = function (sprites) { .catch(error => { logger.warn("fetch json sprites exception :", error); }); - } else {} + } }) .catch(error => { logger.warn("fetch sprites exception :", error); diff --git a/src/OpenLayers/Controls/Editor/Legend.js b/src/OpenLayers/Controls/Editor/Legend.js index 6c5c1e9e3..536e6eea0 100644 --- a/src/OpenLayers/Controls/Editor/Legend.js +++ b/src/OpenLayers/Controls/Editor/Legend.js @@ -359,19 +359,19 @@ Legend.prototype._getValues = function (type, value) { switch (type) { case "line": pColor = value["line-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } _color = pColor || _color; pWidth = value["line-width"]; - _width = (typeof pWidth === "object" || Array.isArray(pWidth)) ? _width : pWidth || _width; + _width = (Array.isArray(pWidth) || typeof pWidth === "object") ? _width : pWidth || _width; pOpacity = value["line-opacity"]; - _opacity = (typeof pOpacity === "object" || Array.isArray(pOpacity)) ? _opacity : pOpacity || _opacity; + _opacity = (Array.isArray(pOpacity) || typeof pOpacity === "object") ? _opacity : pOpacity || _opacity; break; case "text": pColor = value["text-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } @@ -389,7 +389,7 @@ Legend.prototype._getValues = function (type, value) { _icon = value["icon-image"]; } else { pColor = value["icon-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } @@ -399,21 +399,21 @@ Legend.prototype._getValues = function (type, value) { break; case "circle": pColor = value["circle-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } _color = pColor || _color; pStroke = value["circle-stroke-color"]; - _stroke = (typeof pStroke === "object" || Array.isArray(pStroke)) ? _stroke : pStroke || _stroke; + _stroke = (Array.isArray(pStroke) || typeof pStroke === "object") ? _stroke : pStroke || _stroke; pOpacity = value["circle-opacity"]; - _opacity = (typeof pOpacity === "object" || Array.isArray(pOpacity)) ? _opacity : pOpacity || _opacity; + _opacity = (Array.isArray(pOpacity) || typeof pOpacity === "object") ? _opacity : pOpacity || _opacity; pWidth = value["circle-stroke-width"]; - _width = (typeof pWidth === "object" || Array.isArray(pWidth)) ? _width : pWidth || _width; + _width = (Array.isArray(pWidth) || typeof pWidth === "object") ? _width : pWidth || _width; break; case "background": pColor = value["background-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } @@ -421,13 +421,13 @@ Legend.prototype._getValues = function (type, value) { break; case "fill": pColor = value["fill-color"]; - if (typeof pColor === "object" || Array.isArray(pColor)) { + if (Array.isArray(pColor) || typeof pColor === "object") { _color = null; break; } _color = pColor || _color; pOpacity = value["fill-opacity"]; - _opacity = (typeof pOpacity === "object" || Array.isArray(pOpacity)) ? _opacity : pOpacity || _opacity; + _opacity = (Array.isArray(pOpacity) || typeof pOpacity === "object") ? _opacity : pOpacity || _opacity; break; default: // return false; diff --git a/src/OpenLayers/Controls/Editor/Themes.js b/src/OpenLayers/Controls/Editor/Themes.js index bac562851..dc50061bf 100644 --- a/src/OpenLayers/Controls/Editor/Themes.js +++ b/src/OpenLayers/Controls/Editor/Themes.js @@ -90,7 +90,7 @@ Themes.prototype._initialize = function () { } }; - if (!this.options.tools || Object.keys(this.options.tools) === 0) { + if (!this.options.tools || Object.keys(this.options.tools).length === 0) { this.options.tools = _toolsDefault; } @@ -171,7 +171,7 @@ Themes.prototype._initContainer = function () { var _url = _theme.url; // style selectionné par defaut (uniquement en mode radio-button !?) var _selected = _theme.selected || false; - if (_url && _url !== "") { + if (_url) { // bouton var button = this.options.tools.button; if (button.visible) { diff --git a/src/OpenLayers/Controls/ElevationPath.js b/src/OpenLayers/Controls/ElevationPath.js index 97a28512d..2e92bccef 100644 --- a/src/OpenLayers/Controls/ElevationPath.js +++ b/src/OpenLayers/Controls/ElevationPath.js @@ -48,16 +48,16 @@ var logger = Logger.getLogger("elevationpath"); * @param {String} [options.apiKey] - API key for services call (isocurve and autocomplete services), mandatory if autoconf service has not been charged in advance * @param {Boolean} [options.active = false] - specify if control should be actived at startup. Default is false. * @param {Boolean} [options.ssl = true] - use of ssl or not (default true, service requested using https protocol) + * @param {Object} [options.elevationPathOptions = {}] - elevation path service options. See {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~getAltitude Gp.Services.getAltitude()} for available options * @param {Object} [options.layerDescription = {}] - Layer informations to be displayed in LayerSwitcher widget (only if a LayerSwitcher is also added to the map) * @param {String} [options.layerDescription.title = "Profil altimétrique"] - Layer title to be displayed in LayerSwitcher * @param {String} [options.layerDescription.description = "Mon profil altimétrique"] - Layer description to be displayed in LayerSwitcher - * @param {Object} [options.stylesOptions = DEFAULT_STYLES] - styles management + * @param {Object} [options.stylesOptions] - styles management * @param {Object} [options.stylesOptions.marker = {}] - styles management of marker displayed on map when the user follows the elevation path. Specified with an {@link https://openlayers.org/en/latest/apidoc/ol.style.Image.html ol.style.Image} subclass object * @param {Object} [options.stylesOptions.draw = {}] - styles used when drawing. Specified with following properties. * @param {Object} [options.stylesOptions.draw.pointer = {}] - Style for mouse pointer when drawing the line. Specified with an {@link https://openlayers.org/en/latest/apidoc/ol.style.Image.html ol.style.Image} subclass object. * @param {Object} [options.stylesOptions.draw.start = {}] - Line Style when drawing. Specified with an {@link https://openlayers.org/en/latest/apidoc/ol.style.Stroke.html ol.style.Stroke} object. * @param {Object} [options.stylesOptions.draw.finish = {}] - Line Style when finished drawing. Specified with an {@link https://openlayers.org/en/latest/apidoc/ol.style.Stroke.html ol.style.Stroke} object. - * @param {Object} [options.elevationPathOptions = {}] - elevation path service options. See {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~getAltitude Gp.Services.getAltitude()} for available options * @param {Object} [options.displayProfileOptions = {}] - profile options. * @param {Boolean} [options.displayProfileOptions.totalDistance = true] - display the total distance of the path * @param {Boolean} [options.displayProfileOptions.greaterSlope = true] - display the greater slope into the graph @@ -1173,7 +1173,7 @@ var ElevationPath = (function (Control) { options.ssl = true; } } - + Utils.mergeParams(options, { ssl : options.ssl }); @@ -1213,7 +1213,7 @@ var ElevationPath = (function (Control) { var sampling = options.sampling; if (!sampling) { // computing sampling - var _sampling = 50; + var _sampling; var _length = this._getLength(); logger.trace("length", _length); var minSampling = this._getSketchCoords(); @@ -1340,6 +1340,9 @@ var ElevationPath = (function (Control) { _data[i].lon = Math.round(_data[i].lon * 10000) / 10000; } + // check distance totale + logger.trace("List Distances", distances); + // Correction des altitudes aberrantes + arrondi des calculs de distance + ... var _altMin = _data[0].z; var _altMax = _data[0].z; diff --git a/src/OpenLayers/Controls/GeoportalAttribution.js b/src/OpenLayers/Controls/GeoportalAttribution.js index 68689784a..86a9068e5 100644 --- a/src/OpenLayers/Controls/GeoportalAttribution.js +++ b/src/OpenLayers/Controls/GeoportalAttribution.js @@ -181,6 +181,10 @@ var GeoportalAttribution = (function (Attribution) { return; } + if (!mapAttributions) { + mapAttributions = {}; + } + var attributions = []; var visibility = layer.getVisible(); @@ -204,7 +208,7 @@ var GeoportalAttribution = (function (Attribution) { for (var j = 0; j < layerAttributions.length; j++) { var attributionj = layerAttributions[j]; // check that this attribution hasn't been added yet for another layer - if (!mapAttributions || !mapAttributions[attributionj]) { + if (!mapAttributions.hasOwnProperty(attributionj)) { // add attribution html attributions.push(attributionj); diff --git a/src/OpenLayers/Controls/GetFeatureInfo.js b/src/OpenLayers/Controls/GetFeatureInfo.js index 051576dc5..239b53ede 100644 --- a/src/OpenLayers/Controls/GetFeatureInfo.js +++ b/src/OpenLayers/Controls/GetFeatureInfo.js @@ -22,52 +22,52 @@ var logger = Logger.getLogger("getfeatureinfo"); * @constructor * @alias ol.control.GetFeatureInfo * @extends {ol.control.Control} - * @param {Object} gfiOptions - control options - * @param {Array.} [gfiOptions.layers] - list of layers which can be requested through the control. Each array element is an object, with following properties : - * @param {ol.layer.Layer} gfiOptions.layers.obj - {@link http://openlayers.org/en/latest/apidoc/ol.layer.Layer.html ol.layer.Layer} layer handled by the control (that has been added to map). - * @param {String} [gfiOptions.layers.event] - name of the mouse event triggering getFeatureInfo on this layer (that has been added to map). allowed values are : 'singleclick', 'dblclick' and 'contextmenu'. If not specified the triggering event is the current default event (see gfiOptions.options.defaultEvent). - * @param {String} [gfiOptions.layers.infoFormat] - indicates the format mime-type of the response of GetFeatureInfo requests. - * @param {Object} [gfiOptions.options] - custom options object to configure the control, with following properties : - * @param {Boolean} [gfiOptions.options.hidden=false] - specifies if the widget should be hidden. - * @param {Boolean} [gfiOptions.options.auto=false] - specifies if the control run in automatic mode. In automatic mode all vector layers added on run time or added at map initialization can be requested through the control. The triggering event of those layers is the default event. - * @param {Boolean} [gfiOptions.options.active=true] - specifies if the control is active or inactive. In inactive mode requests are not fired and no information are displayed. - * @param {String} [gfiOptions.options.defaultEvent='singleclick'] - default triggering event chosen in the list ('singleclick', 'dblclick', 'contextmenu'). This is the triggering event of all layers added to the control without configured triggering event. - * @param {String} [gfiOptions.options.defaultInfoFormat='text/html'] - indicates the default format mime-type of the response of GetFeatureInfo requests. - * @param {String} [gfiOptions.options.cursorStyle='pointer'] - specifies the type of cursor to be displayed when pointing on vector feature of a layer previously added to the control. The value must be choosen in the possible values of the css cursor property. - * @param {String} [gfiOptions.options.proxyUrl] - Proxy URL to avoid cross-domain problems. - * @param {Array.} [gfiOptions.options.noProxyDomains] - Proxy will not be used for this list of domain names. Only use if you know what you're doing. - * @param {Boolean} [gfiOptions.options.autoPan = true] - Specifies whether the map should auto-pan if the pop-up is rendered outside of the canvas. Defaults to true. - * @param {olx.OverlayPanOptions} [gfiOptions.options.autoPanAnimation] - Used to customize the auto-pan animation. See {@link https://openlayers.org/en/latest/apidoc/olx.html#.OverlayPanOptions olx.OverlayPanOptions}. - * @param {Number} [gfiOptions.options.autoPanMargin] - Margin (in pixels) between the pop-up and the border of the map when autopanning. Default is 20. + * @param {Object} options - control options + * @param {Array.} [options.layers] - list of layers which can be requested through the control. Each array element is an object, with following properties : + * @param {ol.layer.Layer} options.layers.obj - {@link http://openlayers.org/en/latest/apidoc/ol.layer.Layer.html ol.layer.Layer} layer handled by the control (that has been added to map). + * @param {String} [options.layers.event] - name of the mouse event triggering getFeatureInfo on this layer (that has been added to map). allowed values are : 'singleclick', 'dblclick' and 'contextmenu'. If not specified the triggering event is the current default event (see options.options.defaultEvent). + * @param {String} [options.layers.infoFormat] - indicates the format mime-type of the response of GetFeatureInfo requests. + * @param {Object} [options.options] - custom options object to configure the control, with following properties : + * @param {Boolean} [options.options.hidden=false] - specifies if the widget should be hidden. + * @param {Boolean} [options.options.auto=false] - specifies if the control run in automatic mode. In automatic mode all vector layers added on run time or added at map initialization can be requested through the control. The triggering event of those layers is the default event. + * @param {Boolean} [options.options.active=true] - specifies if the control is active or inactive. In inactive mode requests are not fired and no information are displayed. + * @param {String} [options.options.defaultEvent="singleclick"] - default triggering event chosen in the list ('singleclick', 'dblclick', 'contextmenu'). This is the triggering event of all layers added to the control without configured triggering event. + * @param {String} [options.options.defaultInfoFormat="text/html"] - indicates the default format mime-type of the response of GetFeatureInfo requests. + * @param {String} [options.options.cursorStyle="pointer"] - specifies the type of cursor to be displayed when pointing on vector feature of a layer previously added to the control. The value must be choosen in the possible values of the css cursor property. + * @param {String} [options.options.proxyUrl] - Proxy URL to avoid cross-domain problems. + * @param {Array.} [options.options.noProxyDomains] - Proxy will not be used for this list of domain names. Only use if you know what you're doing. + * @param {Boolean} [options.options.autoPan = true] - Specifies whether the map should auto-pan if the pop-up is rendered outside of the canvas. Defaults to true. + * @param {olx.OverlayPanOptions} [options.options.autoPanAnimation] - Used to customize the auto-pan animation. See {@link https://openlayers.org/en/latest/apidoc/olx.html#.OverlayPanOptions olx.OverlayPanOptions}. + * @param {Number} [options.options.autoPanMargin] - Margin (in pixels) between the pop-up and the border of the map when autopanning. Default is 20. */ var GetFeatureInfo = (function (Control) { - function GetFeatureInfo (gfiOptions) { - gfiOptions = gfiOptions || {}; - var options = gfiOptions.options || {}; - var layers = gfiOptions.layers || []; + function GetFeatureInfo (options) { + options = options || {}; + var _options = options.options || {}; + var _layers = options.layers || []; if (!(this instanceof GetFeatureInfo)) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (layers && !Array.isArray(layers)) { + if (!Array.isArray(_layers)) { throw new Error("ERROR WRONG_TYPE : layers should be an array"); } - if (options && typeof options !== "object") { + if (typeof _options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } - this._initialize(options, layers); + this._initialize(_options, _layers); // init control DOM container - var container = this._container = this._initContainer(options); + var container = this._container = this._initContainer(_options); // call ol.control.Control constructor Control.call(this, { element : container, - target : options.target, - render : options.render + target : _options.target, + render : _options.render }); }; diff --git a/src/OpenLayers/Controls/Isocurve.js b/src/OpenLayers/Controls/Isocurve.js index dfb066cc5..4e23f8e84 100644 --- a/src/OpenLayers/Controls/Isocurve.js +++ b/src/OpenLayers/Controls/Isocurve.js @@ -40,16 +40,16 @@ var logger = Logger.getLogger("isocurve"); * @param {Boolean} [options.ssl = true] - use of ssl or not (default true, service requested using https protocol) * @param {Boolean} [options.collapsed = true] - Specify if widget has to be collapsed (true) or not (false) on map loading. Default is true. * @param {Boolean} [options.draggable = false] - Specify if widget is draggable - * @param {Object} [options.exclusions = {toll : false, tunnel : false, bridge : false}] - list of exclusions with status (true = checked). By default : no exclusions checked. + * @param {Object} [options.exclusions = {"toll" : false, "tunnel" : false, "bridge" : false}] - list of exclusions with status (true = checked). By default : no exclusions checked. * @param {Array} [options.graphs = ["Voiture", "Pieton"]] - list of graph resources to be used for isocurve calculation, by default : ["Voiture", "Pieton"]. Possible values are "Voiture" and "Pieton". The first element is selected. * @param {Array} [options.methods = ["time", "distance"]] - list of methods, by default : ["time", "distance"]. Possible values are "time" and "distance". The first element is selected by default. * @param {Array} [options.directions = ["departure", "arrival"]] - list of directions to be displayed, by default : ["departure", "arrival"]. The first element is selected by default. Possible values are "departure" and "arrival". * Directions enable to specify if input location point will be used as a departure point ("departure") or as an arrival point ("arrival") + * @param {Object} [options.isocurveOptions = {}] - isocurve service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~isoCurve Gp.Services.isoCurve()} to know all isocurve options. + * @param {Object} [options.autocompleteOptions = {}] - autocomplete service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~autoComplete Gp.Services.autoComplete()} to know all autocomplete options * @param {Object} [options.markerOpts] - options to use your own marker. Default is a lightOrange marker. * @param {String} [options.markerOpts.url] - marker base64 encoded url (ex "data:image/png;base64,...""). Mandatory for a custom marker * @param {Array} [options.markerOpts.offset] - Offsets in pixels used when positioning the overlay. The first element in the array is the horizontal offset. A positive value shifts the overlay right. The second element in the array is the vertical offset. A positive value shifts the overlay down. Default is [0, 0]. (see http://openlayers.org/en/latest/apidoc/ol.Overlay.html) - * @param {Object} [options.isocurveOptions = {}] - isocurve service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~isoCurve Gp.Services.isoCurve()} to know all isocurve options. - * @param {Object} [options.autocompleteOptions = {}] - autocomplete service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~autoComplete Gp.Services.autoComplete()} to know all autocomplete options * @param {Object} [options.layerDescription = {}] - Layer informations to be displayed in LayerSwitcher widget (only if a LayerSwitcher is also added to the map) * @param {String} [options.layerDescription.title = "Isochrone/Isodistance"] - Layer title to be displayed in LayerSwitcher * @param {String} [options.layerDescription.description = "isochrones/isodistance basé sur un graphe"] - Layer description to be displayed in LayerSwitcher @@ -1352,7 +1352,7 @@ var Isocurve = (function (Control) { } var bridgeInput = document.getElementById("GPisoExclusionsBridge-" + this._uid); if (bridgeInput) { - if (this._currentExclusions.indexOf("bridge") !== -1 && bridgeInput) { + if (this._currentExclusions.indexOf("bridge") !== -1) { bridgeInput.checked = false; } else { bridgeInput.checked = true; diff --git a/src/OpenLayers/Controls/LayerImport.js b/src/OpenLayers/Controls/LayerImport.js index d120d3dc3..89b900f11 100644 --- a/src/OpenLayers/Controls/LayerImport.js +++ b/src/OpenLayers/Controls/LayerImport.js @@ -62,7 +62,7 @@ var logger = Logger.getLogger("layerimport"); * @alias ol.control.LayerImport * @extends {ol.control.Control} * @param {Object} options - options for function call. - * @param {Boolean} [options.collapsed = false] - Specify if LayerImport control should be collapsed at startup. Default is true. + * @param {Boolean} [options.collapsed = true] - Specify if LayerImport control should be collapsed at startup. Default is true. * @param {Boolean} [options.draggable = false] - Specify if widget is draggable * @param {Array} [options.layerTypes = ["KML", "GPX", "GeoJSON", "WMS", "WMTS", "MAPBOX"]] - data types that could be imported : "KML", "GPX", "GeoJSON", "WMS", "WMTS" and "MAPBOX". Values will be displayed in the same order in widget list. * @param {Object} [options.webServicesOptions = {}] - Options to import WMS or WMTS layers @@ -1849,9 +1849,6 @@ var LayerImport = (function (Control) { // Parse GetCapabilities Response if (this._currentImportType === "WMS") { parser = new WMSCapabilities(); - if (!parser) { - return; - } var getCapResponseWMS = this._getCapResponseWMS = parser.read(xmlResponse); logger.log("getCapabilities response : ", getCapResponseWMS); @@ -1874,9 +1871,6 @@ var LayerImport = (function (Control) { } else if (this._currentImportType === "WMTS") { parser = new WMTSCapabilities(); - if (!parser) { - return; - } var getCapResponseWMTS = this._getCapResponseWMTS = parser.read(xmlResponse); logger.log("getCapabilities response : ", getCapResponseWMTS); @@ -1926,10 +1920,11 @@ var LayerImport = (function (Control) { LayerImport.prototype._displayGetCapResponseWMSLayer = function (layerObj, parentLayersInfos) { if (!layerObj) { logger.warn("[ol.control.LayerImport] _displayGetCapResponseWMSLayer : getCapabilities layer object not found"); - } else { - logger.log("[ol.control.LayerImport] _displayGetCapResponseWMSLayer - layerObj : ", layerObj); + return; } + logger.log("[ol.control.LayerImport] _displayGetCapResponseWMSLayer - layerObj : ", layerObj); + // récupération de la projection de la map (pour vérifier que l'on peut reprojeter les couches disponibles) var mapProjCode = this._getMapProjectionCode(); var projection; @@ -1954,7 +1949,7 @@ var LayerImport = (function (Control) { if (Array.isArray(parentLayersInfos[key]) && parentLayersInfos[key].length !== 0) { if (Array.isArray(layerObj[key]) && layerObj[key].length !== 0) { // on ajoute celles de la couche parent - for (var n = 0; n < parentLayersInfos[key]; n++) { + for (var n = 0; n < parentLayersInfos[key].length; n++) { if (layerObj[key].indexOf(parentLayersInfos[key][n]) === -1) { // si le CRS/Style parent n'est pas dans les CRS/Style de la couche, on l'ajoute layerObj[key].push(parentLayersInfos[key][n]); @@ -2064,7 +2059,7 @@ var LayerImport = (function (Control) { if (e.target && e.target.id) { var proposalId = parseInt(e.target.id.substr(23), 10); - if (proposalId == null) { + if (isNaN(proposalId)) { return; } @@ -2328,7 +2323,7 @@ var LayerImport = (function (Control) { layerTileOptions.extent = extent; break; } else { - if (crs && typeof crs === "string") { + if (typeof crs === "string") { var olProj = olGetProj(crs) ? olGetProj(crs) : olGetProj(crs.toUpperCase()); // if ( olGetProj(crs) || olGetProj(crs.toUpperCase()) ) { if (olProj) { @@ -2665,7 +2660,7 @@ var LayerImport = (function (Control) { } // tri des résolutions par ordre décroissant - if (Array.isArray(resolutions) && resolutions.sort !== undefined) { + if (resolutions.sort !== undefined) { resolutions.sort( function (x, y) { return y - x; @@ -2673,7 +2668,7 @@ var LayerImport = (function (Control) { ); } // tri des identifiants des niveaux de pyramide (matrixIds) par ordre croissant - if (Array.isArray(matrixIds) && matrixIds.sort !== undefined) { + if (matrixIds.sort !== undefined) { matrixIds.sort( function (x, y) { return x - y; diff --git a/src/OpenLayers/Controls/LayerSwitcher.js b/src/OpenLayers/Controls/LayerSwitcher.js index 25d7103b4..9c3606d97 100644 --- a/src/OpenLayers/Controls/LayerSwitcher.js +++ b/src/OpenLayers/Controls/LayerSwitcher.js @@ -20,19 +20,19 @@ var logger = Logger.getLogger("layerswitcher"); * @constructor * @extends {ol.control.Control} * @alias ol.control.LayerSwitcher - * @param {Object} lsOptions - control options - * @param {Array} [lsOptions.layers] - list of layers to be configured. Each array element is an object, with following properties : - * @param {ol.layer.Layer} [lsOptions.layers.layer] - ol.layer.Layer layer to be configured (that has been added to map) - * @param {Object} [lsOptions.layers.config] - custom configuration object for layer information (title, description, legends, metadata, quicklook url), with following properties : - * @param {String} [lsOptions.layers.config.title] - layer alias, to be displayed in widget layer list. E.g. : "Cartes IGN" - * @param {String} [lsOptions.layers.config.description] - layer description, to be displayed on title hover, or in layer information panel. - * @param {String} [lsOptions.layers.config.quicklookUrl] - link to a quick look image for this layer. - * @param {Array} [lsOptions.layers.config.legends] - array of layer legends. Each array element is an object, with following properties : + * @param {Object} options - control options + * @param {Array} [options.layers] - list of layers to be configured. Each array element is an object, with following properties : + * @param {ol.layer.Layer} [options.layers.layer] - ol.layer.Layer layer to be configured (that has been added to map) + * @param {Object} [options.layers.config] - custom configuration object for layer information (title, description, legends, metadata, quicklook url), with following properties : + * @param {String} [options.layers.config.title] - layer alias, to be displayed in widget layer list. E.g. : "Cartes IGN" + * @param {String} [options.layers.config.description] - layer description, to be displayed on title hover, or in layer information panel. + * @param {String} [options.layers.config.quicklookUrl] - link to a quick look image for this layer. + * @param {Array} [options.layers.config.legends] - array of layer legends. Each array element is an object, with following properties : * - url (String, mandatory) : link to a legend * - minScaleDenominator (Number, optional) : min scale denominator for legend validity. - * @param {Array} [lsOptions.layers.config.metadata] - array of layer metadata. Each array element is an object, with property url (String, mandatory) : link to a metadata - * @param {Object} [lsOptions.options] - ol.control.Control options (see {@link http://openlayers.org/en/latest/apidoc/ol.control.Control.html ol.control.Control}) - * @param {Boolean} [lsOptions.options.collapsed] - Specify if widget has to be collapsed (true) or not (false) on map loading. Default is true. + * @param {Array} [options.layers.config.metadata] - array of layer metadata. Each array element is an object, with property url (String, mandatory) : link to a metadata + * @param {Object} [options.options] - ol.control.Control options (see {@link http://openlayers.org/en/latest/apidoc/ol.control.Control.html ol.control.Control}) + * @param {Boolean} [options.options.collapsed = true] - Specify if widget has to be collapsed (true) or not (false) on map loading. Default is true. * @example * map.addControl(new ol.control.LayerSwitcher( * [ @@ -50,32 +50,32 @@ var logger = Logger.getLogger("layerswitcher"); * )); */ var LayerSwitcher = (function (Control) { - function LayerSwitcher (lsOptions) { - lsOptions = lsOptions || {}; - var options = lsOptions.options || {}; - var layers = lsOptions.layers || []; + function LayerSwitcher (options) { + options = options || {}; + var _options = options.options || {}; + var _layers = options.layers || []; if (!(this instanceof LayerSwitcher)) { throw new TypeError("ERROR CLASS_CONSTRUCTOR"); } - if (layers && !Array.isArray(layers)) { + if (!Array.isArray(_layers)) { throw new Error("ERROR WRONG_TYPE : layers should be an array"); } - if (options && typeof options !== "object") { + if (typeof _options !== "object") { throw new Error("ERROR WRONG_TYPE : options should be an object"); } - this._initialize(options, layers); + this._initialize(_options, _layers); - var container = this._container = this._initContainer(options); + var container = this._container = this._initContainer(_options); // call ol.control.Control constructor Control.call(this, { element : container, - target : options.target, - render : options.render + target : _options.target, + render : _options.render }); } @@ -279,7 +279,7 @@ var LayerSwitcher = (function (Control) { } // user may also add a new configuration for an already added layer - } else if (this._layers[id] && config) { + } else { // add new configuration parameters to layer informations for (var prop in config) { if (config.hasOwnProperty(prop)) { @@ -407,7 +407,6 @@ var LayerSwitcher = (function (Control) { return; } var removalDiv = document.getElementById(this._addUID("GPremove_ID_" + layerID)); - logger.log(removalDiv.style.display); if (removalDiv) { if (removable === false) { removalDiv.style.display = "none"; diff --git a/src/OpenLayers/Controls/LocationSelector.js b/src/OpenLayers/Controls/LocationSelector.js index ea7715963..865a830a9 100644 --- a/src/OpenLayers/Controls/LocationSelector.js +++ b/src/OpenLayers/Controls/LocationSelector.js @@ -799,7 +799,7 @@ var LocationSelector = (function (Control) { options.ssl = true; } } - + logger.log(options); Gp.Services.autoComplete(options); diff --git a/src/OpenLayers/Controls/MeasureToolBox.js b/src/OpenLayers/Controls/MeasureToolBox.js index f10768ac3..89abd149b 100644 --- a/src/OpenLayers/Controls/MeasureToolBox.js +++ b/src/OpenLayers/Controls/MeasureToolBox.js @@ -54,6 +54,7 @@ var MeasureToolBox = { var mapId = mapContainer.id; if (!this._toolbox || Object.keys(this._toolbox).length === 0) { + this._toolbox = {}; this._toolbox[mapId] = ID.generate(); } else { if (!this._toolbox[mapId]) { diff --git a/src/OpenLayers/Controls/MousePosition.js b/src/OpenLayers/Controls/MousePosition.js index d8c0776c0..cba5e212a 100644 --- a/src/OpenLayers/Controls/MousePosition.js +++ b/src/OpenLayers/Controls/MousePosition.js @@ -44,6 +44,12 @@ var logger = Logger.getLogger("GeoportalMousePosition"); * @param {Boolean} [options.ssl = true] - use of ssl or not (default true, service requested using https protocol) * @param {Boolean} [options.draggable = false] - Specify if widget is draggable * @param {Boolean} [options.collapsed = true] - Specify if MousePosition control should be collapsed at startup. Default is true. + * @param {Array} [options.units] - list of coordinates units, to be displayed in control units list. + * Values may be "DEC" (decimal degrees), "DMS" (sexagecimal), "RAD" (radians) and "GON" (grades) for geographical coordinates, + * and "M" or "KM" for metric coordinates + * @param {Boolean} [options.displayAltitude = true] - activate (true) or deactivate (false) the altitude panel. True by default + * @param {Boolean} [options.displayCoordinates = true] - activate (true) or deactivate (false) the coordinates panel. True by default + * @param {Boolean} [options.editCoordinates = false] - If true, coordinates from the MousePosition control can be edited by users to re-center the view. False by default. * @param {Array} [options.systems] - list of projection systems, default are Geographical ("EPSG:4326"), Web Mercator ("EPSG:3857"), Lambert 93 ("EPSG:2154") and extended Lambert 2 ("EPSG:27572"). * Each array element (=system) is an object with following properties : * @param {String} options.systems.crs - Proj4 crs alias (from proj4 defs). e.g. : "EPSG:4326". Required @@ -54,12 +60,6 @@ var logger = Logger.getLogger("GeoportalMousePosition"); * @param {Number} options.systems.geoBBox.left - Left bound. * @param {Number} options.systems.geoBBox.top - Top bound. * @param {Number} options.systems.geoBBox.bottom - Bottom bound. - * @param {Array} [options.units] - list of coordinates units, to be displayed in control units list. - * Values may be "DEC" (decimal degrees), "DMS" (sexagecimal), "RAD" (radians) and "GON" (grades) for geographical coordinates, - * and "M" or "KM" for metric coordinates - * @param {Array} [options.displayAltitude = true] - activate (true) or deactivate (false) the altitude panel. True by default - * @param {Array} [options.displayCoordinates = true] - activate (true) or deactivate (false) the coordinates panel. True by default - * @param {Boolean} [options.editCoordinates = false] - If true, coordinates from the MousePosition control can be edited by users to re-center the view. False by default. * @param {Object} [options.positionMarker] - options for position marker * @param {String} options.positionMarker.url - Marker url (define in src/Openlayers/Controls/Utils/Markers.js) * @param {Array} options.positionMarker.offset - Offsets in pixels used when positioning the marker towards targeted point. @@ -491,8 +491,9 @@ var MousePosition = (function (Control) { */ MousePosition.prototype._initialize = function (options) { // Set default options + options = options || {}; // {Object} control options - set by user or by default - this.options = options || {}; + this.options = options; this.options.collapsed = (options.collapsed !== undefined) ? options.collapsed : true; /** {Boolean} specify if MousePosition control is collapsed (true) or not (false) */ this.collapsed = this.options.collapsed; @@ -1304,7 +1305,7 @@ var MousePosition = (function (Control) { // dans le cas général // callback onSuccess _onSuccess = function (results) { - if (results && Object.keys(results)) { + if (results && Object.keys(results).length) { callback.call(this, results.elevations[0].z); } }; @@ -1369,13 +1370,7 @@ var MousePosition = (function (Control) { // evenement declenché à l'ouverture/fermeture du panneau, // et en fonction du mode : desktop ou tactile ! if (this._showMousePositionContainer.checked) { - if (this._isDesktop) { - // map.un("pointermove", (e) => { this.onMouseMove(e); }); - olObservableUnByKey(this.listenerKey); - } else { - // map.un("moveend", (e) => this.onMapMove(e)); - olObservableUnByKey(this.listenerKey); - } + olObservableUnByKey(this.listenerKey); } else if (!this.editing) { if (this._isDesktop) { this.listenerKey = map.on("pointermove", (e) => { this.onMouseMove(e); }); diff --git a/src/OpenLayers/Controls/ReverseGeocode.js b/src/OpenLayers/Controls/ReverseGeocode.js index 30f0f5e01..9c8f6d6ce 100644 --- a/src/OpenLayers/Controls/ReverseGeocode.js +++ b/src/OpenLayers/Controls/ReverseGeocode.js @@ -342,24 +342,25 @@ var ReverseGeocode = (function (Control) { if (options.resources) { var resources = options.resources; // on vérifie que la liste des ressources de geocodage est bien un tableau - if (!Array.isArray(resources)) { - logger.log("[ReverseGeocode] 'options.resources' parameter should be an array"); - resources = null; - } - var resourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; - var wrongResourcesIndexes = []; - for (i = 0; i < resources.length; i++) { - if (resourcesList.indexOf(resources[i]) === -1) { - // si la resource n'est pas référencée, on stocke son index pour la retirer du tableau (après avoir terminé de parcourir le tableau) - wrongResourcesIndexes.push(i); - logger.log("[ReverseGeocode] options.resources : " + resources[i] + " is not a resource for reverse geocode"); + if (Array.isArray(resources)) { + var resourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; + var wrongResourcesIndexes = []; + for (i = 0; i < resources.length; i++) { + if (resourcesList.indexOf(resources[i]) === -1) { + // si la resource n'est pas référencée, on stocke son index pour la retirer du tableau (après avoir terminé de parcourir le tableau) + wrongResourcesIndexes.push(i); + logger.log("[ReverseGeocode] options.resources : " + resources[i] + " is not a resource for reverse geocode"); + } } - } - // on retire les ressoures non référencées qu'on a pu rencontrer - if (wrongResourcesIndexes.length !== 0) { - for (j = 0; j < wrongResourcesIndexes.length; j++) { - resources.splice(wrongResourcesIndexes[j], 1); + // on retire les ressoures non référencées qu'on a pu rencontrer + if (wrongResourcesIndexes.length !== 0) { + for (j = 0; j < wrongResourcesIndexes.length; j++) { + resources.splice(wrongResourcesIndexes[j], 1); + } } + } else { + logger.log("[ReverseGeocode] 'options.resources' parameter should be an array"); + resources = null; } } @@ -367,24 +368,25 @@ var ReverseGeocode = (function (Control) { if (options.delimitations) { var delimitations = options.delimitations; // on vérifie que la liste des delimitations est bien un tableau - if (!Array.isArray(delimitations)) { - logger.log("[ReverseGeocode] 'options.delimitations' parameter should be an array"); - delimitations = null; - } - var delimitationsList = ["Circle", "Point", "Extent"]; - var wrongDelimitationsIndexes = []; - for (i = 0; i < delimitations.length; i++) { - if (delimitationsList.indexOf(delimitations[i]) === -1) { - // si la delimitations n'est pas référencée, on stocke son index pour la retirer du tableau (après avoir terminé de parcourir le tableau) - wrongDelimitationsIndexes.push(i); - logger.log("[ReverseGeocode] options.delimitations : " + delimitations[i] + " is not a delimitation for reverse geocode"); + if (Array.isArray(delimitations)) { + var delimitationsList = ["Circle", "Point", "Extent"]; + var wrongDelimitationsIndexes = []; + for (i = 0; i < delimitations.length; i++) { + if (delimitationsList.indexOf(delimitations[i]) === -1) { + // si la delimitations n'est pas référencée, on stocke son index pour la retirer du tableau (après avoir terminé de parcourir le tableau) + wrongDelimitationsIndexes.push(i); + logger.log("[ReverseGeocode] options.delimitations : " + delimitations[i] + " is not a delimitation for reverse geocode"); + } } - } - // on retire les ressoures non référencées qu'on a pu rencontrer - if (wrongDelimitationsIndexes.length !== 0) { - for (j = 0; j < wrongDelimitationsIndexes.length; j++) { - delimitations.splice(wrongDelimitationsIndexes[j], 1); + // on retire les ressoures non référencées qu'on a pu rencontrer + if (wrongDelimitationsIndexes.length !== 0) { + for (j = 0; j < wrongDelimitationsIndexes.length; j++) { + delimitations.splice(wrongDelimitationsIndexes[j], 1); + } } + } else { + logger.log("[ReverseGeocode] 'options.delimitations' parameter should be an array"); + delimitations = null; } } }; @@ -541,9 +543,7 @@ var ReverseGeocode = (function (Control) { this.options.apiKey = rightManagementGeocode.key; } - if (rightManagementGeocode) { - this._servicesRightManagement["Geocode"] = rightManagementGeocode["Geocode"]; - } + this._servicesRightManagement["Geocode"] = rightManagementGeocode["Geocode"]; }; /** @@ -1358,7 +1358,7 @@ var ReverseGeocode = (function (Control) { // récupération de la position var position = [location.position.x, location.position.y]; - if (!position) { + if (position.length === 0) { return; } var view = map.getView(); diff --git a/src/OpenLayers/Controls/Route.js b/src/OpenLayers/Controls/Route.js index a9768e165..03fca9891 100644 --- a/src/OpenLayers/Controls/Route.js +++ b/src/OpenLayers/Controls/Route.js @@ -44,13 +44,13 @@ var logger = Logger.getLogger("route"); * @param {Boolean} [options.ssl = true] - use of ssl or not (default true, service requested using https protocol) * @param {Boolean} [options.collapsed = true] - Specify if widget has to be collapsed (true) or not (false) on map loading. Default is true. * @param {Boolean} [options.draggable = false] - Specify if widget is draggable - * @param {Object} [options.exclusions = {toll : false, tunnel : false, bridge : false}] - list of exclusions with status (true = checked). By default : no exclusions checked. + * @param {Object} [options.exclusions = {"toll" : false, "tunnel" : false, "bridge" : false}] - list of exclusions with status (true = checked). By default : no exclusions checked. * @param {Array} [options.graphs = ["Voiture", "Pieton"]] - list of resources, by default : ["Voiture", "Pieton"]. The first element is selected. - * @param {Object} [options.markersOpts] - options to use your own markers. Object properties can be "departure", "stages" or "arrival". Corresponding value is an object with following properties : - * @param {String} [options.markersOpts[property].url] - marker base64 encoded url (ex "data:image/png;base64,...""). Mandatory for a custom marker - * @param {Array} [options.markersOpts[property].offset] - Offsets in pixels used when positioning the overlay. The first element in the array is the horizontal offset. A positive value shifts the overlay right. The second element in the array is the vertical offset. A positive value shifts the overlay down. Default is [0, 0]. (see http://openlayers.org/en/latest/apidoc/ol.Overlay.html) * @param {Object} [options.routeOptions = {}] - route service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~route Gp.Services.route()} to know all route options. * @param {Object} [options.autocompleteOptions = {}] - autocomplete service options. see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~autoComplete Gp.Services.autoComplete()} to know all autocomplete options + * @param {Object} [options.markersOpts] - options to use your own markers. Object properties can be "departure", "stages" or "arrival". Corresponding value is an object with following properties : + * @param {String} [options.markersOpts.url] - marker base64 encoded url (ex "data:image/png;base64,...""). Mandatory for a custom marker + * @param {Array} [options.markersOpts.offset] - Offsets in pixels used when positioning the overlay. The first element in the array is the horizontal offset. A positive value shifts the overlay right. The second element in the array is the vertical offset. A positive value shifts the overlay down. Default is [0, 0]. (see http://openlayers.org/en/latest/apidoc/ol.Overlay.html) * @param {Object} [options.layerDescription = {}] - Layer informations to be displayed in LayerSwitcher widget (only if a LayerSwitcher is also added to the map) * @param {String} [options.layerDescription.title = "Itinéraire"] - Layer title to be displayed in LayerSwitcher * @param {String} [options.layerDescription.description = "Itinéraire basé sur un graphe"] - Layer description to be displayed in LayerSwitcher @@ -353,23 +353,19 @@ var Route = (function (Control) { // vérification des options // mode de transport if (options.graphs) { - if (Array.isArray(options.graphs)) { - // on ne permet pas de passer un tableau vide : on spécifie au moins un graph - if (options.graphs.length === 0) { - options.graphs = null; - } else { - for (var i = 0; i < options.graphs.length; i++) { - if (typeof options.graphs[i] !== "string") { - logger.log("[ol.control.Route] ERROR : parameter 'graphs' elements should be of type 'string'"); - options.graphs = null; - } else { - if (options.graphs[i].toLowerCase() === "pieton") { - options.graphs[i] = "Pieton"; - } - if (options.graphs[i].toLowerCase() === "voiture") { - options.graphs[i] = "Voiture"; - } + // on ne permet pas de passer un tableau vide : on spécifie au moins un graph + if (Array.isArray(options.graphs) && options.graphs.length) { + for (var i = 0; i < options.graphs.length; i++) { + if (typeof options.graphs[i] === "string") { + if (options.graphs[i].toLowerCase() === "pieton") { + options.graphs[i] = "Pieton"; + } + if (options.graphs[i].toLowerCase() === "voiture") { + options.graphs[i] = "Voiture"; } + } else { + logger.log("[ol.control.Route] ERROR : parameter 'graphs' elements should be of type 'string'"); + options.graphs[i] = null; } } } else { @@ -1686,7 +1682,7 @@ var Route = (function (Control) { var bridgeInput = document.getElementById("GProuteExclusionsBridge-" + this._uid); if (bridgeInput) { - if (this._currentExclusions.indexOf("bridge") !== -1 && bridgeInput) { + if (this._currentExclusions.indexOf("bridge") !== -1) { bridgeInput.checked = false; } else { bridgeInput.checked = true; diff --git a/src/OpenLayers/Controls/SearchEngine.js b/src/OpenLayers/Controls/SearchEngine.js index 479ff972b..16997435d 100644 --- a/src/OpenLayers/Controls/SearchEngine.js +++ b/src/OpenLayers/Controls/SearchEngine.js @@ -29,33 +29,33 @@ var logger = Logger.getLogger("searchengine"); * @param {String} [options.apiKey] - API key, mandatory if autoconf service has not been charged in advance * @param {Boolean} [options.ssl = true] - use of ssl or not (default true, service requested using https protocol) * @param {Boolean} [options.collapsed = true] - collapse mode, true by default - * @param {Object} [options.resources] - resources to be used by geocode and autocompletion services : + * @param {String|Numeric|Function} [options.zoomTo] - zoom to results, by default, current zoom. + * Value possible : auto or zoom level. + * Possible to overload it with a function : + * zoomTo : function (info) { + * // do some stuff... + * return zoom; + * } + * @param {String} [options.placeholder] - Placeholder in search bar. Default is "Rechercher un lieu, une adresse". + * @param {Boolean} [options.displayMarker = true] - set a marker on search result, defaults to true. + * @param {String} [options.markerStyle = "lightOrange"] - Marker style. Currently possible values are "lightOrange" (default value), "darkOrange", "red" and "turquoiseBlue". + * @param {Boolean} [options.displayAdvancedSearch = true] - False to disable advanced search tools (it will not be displayed). Default is true (displayed) + * @param {Object} [options.advancedSearch] - advanced search options for geocoding (filters). Properties can be found among geocode options.filterOptions (see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~geocode Gp.Services.geocode}) + * @param {Object} [options.resources] - resources to be used by geocode and autocompletion services : * @param {Array} [options.resources.geocode] - resources geocoding, by default : ["PositionOfInterest", "StreetAddress"] * @param {Array} [options.resources.autocomplete] - resources autocompletion, by default : ["PositionOfInterest", "StreetAddress"] - * @param {Boolean} [options.displayAdvancedSearch = true] - False to disable advanced search tools (it will not be displayed). Default is true (displayed) - * @param {Object} [options.advancedSearch] - advanced search options for geocoding (filters). Properties can be found among geocode options.filterOptions (see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~geocode Gp.Services.geocode}) * @param {Object} [options.geocodeOptions = {}] - options of geocode service * @param {Object} [options.geocodeOptions.apiKey] - to overload the check of rights (only) on the given apiKey for the geocode service * @param {Object} [options.geocodeOptions.filterOptions = {}] - filteroptions of the geocode service - * @param {Array} [options.geocodeOptions.filterOptions.type = []] - to overload the check of rights (only) on the given type of resources used by the geocode service. + * @param {Array} [options.geocodeOptions.filterOptions.type = []] - to overload the check of rights (only) on the given type of resources used by the geocode service. * @param {Object} [options.geocodeOptions.serviceOptions] - overload other options : options of geocode service from the access-lib API (see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~geocode Gp.Services.geocode}) * @param {Object} [options.autocompleteOptions = {}] - options of autocomplete service * @param {Object} [options.autocompleteOptions.apiKey] - to overload the check of rights (only) on the given apiKey for the the autocomplete service * @param {Object} [options.autocompleteOptions.filterOptions = {}] - filteroptions of the autocomplete service - * @param {Array} [options.autocompleteOptions.filterOptions.type = []] - to overload the check of rights (only) on the given type of resources used by the autocomplete service + * @param {Array} [options.autocompleteOptions.filterOptions.type = []] - to overload the check of rights (only) on the given type of resources used by the autocomplete service * @param {Object} [options.autocompleteOptions.serviceOptions] - overload other options : options of autocomplete service from the access-lib API (see {@link http://ignf.github.io/geoportal-access-lib/latest/jsdoc/module-Services.html#~autoComplete Gp.Services.autoComplete}) * @param {Boolean} [options.autocompleteOptions.triggerGeocode = false] - trigger a geocoding request if the autocompletion does not return any suggestions, false by default * @param {Number} [options.autocompleteOptions.triggerDelay = 1000] - waiting time before sending the geocoding request, 1000ms by default - * @param {String|Numeric|Function} [options.zoomTo] - zoom to results, by default, current zoom. - * Value possible : auto or zoom level. - * Possible to overload it with a function : - * zoomTo : function (info) { - * // do some stuff... - * return zoom; - * } - * @param {String} [options.placeholder] - Placeholder in search bar. Default is "Rechercher un lieu, une adresse". - * @param {Boolean} [options.displayMarker = true] - set a marker on search result, defaults to true. - * @param {String} [options.markerStyle = "lightOrange"] - Marker style. Currently possible values are "lightOrange" (default value), "darkOrange", "red" and "turquoiseBlue". * @example * var SearchEngine = ol.control.SearchEngine({ * apiKey : "CLEAPI", @@ -161,11 +161,8 @@ var SearchEngine = (function (Control) { if ((collapsed && this.collapsed) || (!collapsed && !this.collapsed)) { return; } - if (collapsed) { - this._showSearchEngineInput.click(); - } else { - this._showSearchEngineInput.click(); - } + + this._showSearchEngineInput.click(); this.collapsed = collapsed; }; @@ -305,36 +302,38 @@ var SearchEngine = (function (Control) { var geocodeResources = options.resources.geocode; if (geocodeResources) { // on vérifie que la liste des ressources de geocodage est bien un tableau - if (!Array.isArray(geocodeResources)) { + if (Array.isArray(geocodeResources)) { + var geocodeResourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; + for (i = 0; i < geocodeResources.length; i++) { + if (geocodeResourcesList.indexOf(geocodeResources[i]) === -1) { + // si la resource n'est pas référencée, on l'enlève + // geocodeResources.splice(i, 1); + logger.log("[SearchEngine] options.resources.geocode : " + geocodeResources[i] + " is not a resource for geocode"); + } + } + } else { logger.log("[SearchEngine] 'options.resources.geocode' parameter should be an array"); geocodeResources = null; } - var geocodeResourcesList = ["StreetAddress", "PositionOfInterest", "CadastralParcel", "Administratif"]; - for (i = 0; i < geocodeResources.length; i++) { - if (geocodeResourcesList.indexOf(geocodeResources[i]) === -1) { - // si la resource n'est pas référencée, on l'enlève - // geocodeResources.splice(i, 1); - logger.log("[SearchEngine] options.resources.geocode : " + geocodeResources[i] + " is not a resource for geocode"); - } - } } // ressources d'autocompletion var autocompleteResources = options.resources.autocomplete; if (autocompleteResources) { // on vérifie que la liste des ressources d'autocompletion est bien un tableau - if (!Array.isArray(autocompleteResources)) { + if (Array.isArray(autocompleteResources)) { + var autocompleteResourcesList = ["StreetAddress", "PositionOfInterest"]; + for (i = 0; i < autocompleteResources.length; i++) { + if (autocompleteResourcesList.indexOf(autocompleteResources[i]) === -1) { + // si la resource n'est pas référencée, on l'enlève + // autocompleteResources.splice(i, 1); + logger.log("[SearchEngine] options.resources.autocomplete : " + autocompleteResources[i] + " is not a resource for autocomplete"); + } + } + } else { logger.log("[SearchEngine] 'options.resources.autocomplete' parameter should be an array"); autocompleteResources = null; } - var autocompleteResourcesList = ["StreetAddress", "PositionOfInterest"]; - for (i = 0; i < autocompleteResources.length; i++) { - if (autocompleteResourcesList.indexOf(autocompleteResources[i]) === -1) { - // si la resource n'est pas référencée, on l'enlève - // autocompleteResources.splice(i, 1); - logger.log("[SearchEngine] options.resources.autocomplete : " + autocompleteResources[i] + " is not a resource for autocomplete"); - } - } } } else { logger.log("[SearchEngine] 'resources' parameter should be an object"); diff --git a/src/OpenLayers/Formats/KML.js b/src/OpenLayers/Formats/KML.js index c73f1ea58..e88808b86 100644 --- a/src/OpenLayers/Formats/KML.js +++ b/src/OpenLayers/Formats/KML.js @@ -517,9 +517,9 @@ var KML = (function (olKML) { x = anchor[0]; y = anchor[1]; if (yunits === "fraction") { - y = (anchor[1] === 1) ? 0 : 1 - anchor[1]; // cf. fixme contribution à faire ! + y = (y === 1) ? 0 : 1 - y; // cf. fixme contribution à faire ! } else { - y = (yunits === "pixels" && anchor[1] === size[1]) ? 0 : size[1] - anchor[1]; // cf. fixme contribution à faire ! + y = (yunits === "pixels" && y === size[1]) ? 0 : size[1] - y; // cf. fixme contribution à faire ! } } @@ -570,7 +570,7 @@ var KML = (function (olKML) { var kmlStringExtended = _kmlToString(kmlDoc); // au cas où... - if (kmlStringExtended === null) { + if (!kmlStringExtended) { kmlStringExtended = kmlString; } @@ -578,7 +578,7 @@ var KML = (function (olKML) { var kmlStringFormatted = _kmlFormattedToString(kmlStringExtended); // au cas où... - if (kmlStringFormatted === null) { + if (kmlStringFormatted === "") { kmlStringFormatted = kmlString; } diff --git a/src/OpenLayers/Sources/WMTS.js b/src/OpenLayers/Sources/WMTS.js index 24a782e71..c399d9653 100644 --- a/src/OpenLayers/Sources/WMTS.js +++ b/src/OpenLayers/Sources/WMTS.js @@ -57,7 +57,7 @@ var WMTS = (function (WMTSSource) { * @return {String|undefined} GetFeatureInfo URL. */ WMTS.prototype.getGetFeatureInfoUrl = function (coordinate, resolution, projection, params) { - var pixelRatio = (this.option && this.options.tilePixelRatio) ? this.options.tilePixelRatio : 1; + var pixelRatio = (this.options && this.options.tilePixelRatio) ? this.options.tilePixelRatio : 1; var tileGrid = this.tileGrid; var tileCoord = this.tileGrid.getTileCoordForCoordAndResolution(coordinate, resolution); @@ -69,10 +69,9 @@ var WMTS = (function (WMTSSource) { var x = tileCoord[1]; var y = -tileCoord[2] - 1; // FIXME : v6.0.0, on utilise "var y = tileCoord[2];" var tileExtent = tileGrid.getTileCoordExtent(tileCoord); - var projectionExtent = projection.getExtent(); - var extent = projectionExtent; + var extent = projection.getExtent(); - if (extent != null && projection.isGlobal() && extent[0] === projectionExtent[0] && extent[2] === projectionExtent[2]) { + if (extent != null && projection.isGlobal()) { var numCols = Math.ceil(olGetWidth(extent) / olGetWidth(tileExtent)); x = x % numCols; tmpTileCoord[0] = tileCoord[0]; diff --git a/test/spec/Common/test-common-utils.js b/test/spec/Common/test-common-utils.js new file mode 100644 index 000000000..774d50223 --- /dev/null +++ b/test/spec/Common/test-common-utils.js @@ -0,0 +1,154 @@ +/* global describe, it */ +import Utils from "../../../src/Common/Utils"; + +import { assert, expect, should } from "chai"; +should(); + +describe("-- Test Utils --", function () { + + describe("#mergeParams", function () { + it('merge to null value returns value', function () { + var settings_default = { + a : null + }; + var settings_user = { + a : 1 + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + a : 1 + })); + }); + + it('merge from null value returns value', function () { + var settings_default = { + a : 1 + }; + var settings_user = { + a : null + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + a : 1 + })); + }); + + it('merge to undefined value returns value', function () { + var settings_default = { + b : undefined + }; + var settings_user = { + b : 2 + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + b : 2 + })); + }); + + it('merge from undefined value returns undefined', function () { + var settings_default = { + b : 2 + }; + var settings_user = { + b : undefined + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + b : undefined + })); + }); + + it('merge to {undefined} value returns {value}', function () { + var settings_default = { + c : {} + }; + var settings_user = { + c : { a:1 } + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + c : { a:1 } + })); + }); + + it('merge from {undefined} value returns {value}', function () { + var settings_default = { + c : { a:1 } + }; + var settings_user = { + c : {} + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + c : { a:1 } + })); + }); + + it('merge to {} value concats object', function () { + var settings_default = { + c : { a:1, b:0, d:4 } + }; + var settings_user = { + c : { a:1, b:2, c:3 } + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + c : { a:1, b:2, d:4, c:3 } + })); + }); + + it('merge to [undefined] value returns [value]', function () { + var settings_default = { + d : [] + }; + var settings_user = { + d : [1,2,3] + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + d : [1,2,3] + })); + }); + + it('merge from [undefined] value returns [value]', function () { + var settings_default = { + d : [1,2,3] + }; + var settings_user = { + d : [] + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + d : [1,2,3] + })); + }); + + it('merge to [] value does not concat array ', function () { + var settings_default = { + d : [1,2,3] + }; + var settings_user = { + d : [4,5,6] + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + d : [4,5,6] + })); + }); + + it('merge from [] with null value concats array ', function () { + var settings_default = { + d : [1,2,3] + }; + var settings_user = { + d : [null,5,null,7] + }; + Utils.mergeParams(settings_default, settings_user); + expect(JSON.stringify(settings_default)).to.be.equal(JSON.stringify({ + d : [1,5,3,7] + })); + }); + }); + +});