From 6649079de91774ece3899e3f0a6f91c0dd715d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 23 Jan 2019 09:29:24 +0100 Subject: [PATCH 1/2] Fix types in profile --- contribs/gmf/src/profile/component.js | 6 +- src/profile/d3Elevation.js | 103 ++++++++------------------ src/profile/elevationComponent.js | 54 +++++++++++++- 3 files changed, 84 insertions(+), 79 deletions(-) diff --git a/contribs/gmf/src/profile/component.js b/contribs/gmf/src/profile/component.js index 5b35d7a20755..5b558a241b39 100644 --- a/contribs/gmf/src/profile/component.js +++ b/contribs/gmf/src/profile/component.js @@ -108,7 +108,7 @@ function gmfProfileTemplateUrl($element, $attrs, gmfProfileTemplateUrl) { * @htmlAttribute {number?} gmf-profile-numberofpoints Optional maximum limit of * points to request. Default to 100. * @htmlAttribute {Object.?} gmf-profile-options Optional options - * object like {@link ProfileOptions} but without any + * object like {@link import('ngeo/profile/elevationComponent.js').ProfileOptions} but without any * mandatory value. Will be passed to the ngeo profile component. Providing * 'linesConfiguration', 'distanceExtractor', hoverCallback, outCallback * or i18n will override native gmf profile values. @@ -288,7 +288,7 @@ function Controller($scope, $http, $element, $filter, /** - * @type {?ProfileOptions} + * @type {?import('ngeo/profile/elevationComponent.js').ProfileOptions} * @export */ this.profileOptions = null; @@ -371,7 +371,7 @@ Controller.prototype.$onInit = function() { } } - this.profileOptions = /** @type {ProfileOptions} */ ({ + this.profileOptions = /** @type {import('ngeo/profile/elevationComponent.js').ProfileOptions} */ ({ linesConfiguration: this.linesConfiguration_, distanceExtractor: this.getDist_, hoverCallback: this.hoverCallback_.bind(this), diff --git a/src/profile/d3Elevation.js b/src/profile/d3Elevation.js index c36999876b75..7b16f3b1ec2f 100644 --- a/src/profile/d3Elevation.js +++ b/src/profile/d3Elevation.js @@ -11,56 +11,6 @@ import { } from 'd3'; -/** - * @typedef {Object} I18n - * @property {string} [xAxis] Text for the x axis. Will be completed by ` km` or ' m' (for kilometers or meters). - * @property {string} [yAxis] Text for the y axis. Will be completed by ' m' (for meters). - */ - - -/** - * Configuration object for one profile's line. - * - * @typedef {Object} LineConfiguration - * @property {string} [color] Color of the line (hex color string). - * @property {!function(Object): number} zExtractor Extract the elevation of a point (an item of the - * elevation data array). - */ - - -/** - * Options for the profile. - * - * @typedef {Object} ProfileOptions - * @property {string} [styleDefs] Inline CSS style definition to inject in the SVG. - * @property {number} [poiLabelAngle] Inline CSS style definition to inject in the SVG. - * @property {ProfileFormatter} [formatter] Formatter giving full control on how numbers are formatted. - * @property {function(Object): number} distanceExtractor Extract the distance from origin of a point (an - * item of the elevation data array). - * @property {!Object.} linesConfiguration Configuration object for the profile's - * lines. The key string of each object is used as class for its respective svg line. - * @property {PoiExtractor} [poiExtractor] Extractor for parsing POI data. - * @property {boolean} [light] Show a simplified profile when true. - * @property {boolean} [lightXAxis] Show a simplified x axis with only both end ticks. - * @property {function(function(), function(), number, number)} [scaleModifier] Allows to modify the raw x - * and y scales. Notably, it is possible to modify the y domain according to XY ratio rules, - * add padding or enforce y lower bound. - * @property {function(Object)} [hoverCallback] A callback called from the profile when the mouse moves over - * a point. The point, an item of the elevation data array, is passed as the first argument of the function. - * @property {function()} [outCallback] A callback called from the profile when the mouse leaves the profile. - * @property {I18n} [i18n] - */ - - -/** - * @typedef {Object} ProfileFormatter - * @property {function(number, string): string} xhover Format the xhover distance. - * @property {function(number, string): string} yhover Format the yhover elevation. - * @property {function(number, string): (string|number)} xtick Format the xtick, for graduating the x axis. - * @property {function(number, string): (string|number)} ytick Format the ytick, for graduating the y axis. - */ - - /** * Provides a D3js component to be used to draw an elevation * profile chart. @@ -110,7 +60,7 @@ import { * ] * * @return {Object} D3js component. - * @param {ProfileOptions} options Profile options. + * @param {import('ngeo/profile/elevationComponent.js').ProfileOptions} options Profile options. * @export */ function d3Elevation(options) { @@ -129,17 +79,15 @@ function d3Elevation(options) { /** * Hover callback function. - * @type {function(Object, number, string, Object., string)} + * @type {function(Object, number, string, Object., string): void} */ - const hoverCallback = options.hoverCallback !== undefined ? - options.hoverCallback : () => {}; + const hoverCallback = options.hoverCallback !== undefined ? options.hoverCallback : () => {}; /** * Out callback function. - * @type {function()} + * @type {function} */ - const outCallback = options.outCallback !== undefined ? - options.outCallback : () => {}; + const outCallback = options.outCallback !== undefined ? options.outCallback : () => {}; /** * Distance data extractor used to get the dist values. @@ -193,7 +141,7 @@ function d3Elevation(options) { const yAxisLabel = (i18n.yAxis || 'Elevation'); /** - * @type {ProfileFormatter} + * @type {import('ngeo/profile/elevationComponent.js').ProfileFormatter} */ const formatter = { /** @@ -239,7 +187,6 @@ function d3Elevation(options) { */ const lightXAxis = options.lightXAxis !== undefined ? options.lightXAxis : false; - // Objects shared with the showPois function /** * @type {Object} */ @@ -247,43 +194,54 @@ function d3Elevation(options) { /** * D3 x scale. + * @type {import('d3').ScaleLinear} */ let x; /** * D3 y scale. + * @type {import('d3').ScaleLinear} */ let y; /** * Scale modifier to allow customizing the x and y scales. + * @type {function(function, function, number, number): void} */ const scaleModifier = options.scaleModifier; + /** + * @type {import('d3').Selection} + */ let g; /** * Height of the chart in pixels + * @type {number} */ let height; /** * Width of the chart in pixels + * @type {number} */ let width; /** - * Factor to determine whether to use 'm' or 'km'. - */ + * Factor to determine whether to use 'm' or 'km'. + * @type {number} + */ let xFactor; /** - * Distance units. Either 'm' or 'km'. - */ + * Distance units. Either 'm' or 'km'. + * @type {string} + */ let xUnits; /** * D3 extent of the distance. + * @type {[number, number]} */ let xDomain; @@ -301,7 +259,9 @@ function d3Elevation(options) { height = Math.max(this.clientHeight - margin.top - margin.bottom, 0); y = d3scaleLinear().range([height, 0]); + /** @type {import('d3').Axis} */ const xAxis = d3axisBottom(x); + /** @type {import('d3').Axis} */ const yAxis = d3axisLeft(y); let area; @@ -316,7 +276,7 @@ function d3Elevation(options) { } // Select the svg element, if it exists. - svg = d3select(this).selectAll('svg').data([data]); + let svg = d3select(this).selectAll('svg').data([data]); // Otherwise, create the skeletal chart. const svgEnter = svg.enter().append('svg'); // Then select it again to get the complete object. @@ -456,21 +416,16 @@ function d3Elevation(options) { .attr('d', line); } - if (xDomain[1] > 2000) { - xFactor = 1000; - xUnits = 'km'; - } else { - xFactor = 1; - xUnits = 'm'; - } + xFactor = xDomain[1] > 2000 ? 1000 : 1; + xUnits = xDomain[1] > 2000 ? 'km' : 'm'; if (!light) { - xAxis.tickFormat(d => formatter.xtick(d / xFactor, xUnits)); + xAxis.tickFormat((domainValue) => /** @type {string} */(formatter.xtick(/** @type {number} */(domainValue) / xFactor, xUnits))); if (lightXAxis) { xAxis.tickValues([0, x.domain()[1]]); } - yAxis.tickFormat(d => formatter.ytick(d, 'm')); + yAxis.tickFormat((dommainValue) => /** @type {string} */(formatter.ytick(/** @type {number} */(dommainValue), 'm'))); g.select('.x.axis') .transition() @@ -493,7 +448,7 @@ function d3Elevation(options) { g.select('.grid-y') .transition() - .call(yAxis.tickSize(-width, 0).tickFormat('')) + .call(yAxis.tickSize(-width).tickFormat(null)) .selectAll('.tick line') .style('stroke', '#ccc') .style('opacity', 0.7); diff --git a/src/profile/elevationComponent.js b/src/profile/elevationComponent.js index 534ca1479b1e..c8092f3d1597 100644 --- a/src/profile/elevationComponent.js +++ b/src/profile/elevationComponent.js @@ -19,6 +19,56 @@ import {select as d3select} from 'd3'; */ +/** + * Configuration object for one profile's line. + * + * @typedef {Object} LineConfiguration + * @property {string} [color] Color of the line (hex color string). + * @property {!function(Object): number} zExtractor Extract the elevation of a point (an item of the + * elevation data array). + */ + + +/** + * @typedef {Object} ProfileFormatter + * @property {function(number, string): string} xhover Format the xhover distance. + * @property {function(number, string): string} yhover Format the yhover elevation. + * @property {function(number, string): (string|number)} xtick Format the xtick, for graduating the x axis. + * @property {function(number, string): (string|number)} ytick Format the ytick, for graduating the y axis. + */ + + +/** + * @typedef {Object} I18n + * @property {string} [xAxis] Text for the x axis. Will be completed by ` km` or ' m' (for kilometers or meters). + * @property {string} [yAxis] Text for the y axis. Will be completed by ' m' (for meters). + */ + + +/** + * Options for the profile. + * + * @typedef {Object} ProfileOptions + * @property {string} [styleDefs] Inline CSS style definition to inject in the SVG. + * @property {number} [poiLabelAngle] Inline CSS style definition to inject in the SVG. + * @property {ProfileFormatter} [formatter] Formatter giving full control on how numbers are formatted. + * @property {function(Object): number} distanceExtractor Extract the distance from origin of a point (an + * item of the elevation data array). + * @property {!Object.} linesConfiguration Configuration object for the profile's + * lines. The key string of each object is used as class for its respective svg line. + * @property {PoiExtractor} [poiExtractor] Extractor for parsing POI data. + * @property {boolean} [light] Show a simplified profile when true. + * @property {boolean} [lightXAxis] Show a simplified x axis with only both end ticks. + * @property {function(function(), function(), number, number)} [scaleModifier] Allows to modify the raw x + * and y scales. Notably, it is possible to modify the y domain according to XY ratio rules, + * add padding or enforce y lower bound. + * @property {function(Object)} [hoverCallback] A callback called from the profile when the mouse moves over + * a point. The point, an item of the elevation data array, is passed as the first argument of the function. + * @property {function()} [outCallback] A callback called from the profile when the mouse leaves the profile. + * @property {I18n} [i18n] + */ + + /** * @type {!angular.IModule} */ @@ -74,8 +124,8 @@ function directive(ngeoDebounce) { scope.$watchCollection(optionsAttr, (newVal) => { - const options = /** @type {ProfileOptions} */ - (Object.assign({}, newVal)); + /** @type {ProfileOptions} */ + const options = Object.assign({}, newVal); if (options !== undefined) { From 55c3a482305f6d526674b4b6bd0ba8e22c09735a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Wed, 23 Jan 2019 10:35:13 +0100 Subject: [PATCH 2/2] Fix types in print --- contribs/gmf/src/print/component.js | 4 +- contribs/gmf/src/search/component.js | 12 +- examples/mapfishprint.js | 4 +- src/map/LayerHelper.js | 2 +- src/print/Service.js | 65 ++++----- src/print/Utils.js | 6 +- src/print/VectorEncoder.js | 62 +++++---- src/print/mapfish-print-v3.js | 187 ++++++++++++++++++++++++++ src/profile/d3Elevation.js | 1 + src/search/createGeoJSONBloodhound.js | 2 +- test/spec/services/print.spec.js | 4 +- 11 files changed, 272 insertions(+), 77 deletions(-) create mode 100644 src/print/mapfish-print-v3.js diff --git a/contribs/gmf/src/print/component.js b/contribs/gmf/src/print/component.js index e2cc55f39178..89e451979c5d 100644 --- a/contribs/gmf/src/print/component.js +++ b/contribs/gmf/src/print/component.js @@ -1100,7 +1100,7 @@ class Controller { * @private */ handleCreateReportSuccess_(resp) { - const mfResp = /** @type {MapFishPrintReportResponse} */ (resp.data); + const mfResp = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintReportResponse} */ (resp.data); const ref = mfResp.ref; console.assert(ref.length > 0); this.curRef_ = ref; @@ -1129,7 +1129,7 @@ class Controller { * @private */ handleGetStatusSuccess_(ref, resp) { - const mfResp = /** @type {MapFishPrintStatusResponse} */ (resp.data); + const mfResp = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintStatusResponse} */ (resp.data); const done = mfResp.done; if (done) { if (mfResp.status != 'error') { diff --git a/contribs/gmf/src/search/component.js b/contribs/gmf/src/search/component.js index 27331f3e3151..d2592305c02c 100644 --- a/contribs/gmf/src/search/component.js +++ b/contribs/gmf/src/search/component.js @@ -617,7 +617,7 @@ class SearchController { /** * @param {SearchComponentDatasource} config The config of the dataset. - * @param {(function(GeoJSONFeature): boolean)=} opt_filter A filter function + * @param {(function(import("geojson").Feature): boolean)=} opt_filter A filter function * based on a GeoJSONFeaturesCollection's array. * @return {Twitter.Typeahead.Dataset} A typeahead dataset. * @private @@ -667,14 +667,14 @@ class SearchController { /** * @param {string} action The action to keep. - * @return {(function(GeoJSONFeature): boolean)} A filter function based on a + * @return {(function(import("geojson").Feature): boolean)} A filter function based on a * GeoJSONFeaturesCollection's array. * @private */ filterAction_(action) { return ( /** - * @param {GeoJSONFeature} feature + * @param {import("geojson").Feature} feature * @return {boolean} */ function(feature) { @@ -694,14 +694,14 @@ class SearchController { /** * @param {string=} opt_layerName The layerName to keep. If null, keep all layers * (In all cases, except actions layers). - * @return {(function(GeoJSONFeature): boolean)} A filter function based on a + * @return {(function(import("geojson").Feature): boolean)} A filter function based on a * GeoJSONFeaturesCollection's array. * @private */ filterLayername_(opt_layerName) { return ( /** - * @param {GeoJSONFeature} feature + * @param {import("geojson").Feature} feature * @return {boolean} */ function(feature) { @@ -721,7 +721,7 @@ class SearchController { /** * @param {SearchComponentDatasource} config The config of the dataset. - * @param {(function(GeoJSONFeature): boolean)=} opt_filter Afilter function + * @param {(function(import("geojson").Feature): boolean)=} opt_filter Afilter function * based on a GeoJSONFeaturesCollection's array. * @return {Bloodhound} The bloodhound engine. * @private diff --git a/examples/mapfishprint.js b/examples/mapfishprint.js index 0bc9e237d701..5de3f8f23fe9 100644 --- a/examples/mapfishprint.js +++ b/examples/mapfishprint.js @@ -195,7 +195,7 @@ MainController.prototype.print = function() { * @private */ MainController.prototype.handleCreateReportSuccess_ = function(resp) { - const mfResp = /** @type {MapFishPrintReportResponse} */ (resp.data); + const mfResp = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintReportResponse} */ (resp.data); this.getStatus_(mfResp.ref); }; @@ -227,7 +227,7 @@ MainController.prototype.handleCreateReportError_ = function(resp) { * @private */ MainController.prototype.handleGetStatusSuccess_ = function(ref, resp) { - const mfResp = /** @type {MapFishPrintStatusResponse} */ (resp.data); + const mfResp = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintStatusResponse} */ (resp.data); const done = mfResp.done; if (done) { // The report is ready. Open it by changing the window location. diff --git a/src/map/LayerHelper.js b/src/map/LayerHelper.js index e57601ca8211..3f85da03e155 100644 --- a/src/map/LayerHelper.js +++ b/src/map/LayerHelper.js @@ -23,7 +23,7 @@ import {ServerType} from 'ngeo/datasource/OGC.js'; * @ngname ngeoLayerHelper * @ngInject */ -function LayerHelper($q, $http, ngeoTilesPreloadingLimit) { +export function LayerHelper($q, $http, ngeoTilesPreloadingLimit) { /** * @type {angular.IQService} diff --git a/src/print/Service.js b/src/print/Service.js index 62e640039587..adf368f11e6d 100644 --- a/src/print/Service.js +++ b/src/print/Service.js @@ -14,7 +14,7 @@ import olTilegridWMTS from 'ol/tilegrid/WMTS.js'; /** - * @typedef {function(string):!import("ngeo/print/Service.js").default} CreatePrint + * @typedef {function(string):!PrintService} CreatePrint */ @@ -59,7 +59,7 @@ import olTilegridWMTS from 'ol/tilegrid/WMTS.js'; * @param {string} url URL to MapFish print web service. * @param {angular.IHttpService} $http Angular $http service. * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext service. - * @param {import("ngeo/map/LayerHelper.js").default} ngeoLayerHelper Ngeo Layer Helper service. + * @param {import("ngeo/map/LayerHelper.js").LayerHelper} ngeoLayerHelper Ngeo Layer Helper service. */ export function PrintService(url, $http, gettextCatalog, ngeoLayerHelper) { /** @@ -81,7 +81,7 @@ export function PrintService(url, $http, gettextCatalog, ngeoLayerHelper) { this.gettextCatalog_ = gettextCatalog; /** - * @type {import("ngeo/map/LayerHelper.js").default} + * @type {import("ngeo/map/LayerHelper.js").LayerHelper} * @private */ this.ngeoLayerHelper_ = ngeoLayerHelper; @@ -124,32 +124,34 @@ PrintService.prototype.cancel = function(ref, opt_httpConfig) { * @param {string} layout Layout. * @param {string} format Formats. * @param {Object.} customAttributes Custom attributes. - * @return {MapFishPrintSpec} The print spec. + * @return {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSpec} The print spec. * @export */ PrintService.prototype.createSpec = function( map, scale, dpi, layout, format, customAttributes) { - const specMap = /** @type {MapFishPrintMap} */ ({ + const specMap = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintMap} */ ({ dpi: dpi, rotation: /** number */ (customAttributes['rotation']) }); this.encodeMap_(map, scale, specMap); - const attributes = /** @type {!MapFishPrintAttributes} */ ({ + /** @type {!import('ngeo/print/mapfish-print-v3.js').MapFishPrintAttributes} */ + const attributes = { map: specMap - }); + }; Object.assign(attributes, customAttributes); - const lang = this.gettextCatalog_.currentLanguage; + const lang = this.gettextCatalog_.getCurrentLanguage(); - const spec = /** @type {MapFishPrintSpec} */ ({ + /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSpec} */ + const spec = { attributes, format, lang, layout - }); + }; return spec; }; @@ -158,7 +160,7 @@ PrintService.prototype.createSpec = function( /** * @param {import("ol/Map.js").default} map Map. * @param {number} scale Scale. - * @param {MapFishPrintMap} object Object. + * @param {import('ngeo/print/mapfish-print-v3.js').MapFishPrintMap} object Object. * @private */ PrintService.prototype.encodeMap_ = function(map, scale, object) { @@ -196,7 +198,7 @@ PrintService.prototype.encodeMap_ = function(map, scale, object) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Base.js").default} layer Layer. * @param {number} resolution Resolution. */ @@ -212,7 +214,7 @@ PrintService.prototype.encodeLayer = function(arr, layer, resolution) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Image.js").default} layer Layer. * @private */ @@ -226,12 +228,12 @@ PrintService.prototype.encodeImageLayer_ = function(arr, layer) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Image.js").default} layer Layer. * @private */ PrintService.prototype.encodeImageWmsLayer_ = function(arr, layer) { - const source = layer.getSource(); + const source = /** @type {olSourceImageWMS} */(layer.getSource()); console.assert(layer instanceof olLayerImage); console.assert(source instanceof olSourceImageWMS); @@ -245,7 +247,7 @@ PrintService.prototype.encodeImageWmsLayer_ = function(arr, layer) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Image.js").default} layer The layer. * @param {string} url Url of the WMS server. * @param {Object} params Url parameters @@ -256,7 +258,7 @@ PrintService.prototype.encodeWmsLayer_ = function(arr, layer, url, params) { url = window.location.protocol + url; } const url_url = new URL(url); - const customParams = {'TRANSPARENT': true}; + const customParams = {'TRANSPARENT': 'true'}; if (url_url.searchParams) { /** @type {Object} */ (url_url.searchParams).forEach((value, key) => { customParams[key] = value; @@ -274,7 +276,8 @@ PrintService.prototype.encodeWmsLayer_ = function(arr, layer, url, params) { delete customParams['SERVERTYPE']; delete customParams['VERSION']; - const object = /** @type {MapFishPrintWmsLayer} */ ({ + /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintWmsLayer} */ + const object = { baseURL: getAbsoluteUrl_(url_url.origin + url_url.pathname), imageFormat: 'FORMAT' in params ? params['FORMAT'] : 'image/png', layers: params['LAYERS'].split(','), @@ -284,7 +287,7 @@ PrintService.prototype.encodeWmsLayer_ = function(arr, layer, url, params) { opacity: this.getOpacityOrInherited_(layer), version: params['VERSION'], useNativeAngle: this.printNativeAngle_, - }); + }; arr.push(object); }; @@ -302,7 +305,7 @@ function getAbsoluteUrl_(url) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Tile.js").default} layer Layer. * @private */ @@ -318,26 +321,26 @@ PrintService.prototype.encodeTileLayer_ = function(arr, layer) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Tile.js").default} layer Layer. * @private */ PrintService.prototype.encodeTileWmtsLayer_ = function(arr, layer) { console.assert(layer instanceof olLayerTile); - const source = layer.getSource(); + const source = /** @type {olSourceWMTS} */(layer.getSource()); console.assert(source instanceof olSourceWMTS); const projection = source.getProjection(); - const tileGrid = source.getTileGrid(); + const tileGrid = /** @type {olTilegridWMTS} */(source.getTileGrid()); console.assert(tileGrid instanceof olTilegridWMTS); const matrixIds = tileGrid.getMatrixIds(); - /** @type {Array.} */ + /** @type {Array.} */ const matrices = []; for (let i = 0, ii = matrixIds.length; i < ii; ++i) { const tileRange = tileGrid.getFullTileRange(i); - matrices.push(/** @type {MapFishPrintWmtsMatrix} */ ({ + matrices.push(/** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintWmtsMatrix} */ ({ identifier: matrixIds[i], scaleDenominator: tileGrid.getResolution(i) * projection.getMetersPerUnit() / 0.28E-3, @@ -353,7 +356,7 @@ PrintService.prototype.encodeTileWmtsLayer_ = function(arr, layer) { const dimensions = source.getDimensions(); const dimensionKeys = Object.keys(dimensions); - const object = /** @type {MapFishPrintWmtsLayer} */ ({ + const object = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintWmtsLayer} */ ({ baseURL: this.getWmtsUrl_(source), dimensions: dimensionKeys, dimensionParams: dimensions, @@ -373,12 +376,12 @@ PrintService.prototype.encodeTileWmtsLayer_ = function(arr, layer) { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Tile.js").default} layer Layer. * @private */ PrintService.prototype.encodeTileWmsLayer_ = function(arr, layer) { - const source = layer.getSource(); + const source = /** @type {olSourceTileWMS} */(layer.getSource()); console.assert(layer instanceof olLayerTile); console.assert(source instanceof olSourceTileWMS); @@ -415,7 +418,7 @@ PrintService.prototype.getOpacityOrInherited_ = function(layer) { /** * Send a create report request to the MapFish Print service. - * @param {MapFishPrintSpec} printSpec Print specification. + * @param {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSpec} printSpec Print specification. * @param {angular.IRequestShortcutConfig=} opt_httpConfig $http config object. * @return {angular.IHttpPromise} HTTP promise. * @export @@ -478,7 +481,7 @@ PrintService.prototype.getCapabilities = function(opt_httpConfig) { /** * @param {angular.IHttpService} $http Angular $http service. * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext service. - * @param {import("ngeo/map/LayerHelper.js").default} ngeoLayerHelper Ngeo Layer Helper. + * @param {import("ngeo/map/LayerHelper.js").LayerHelper} ngeoLayerHelper Ngeo Layer Helper. * @return {CreatePrint} The function to create a print service. * @ngInject * @ngdoc service @@ -488,7 +491,7 @@ function createPrintServiceFactory($http, gettextCatalog, ngeoLayerHelper) { return ( /** * @param {string} url URL to MapFish print service. - * @return {Service} The print service + * @return {PrintService} The print service */ function(url) { return new PrintService(url, $http, gettextCatalog, ngeoLayerHelper); diff --git a/src/print/Utils.js b/src/print/Utils.js index 4bb16c417b85..ff9d7c9e94c0 100644 --- a/src/print/Utils.js +++ b/src/print/Utils.js @@ -43,14 +43,14 @@ export const DOTS_PER_INCH = 72; /** * Return a function to use as map postcompose listener for drawing a print * mask on the map. - * @param {function():import("ol/size.js").Size} getSize User-defined function returning the + * @param {function():import('ol/size.js').Size} getSize User-defined function returning the * size in dots of the map to print. - * @param {function(olx.FrameState):number} getScale User-defined function + * @param {function(import('ol/PluggableMap.js').FrameState):number} getScale User-defined function * returning the scale of the map to print. * @param {function():number=} opt_rotation User defined function returning the * inclination of the canvas in degree (-180 to 180). * returning the scale of the map to print. - * @return {function(import("ol/render/Event.js").default)} Function to use as a map postcompose + * @return {function(import('ol/render/Event.js').default)} Function to use as a map postcompose * listener. * @export */ diff --git a/src/print/VectorEncoder.js b/src/print/VectorEncoder.js index aa7bc8383114..67cc4f06ad86 100644 --- a/src/print/VectorEncoder.js +++ b/src/print/VectorEncoder.js @@ -30,7 +30,7 @@ const PrintStyleType = { /** - * @type {Object.} + * @type {Object.} */ const PRINT_STYLE_TYPES = { 'LineString': PrintStyleType.LINE_STRING, @@ -43,20 +43,22 @@ const PRINT_STYLE_TYPES = { /** - * @param {Array.} arr Array. + * @param {Array.} arr Array. * @param {import("ol/layer/Vector.js").default} layer Layer. * @param {number} resolution Resolution. */ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) { - const source = layer.getSource(); + const source = /** @type {olSourceVector} */(layer.getSource()); console.assert(source instanceof olSourceVector); const features = source.getFeatures(); - const /** @type {Array.} */ geojsonFeatures = []; - const mapfishStyleObject = /** @type {MapFishPrintVectorStyle} */ ({ + /** @type {Array.} */ + const geojsonFeatures = []; + /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintVectorStyle} */ + const mapfishStyleObject = { version: 2 - }); + }; for (let i = 0, ii = features.length; i < ii; ++i) { const originalFeature = features[i]; @@ -77,7 +79,7 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) { let isOriginalFeatureAdded = false; for (let j = 0, jj = styles.length; j < jj; ++j) { const style = styles[j]; - let geometry = style.getGeometry(); + let geometry = /** @type {import("ol/geom/Geometry.js").default} */(style.getGeometry()); let geojsonFeature; if (!geometry) { geojsonFeature = origGeojsonFeature; @@ -118,11 +120,11 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) { // See https://github.com/mapfish/mapfish-print/issues/279 if (geojsonFeatures.length > 0) { - const geojsonFeatureCollection = /** @type {GeoJSONFeatureCollection} */ ({ + const geojsonFeatureCollection = /** @type {import("geojson").FeatureCollection} */ ({ type: 'FeatureCollection', features: geojsonFeatures }); - const object = /** @type {MapFishPrintVectorLayer} */ ({ + const object = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintVectorLayer} */ ({ geoJson: geojsonFeatureCollection, opacity: layer.getOpacity(), style: mapfishStyleObject, @@ -134,7 +136,7 @@ VectorEncoder.prototype.encodeVectorLayer = function(arr, layer, resolution) { /** - * @param {MapFishPrintVectorStyle} object MapFish style object. + * @param {import('ngeo/print/mapfish-print-v3.js').MapFishPrintVectorStyle} object MapFish style object. * @param {import("ol/geom/GeometryType.js").default} geometryType Type of the GeoJSON geometry * @param {import("ol/style/Style.js").default} style Style. * @param {string} styleId Style id. @@ -151,7 +153,7 @@ VectorEncoder.prototype.encodeVectorStyle = function(object, geometryType, style // do nothing if we already have a style object for this CQL rule return; } - const styleObject = /** @type {MapFishPrintSymbolizers} */ ({ + const styleObject = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizers} */ ({ symbolizers: [] }); object[key] = styleObject; @@ -180,12 +182,12 @@ VectorEncoder.prototype.encodeVectorStyle = function(object, geometryType, style /** - * @param {MapFishPrintSymbolizerPoint|MapFishPrintSymbolizerPolygon} symbolizer MapFish Print symbolizer. + * @param {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPoint|import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPolygon} symbolizer MapFish Print symbolizer. * @param {!import("ol/style/Fill.js").default} fillStyle Fill style. * @protected */ VectorEncoder.prototype.encodeVectorStyleFill = function(symbolizer, fillStyle) { - let fillColor = fillStyle.getColor(); + let fillColor = /** @type {import('ol/color.js').Color} */(fillStyle.getColor()); if (fillColor !== null) { console.assert(typeof fillColor === 'string' || Array.isArray(fillColor)); fillColor = olColor.asArray(fillColor); @@ -197,13 +199,13 @@ VectorEncoder.prototype.encodeVectorStyleFill = function(symbolizer, fillStyle) /** - * @param {Array.} symbolizers Array of MapFish Print + * @param {Array.} symbolizers Array of MapFish Print * symbolizers. * @param {!import("ol/style/Stroke.js").default} strokeStyle Stroke style. * @protected */ VectorEncoder.prototype.encodeVectorStyleLine = function(symbolizers, strokeStyle) { - const symbolizer = /** @type {MapFishPrintSymbolizerLine} */ ({ + const symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerLine} */ ({ type: 'line' }); this.encodeVectorStyleStroke(symbolizer, strokeStyle); @@ -212,7 +214,7 @@ VectorEncoder.prototype.encodeVectorStyleLine = function(symbolizers, strokeStyl /** - * @param {Array.} symbolizers Array of MapFish Print + * @param {Array.} symbolizers Array of MapFish Print * symbolizers. * @param {!import("ol/style/Image.js").default} imageStyle Image style. * @protected @@ -220,7 +222,7 @@ VectorEncoder.prototype.encodeVectorStyleLine = function(symbolizers, strokeStyl VectorEncoder.prototype.encodeVectorStylePoint = function(symbolizers, imageStyle) { let symbolizer; if (imageStyle instanceof olStyleCircle) { - symbolizer = /** @type {MapFishPrintSymbolizerPoint} */ ({ + symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPoint} */ ({ type: 'point' }); symbolizer.pointRadius = imageStyle.getRadius(); @@ -235,7 +237,7 @@ VectorEncoder.prototype.encodeVectorStylePoint = function(symbolizers, imageStyl } else if (imageStyle instanceof olStyleIcon) { const src = imageStyle.getSrc(); if (src !== undefined) { - symbolizer = /** @type {MapFishPrintSymbolizerPoint} */ ({ + symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPoint} */ ({ type: 'point', externalGraphic: src }); @@ -265,7 +267,7 @@ VectorEncoder.prototype.encodeVectorStylePoint = function(symbolizers, imageStyl */ const points = /** @type {import("ol/style/RegularShape.js").default} */ (imageStyle).getPoints(); if (points !== null) { - symbolizer = /** @type {MapFishPrintSymbolizerPoint} */ ({ + symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPoint} */ ({ type: 'point' }); if (points === 4) { @@ -307,14 +309,14 @@ VectorEncoder.prototype.encodeVectorStylePoint = function(symbolizers, imageStyl /** - * @param {Array.} symbolizers Array of MapFish Print + * @param {Array.} symbolizers Array of MapFish Print * symbolizers. * @param {!import("ol/style/Fill.js").default} fillStyle Fill style. * @param {import("ol/style/Stroke.js").default} strokeStyle Stroke style. * @protected */ VectorEncoder.prototype.encodeVectorStylePolygon = function(symbolizers, fillStyle, strokeStyle) { - const symbolizer = /** @type {MapFishPrintSymbolizerPolygon} */ ({ + const symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPolygon} */ ({ type: 'polygon' }); this.encodeVectorStyleFill(symbolizer, fillStyle); @@ -326,13 +328,13 @@ VectorEncoder.prototype.encodeVectorStylePolygon = function(symbolizers, fillSty /** - * @param {MapFishPrintSymbolizerPoint|MapFishPrintSymbolizerLine|MapFishPrintSymbolizerPolygon} + * @param {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPoint|import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerLine|import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerPolygon} * symbolizer MapFish Print symbolizer. * @param {!import("ol/style/Stroke.js").default} strokeStyle Stroke style. * @protected */ VectorEncoder.prototype.encodeVectorStyleStroke = function(symbolizer, strokeStyle) { - const strokeColor = strokeStyle.getColor(); + const strokeColor = /** @type {import('ol/color.js').Color} */(strokeStyle.getColor()); if (strokeColor !== null) { console.assert(typeof strokeColor === 'string' || Array.isArray(strokeColor)); const strokeColorRgba = olColor.asArray(strokeColor); @@ -342,7 +344,8 @@ VectorEncoder.prototype.encodeVectorStyleStroke = function(symbolizer, strokeSty } const strokeDashstyle = strokeStyle.getLineDash(); if (strokeDashstyle !== null) { - symbolizer.strokeDashstyle = strokeDashstyle.join(' '); + /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerLine} */(symbolizer) + .strokeDashstyle = strokeDashstyle.join(' '); } const strokeWidth = strokeStyle.getWidth(); if (strokeWidth !== undefined) { @@ -350,19 +353,20 @@ VectorEncoder.prototype.encodeVectorStyleStroke = function(symbolizer, strokeSty } const strokeLineCap = strokeStyle.getLineCap(); if (strokeLineCap) { - symbolizer.strokeLinecap = strokeStyle.getLineCap(); + /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerLine} */(symbolizer) + .strokeLinecap = strokeStyle.getLineCap(); } }; /** - * @param {Array.} symbolizers Array of MapFish Print + * @param {Array.} symbolizers Array of MapFish Print * symbolizers. * @param {!import("ol/style/Text.js").default} textStyle Text style. * @protected */ VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle) { - const symbolizer = /** @type {MapFishPrintSymbolizerText} */ ({ + const symbolizer = /** @type {import('ngeo/print/mapfish-print-v3.js').MapFishPrintSymbolizerText} */ ({ type: 'Text' }); const label = textStyle.getText(); @@ -408,7 +412,7 @@ VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle) { const strokeStyle = textStyle.getStroke(); if (strokeStyle !== null) { - const strokeColor = strokeStyle.getColor(); + const strokeColor = /** @type {import('ol/color.js').Color} */(strokeStyle.getColor()); console.assert(typeof strokeColor === 'string' || Array.isArray(strokeColor)); const strokeColorRgba = olColor.asArray(strokeColor); console.assert(Array.isArray(strokeColorRgba), 'only supporting stroke colors'); @@ -423,7 +427,7 @@ VectorEncoder.prototype.encodeTextStyle = function(symbolizers, textStyle) { const fillStyle = textStyle.getFill(); if (fillStyle !== null) { - const fillColor = fillStyle.getColor(); + const fillColor = /** @type {import('ol/color.js').Color} */(fillStyle.getColor()); console.assert(typeof fillColor === 'string' || Array.isArray(fillColor)); const fillColorRgba = olColor.asArray(fillColor); console.assert(Array.isArray(fillColorRgba), 'only supporting fill colors'); diff --git a/src/print/mapfish-print-v3.js b/src/print/mapfish-print-v3.js new file mode 100644 index 000000000000..1e783adb451b --- /dev/null +++ b/src/print/mapfish-print-v3.js @@ -0,0 +1,187 @@ +/** + * @typedef {Object} MapFishPrintSpec + * @property {MapFishPrintAttributes} attributes + * @property {string} layout + * @property {string} format + * @property {string} lang + */ + + +/** + * @typedef {Object} MapFishPrintAttributes + * @property {MapFishPrintMap} map + */ + + +/** + * @typedef {Object} MapFishPrintMap + * @property {Array.} bbox + * @property {Array.} center + * @property {number} scale + * @property {number} dpi + * @property {Array.} layers + * @property {string} projection + * @property {number} rotation + */ + + +/** + * @typedef {Object} MapFishPrintLayer + * @property {string} type + * @property {number} opacity + */ + + +/** + * extends {MapFishPrintLayer} + * @typedef {Object} MapFishPrintVectorLayer + * @property {string} type (MapFishPrintLayer) + * @property {number} opacity (MapFishPrintLayer) + * @property {import("geojson").Object} geoJson + * @property {MapFishPrintVectorStyle} style + */ + + +/** + * @typedef {Object} MapFishPrintVectorStyle + * @property {number} version + */ + + +/** + * extends {MapFishPrintLayer} + * @typedef {Object} MapFishPrintWmsLayer + * @property {string} type (MapFishPrintLayer) + * @property {number} opacity (MapFishPrintLayer) + * @property {string} baseURL + * @property {Object.} customParams + * @property {Array.} layers + * @property {string} serverType + * @property {Array.} [styles] + * @property {string} version + * @property {boolean} useNativeAngle + * @property {string} imageFormat + */ + + +/** + * @typedef {Object} MapFishPrintWmtsMatrix + * @property {string} identifier + * @property {number} scaleDenominator + * @property {Array.} tileSize + * @property {Array.} topLeftCorner + * @property {Array.} matrixSize + */ + + +/** + * extends {MapFishPrintLayer} + * @typedef {Object} MapFishPrintWmtsLayer + * @property {string} type (MapFishPrintLayer) + * @property {number} opacity (MapFishPrintLayer) + * @property {string} baseURL + * @property {Object} dimensions + * @property {Object} dimensionParams + * @property {string} imageFormat + * @property {string} layer + * @property {Array.} matrices + * @property {string} matrixSet + * @property {string} requestEncoding + * @property {string} style + * @property {string} version + */ + + +/** + * @typedef {Object} MapFishPrintReportResponse + * @property {string} ref + * @property {string} statusURL + * @property {string} downloadURL + */ + + +/** + * @typedef {Object} MapFishPrintStatusResponse + * @property {boolean} done + * @property {string} status + * @property {string} error + * @property {string} downloadURL + */ + + +/** + * @typedef {Object} MapFishPrintSymbolizers + * @property {Array.} symbolizers + */ + + +/** + * @typedef {Object} MapFishPrintSymbolizer + * @property {string} type + */ + + +/** + * extends {MapFishPrintSymbolizer} + * @typedef {Object} MapFishPrintSymbolizerLine + * @property {string} type (MapFishPrintSymbolizer) + * @property {string} strokeColor + * @property {number} strokeOpacity + * @property {number} strokeWidth + * @property {string} strokeDashstyle + * @property {string} strokeLinecap + */ + + +/** + * extends {MapFishPrintSymbolizer} + * @typedef {Object} MapFishPrintSymbolizerPoint + * @property {string} type (MapFishPrintSymbolizer) + * @property {string} externalGraphic + * @property {string} graphicFormat + * @property {number} graphicOpacity + * @property {number} graphicHeight + * @property {number} graphicWidth + * @property {string} fillColor + * @property {number} fillOpacity + * @property {number} pointRadius + * @property {number} rotation + * @property {string} strokeColor + * @property {number} strokeOpacity + * @property {number} strokeWidth + * @property {string} graphicName + */ + + +/** + * extends {MapFishPrintSymbolizer} + * @typedef {Object} MapFishPrintSymbolizerPolygon + * @property {string} type (MapFishPrintSymbolizer) + * @property {string} fillColor + * @property {number} fillOpacity + * @property {string} strokeColor + * @property {number} strokeOpacity + * @property {number} strokeWidth + * @property {string} strokeDashstyle + */ + + +/** + * extends {MapFishPrintSymbolizer} + * @typedef {Object} MapFishPrintSymbolizerText + * @property {string} type (MapFishPrintSymbolizer) + * @property {string} label + * @property {string} labelAlign + * @property {string} labelRotation + * @property {string} fontWeight + * @property {string} fontSize + * @property {string} fontFamily + * @property {number} labelXOffset + * @property {number} labelYOffset + * @property {string} haloColor + * @property {number} haloOpacity + * @property {number} haloRadius + * @property {string} fontColor + */ + +export const nothing = null; diff --git a/src/profile/d3Elevation.js b/src/profile/d3Elevation.js index 7b16f3b1ec2f..4dad84ddca76 100644 --- a/src/profile/d3Elevation.js +++ b/src/profile/d3Elevation.js @@ -360,6 +360,7 @@ function d3Elevation(options) { let elevationsValues = []; // Get min/max values (extent) of each lines. for (const name in linesConfiguration) { + /** @type {[number, number]} */ const extent = d3extent(data, d => linesConfiguration[name].zExtractor(d)); // only include defined extent if (extent.every(Number.isFinite)) { diff --git a/src/search/createGeoJSONBloodhound.js b/src/search/createGeoJSONBloodhound.js index 8ca4c9019324..1aecb915e51f 100644 --- a/src/search/createGeoJSONBloodhound.js +++ b/src/search/createGeoJSONBloodhound.js @@ -114,7 +114,7 @@ module.value('ngeoSearchCreateGeoJSONBloodhound', createGeoJSONBloodhound); * ); * bloodhound.initialize(); * - * @typedef {function(string, (function(GeoJSONFeature): boolean)=, import("ol/proj/Projection.js").default=, import("ol/proj/Projection.js").default=, BloodhoundOptions=, BloodhoundRemoteOptions=):Bloodhound} + * @typedef {function(string, (function(import("geojson").Feature): boolean)=, import("ol/proj/Projection.js").default=, import("ol/proj/Projection.js").default=, BloodhoundOptions=, BloodhoundRemoteOptions=):Bloodhound} */ diff --git a/test/spec/services/print.spec.js b/test/spec/services/print.spec.js index 18cbc6c1431c..bfb2c2f278c9 100644 --- a/test/spec/services/print.spec.js +++ b/test/spec/services/print.spec.js @@ -110,7 +110,7 @@ describe('ngeo.print.Service', () => { baseURL: 'http://example.com/wms', imageFormat: 'image/jpeg', customParams: { - TRANSPARENT: true + TRANSPARENT: 'true' }, layers: ['foo', 'bar'], type: 'wms', @@ -169,7 +169,7 @@ describe('ngeo.print.Service', () => { baseURL: 'http://example.com/wms', imageFormat: 'image/jpeg', customParams: { - TRANSPARENT: true + TRANSPARENT: 'true' }, layers: ['foo', 'bar'], type: 'wms',