Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix types in profile and in print #4545

Merged
merged 2 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions contribs/gmf/src/print/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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') {
Expand Down
6 changes: 3 additions & 3 deletions contribs/gmf/src/profile/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string, *>?} 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.
Expand Down Expand Up @@ -288,7 +288,7 @@ function Controller($scope, $http, $element, $filter,


/**
* @type {?ProfileOptions}
* @type {?import('ngeo/profile/elevationComponent.js').ProfileOptions}
* @export
*/
this.profileOptions = null;
Expand Down Expand Up @@ -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),
Expand Down
12 changes: 6 additions & 6 deletions contribs/gmf/src/search/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/mapfishprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/map/LayerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
65 changes: 34 additions & 31 deletions src/print/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/


Expand Down Expand Up @@ -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) {
/**
Expand All @@ -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;
Expand Down Expand Up @@ -124,32 +124,34 @@ PrintService.prototype.cancel = function(ref, opt_httpConfig) {
* @param {string} layout Layout.
* @param {string} format Formats.
* @param {Object.<string, *>} 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;
};
Expand All @@ -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) {
Expand Down Expand Up @@ -196,7 +198,7 @@ PrintService.prototype.encodeMap_ = function(map, scale, object) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} arr Array.
* @param {import("ol/layer/Base.js").default} layer Layer.
* @param {number} resolution Resolution.
*/
Expand All @@ -212,7 +214,7 @@ PrintService.prototype.encodeLayer = function(arr, layer, resolution) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} arr Array.
* @param {import("ol/layer/Image.js").default} layer Layer.
* @private
*/
Expand All @@ -226,12 +228,12 @@ PrintService.prototype.encodeImageLayer_ = function(arr, layer) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} 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);
Expand All @@ -245,7 +247,7 @@ PrintService.prototype.encodeImageWmsLayer_ = function(arr, layer) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} 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
Expand All @@ -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;
Expand All @@ -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(','),
Expand All @@ -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);
};

Expand All @@ -302,7 +305,7 @@ function getAbsoluteUrl_(url) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} arr Array.
* @param {import("ol/layer/Tile.js").default} layer Layer.
* @private
*/
Expand All @@ -318,26 +321,26 @@ PrintService.prototype.encodeTileLayer_ = function(arr, layer) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} 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.<MapFishPrintWmtsMatrix>} */
/** @type {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintWmtsMatrix>} */
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,
Expand All @@ -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,
Expand All @@ -373,12 +376,12 @@ PrintService.prototype.encodeTileWmtsLayer_ = function(arr, layer) {


/**
* @param {Array.<MapFishPrintLayer>} arr Array.
* @param {Array.<import('ngeo/print/mapfish-print-v3.js').MapFishPrintLayer>} 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);
Expand Down Expand Up @@ -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<Object>} HTTP promise.
* @export
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/print/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down