diff --git a/contribs/gmf/src/editing/editFeatureComponent.js b/contribs/gmf/src/editing/editFeatureComponent.js index 6b860678ecb3..d89147b6468f 100644 --- a/contribs/gmf/src/editing/editFeatureComponent.js +++ b/contribs/gmf/src/editing/editFeatureComponent.js @@ -527,7 +527,7 @@ Controller.prototype.$onInit = function() { this.dirty = this.dirty === true; this.editableNode_ = /** @type {import(gmf/themes.js).GmfLayer} */ ( this.editableTreeCtrl.node); - this.features = this.vectorLayer.getSource().getFeaturesCollection(); + this.features = /** @type {olSourceVector} */(this.vectorLayer.getSource()).getFeaturesCollection(); this.tolerance = this.tolerance !== undefined ? this.tolerance : 10; // (1.1) Set editable WMS layer diff --git a/contribs/gmf/src/import/importdatasourceComponent.js b/contribs/gmf/src/import/importdatasourceComponent.js index 1d5c6fd24978..adf057377211 100644 --- a/contribs/gmf/src/import/importdatasourceComponent.js +++ b/contribs/gmf/src/import/importdatasourceComponent.js @@ -183,10 +183,10 @@ class Controller { this.pending = false; /** - * @type {!unitPrefix} + * @type {!import('ngeo/misc/filters.js').unitPrefix} * @private */ - this.unitPrefixFormat_ = /** @type {unitPrefix} */ ( + this.unitPrefixFormat_ = /** @type {import('ngeo/misc/filters.js').unitPrefix} */ ( $filter('ngeoUnitPrefix')); /** diff --git a/contribs/gmf/src/lidarprofile/Manager.js b/contribs/gmf/src/lidarprofile/Manager.js index 76a3cb251df7..2bbe86481661 100644 --- a/contribs/gmf/src/lidarprofile/Manager.js +++ b/contribs/gmf/src/lidarprofile/Manager.js @@ -152,7 +152,7 @@ export class LidarprofileManager { */ clearBuffer() { if (this.lidarBuffer) { - this.lidarBuffer.getSource().clear(); + /** @type {olSourceVector} */(this.lidarBuffer.getSource()).clear(); } } @@ -461,8 +461,8 @@ export class LidarprofileManager { const clip = this.utils.clipLineByMeasure(this.config, map_resolution, this.line_, domainX[0], domainX[1]); - this.lidarBuffer.getSource().clear(); - this.lidarBuffer.getSource().addFeature(clip.bufferGeom); + /** @type {olSourceVector} */(this.lidarBuffer.getSource()).clear(); + /** @type {olSourceVector} */(this.lidarBuffer.getSource()).addFeature(clip.bufferGeom); this.lidarBuffer.setStyle(clip.bufferStyle); const span = domainX[1] - domainX[0]; diff --git a/contribs/gmf/src/lidarprofile/Plot.js b/contribs/gmf/src/lidarprofile/Plot.js index 5b09a27abcdf..c4b60914a056 100644 --- a/contribs/gmf/src/lidarprofile/Plot.js +++ b/contribs/gmf/src/lidarprofile/Plot.js @@ -343,7 +343,7 @@ export default class { this.manager_.cartoHighlight.setElement(el); this.manager_.cartoHighlight.setPosition([p.coords[0], p.coords[1]]); - this.manager_.lidarPointHighlight.getSource().clear(); + /** @type {olSourceVector} */(this.manager_.lidarPointHighlight.getSource()).clear(); const lidarPointGeom = new olGeomPoint([p.coords[0], p.coords[1]]); const lidarPointFeature = new olFeature(lidarPointGeom); if (typeof (pointClassification.color) !== undefined) { @@ -358,9 +358,9 @@ export default class { })); } - this.manager_.lidarPointHighlight.getSource().addFeature(lidarPointFeature); + /** @type {olSourceVector} */(this.manager_.lidarPointHighlight.getSource()).addFeature(lidarPointFeature); } else { - this.manager_.lidarPointHighlight.getSource().clear(); + /** @type {olSourceVector} */(this.manager_.lidarPointHighlight.getSource()).clear(); svg.select('#highlightCircle').remove(); lidarInfo.html(''); this.manager_.cartoHighlight.setPosition(undefined); diff --git a/contribs/gmf/src/mobile/measure/areaComponent.js b/contribs/gmf/src/mobile/measure/areaComponent.js index df28c1921328..85ffd0e4bcee 100644 --- a/contribs/gmf/src/mobile/measure/areaComponent.js +++ b/contribs/gmf/src/mobile/measure/areaComponent.js @@ -40,7 +40,7 @@ module.run(/* @ngInject */ ($templateCache) => { * or deactivate the component. * @htmlAttribute {number=} gmf-mobile-measurearea-precision the number of significant digits to display. * @htmlAttribute {import("ol/Map.js").default} gmf-mobile-measurearea-map The map. - * @htmlAttribute {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction=} + * @htmlAttribute {import("ol/style/Style.js").StyleLike=} * gmf-mobile-measurearea-sketchstyle A style for the measure area. * @param {string|function(!JQuery=, !angular.IAttributes=)} * gmfMobileMeasureAreaTemplateUrl Template URL for the directive. diff --git a/contribs/gmf/src/mobile/measure/baseComponent.js b/contribs/gmf/src/mobile/measure/baseComponent.js index 1564fcc49296..40a281c604e5 100644 --- a/contribs/gmf/src/mobile/measure/baseComponent.js +++ b/contribs/gmf/src/mobile/measure/baseComponent.js @@ -66,7 +66,7 @@ export function MeasueMobileBaseController($scope, $filter, gettextCatalog) { this.precision; /** - * @type {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} + * @type {import("ol/style/Style.js").StyleLike} * @export */ this.sketchStyle = new olStyleStyle({ diff --git a/contribs/gmf/src/mobile/measure/lengthComponent.js b/contribs/gmf/src/mobile/measure/lengthComponent.js index 32d112714f4e..b4085c88e7a2 100644 --- a/contribs/gmf/src/mobile/measure/lengthComponent.js +++ b/contribs/gmf/src/mobile/measure/lengthComponent.js @@ -40,7 +40,7 @@ module.run(/* @ngInject */ ($templateCache) => { * or deactivate the component. * @htmlAttribute {number=} gmf-mobile-measurelength-precision the number of significant digits to display. * @htmlAttribute {import("ol/Map.js").default} gmf-mobile-measurelength-map The map. - * @htmlAttribute {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction=} + * @htmlAttribute {import("ol/style/Style.js").StyleLike=} * gmf-mobile-measurelength-sketchstyle A style for the measure length. * @param {string|function(!JQuery=, !angular.IAttributes=)} * gmfMobileMeasureLengthTemplateUrl Template URL for the directive. diff --git a/contribs/gmf/src/mobile/measure/pointComponent.js b/contribs/gmf/src/mobile/measure/pointComponent.js index 0f676b3b238a..d85d54f5b12b 100644 --- a/contribs/gmf/src/mobile/measure/pointComponent.js +++ b/contribs/gmf/src/mobile/measure/pointComponent.js @@ -61,7 +61,7 @@ module.run(/* @ngInject */ ($templateCache) => { * gmf-mobile-measurepoint-layersconfig Raster elevation layers to get * information under the point and its configuaration. * @htmlAttribute {import("ol/Map.js").default} gmf-mobile-measurepoint-map The map. - * @htmlAttribute {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction=} + * @htmlAttribute {import("ol/style/Style.js").StyleLike=} * gmf-mobile-measurepoint-sketchstyle A style for the measure point. * @param {string|function(!JQuery=, !angular.IAttributes=)} * gmfMobileMeasurePointTemplateUrl Template URL for the directive. @@ -170,7 +170,7 @@ function Controller(gettextCatalog, $scope, $filter, gmfRaster, ngeoDebounce) { this.layersConfig; /** - * @type {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} + * @type {import("ol/style/Style.js").StyleLike} * @export */ this.sketchStyle; @@ -229,7 +229,7 @@ function Controller(gettextCatalog, $scope, $filter, gmfRaster, ngeoDebounce) { */ Controller.prototype.init = function() { this.measure = new ngeoInteractionMeasurePointMobile( - /** @type {numberCoordinates} */ (this.$filter_('ngeoNumberCoordinates')), + /** @type {import('ngeo/misc/filters.js').numberCoordinates} */ (this.$filter_('ngeoNumberCoordinates')), this.format || '{x}, {y}', { decimals: this.coordinateDecimals, diff --git a/examples/elevationProfile.js b/examples/elevationProfile.js index 5bd417c3dfd5..19ef30526d5a 100644 --- a/examples/elevationProfile.js +++ b/examples/elevationProfile.js @@ -81,7 +81,7 @@ function MainController($http, $scope) { }); this.snappedPoint_ = new olFeature(); - vectorLayer.getSource().addFeature(this.snappedPoint_); + /** @type {olSourceVector} */(vectorLayer.getSource()).addFeature(this.snappedPoint_); // Use vectorLayer.setMap(map) rather than map.addLayer(vectorLayer). This // makes the vector layer "unmanaged", meaning that it is always on top. diff --git a/examples/modifycircle.js b/examples/modifycircle.js index 9aca155ebcd5..ae246881b3d2 100644 --- a/examples/modifycircle.js +++ b/examples/modifycircle.js @@ -85,7 +85,7 @@ function MainController() { * @export */ this.interaction = new ngeoInteractionModifyCircle( - /** @type {olx.interaction.ModifyOptions} */({ + /** @type {import('ol/interaction/Modify.js').Options} */({ features: this.features })); diff --git a/examples/modifyrectangle.js b/examples/modifyrectangle.js index 3bf913743cf5..e5f773dc1838 100644 --- a/examples/modifyrectangle.js +++ b/examples/modifyrectangle.js @@ -127,7 +127,7 @@ function MainController() { * @export */ this.interaction = new ngeoInteractionModifyRectangle( - /** @type {olx.interaction.ModifyOptions} */({ + /** @type {import('ol/interaction/Modify.js').Options} */({ features: this.features, style: style })); diff --git a/examples/permalink.js b/examples/permalink.js index b0c57adf653a..f368b066466e 100644 --- a/examples/permalink.js +++ b/examples/permalink.js @@ -178,7 +178,7 @@ function DrawComponentController($scope, ngeoLocation) { } DrawComponentController.prototype.$onInit = function() { - const vectorSource = this.layer.getSource(); + const vectorSource = /** @type {olSourceVector} */(this.layer.getSource()); this.interaction = new olInteractionDraw({ type: /** @type {import("ol/geom/GeometryType.js").default} */ ('LineString'), @@ -226,7 +226,7 @@ DrawComponentController.prototype.$onInit = function() { * @export */ DrawComponentController.prototype.clearLayer = function() { - this.layer.getSource().clear(true); + /** @type {olSourceVector} */(this.layer.getSource()).clear(true); this.featureSeq_ = 0; this.ngeoLocation_.deleteParam('features'); }; diff --git a/examples/rotate.js b/examples/rotate.js index 322a9c1db829..3a7578df1f18 100644 --- a/examples/rotate.js +++ b/examples/rotate.js @@ -127,7 +127,7 @@ function MainController() { * @export */ this.interaction = new ngeoInteractionRotate( - /** @type {olx.interaction.ModifyOptions} */({ + /** @type {import('ol/interaction/Modify.js').Options} */({ features: this.features, layers: [vectorLayer], style: style diff --git a/src/draw/Controller.js b/src/draw/Controller.js index ca467ae21a62..7025707de10d 100644 --- a/src/draw/Controller.js +++ b/src/draw/Controller.js @@ -169,7 +169,7 @@ DrawController.prototype.handleActiveChange = function(event) { * Called when a feature is finished being drawn. Set the default properties * for its style, then set its style and add it to the features collection. * @param {string} type Type of geometry being drawn. - * @param {import("ol/interaction/Draw/Event.js").default|MeasureEvent} event Event. + * @param {import('ol/events/Event.js').default|MeasureEvent} event Event. * @export */ DrawController.prototype.handleDrawEnd = function(type, event) { diff --git a/src/editing/createfeatureComponent.js b/src/editing/createfeatureComponent.js index 23c43bda7603..08cb7233ed78 100644 --- a/src/editing/createfeatureComponent.js +++ b/src/editing/createfeatureComponent.js @@ -254,7 +254,7 @@ Controller.prototype.$onInit = function() { /** * Called when a feature is finished being drawn. Add the feature to the * collection. - * @param {import("ol/interaction/Draw/Event.js").default|MeasureEvent} event Event. + * @param {import('ol/events/Event.js').default|MeasureEvent} event Event. * @export */ Controller.prototype.handleDrawEnd_ = function(event) { diff --git a/src/editing/createregularpolygonfromclickComponent.js b/src/editing/createregularpolygonfromclickComponent.js index 7bbcb3527731..f9bfb496eb93 100644 --- a/src/editing/createregularpolygonfromclickComponent.js +++ b/src/editing/createregularpolygonfromclickComponent.js @@ -172,7 +172,7 @@ Controller.prototype.$onInit = function() { /** * Called when a feature is finished being drawn. Add the feature to the * collection. - * @param {import("ol/interaction/Draw/Event.js").default} evt Event. + * @param {import('ol/events/Event.js').default} evt Event. * @private */ Controller.prototype.handleDrawEnd_ = function(evt) { diff --git a/src/geolocation/desktop.js b/src/geolocation/desktop.js index d8e39e32c969..183fbf500b10 100644 --- a/src/geolocation/desktop.js +++ b/src/geolocation/desktop.js @@ -12,9 +12,9 @@ import olGeomPoint from 'ol/geom/Point.js'; * Options for the mobile geolocations directive. * * @typedef {Object} DesktopGeolocationDirectiveOptions - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [accuracyFeatureStyle] The style to + * @property {import("ol/style/Style.js").StyleLike} [accuracyFeatureStyle] The style to * use to sketch the accuracy feature, which is a regular polygon. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [positionFeatureStyle] The style to + * @property {import("ol/style/Style.js").StyleLike} [positionFeatureStyle] The style to * use to sketch the position feature, which is a point. * @property {number} [zoom] If set, in addition to recentering the map view at the location, determines * the zoom level to set when obtaining a new position. diff --git a/src/geolocation/mobile.js b/src/geolocation/mobile.js index 5cb0ffaba49f..13d4d6af527b 100644 --- a/src/geolocation/mobile.js +++ b/src/geolocation/mobile.js @@ -13,9 +13,9 @@ import olGeomPoint from 'ol/geom/Point.js'; * Options for the mobile geolocations directive. * * @typedef {Object} MobileGeolocationDirectiveOptions - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [accuracyFeatureStyle] The style to + * @property {import("ol/style/Style.js").StyleLike} [accuracyFeatureStyle] The style to * use to sketch the accuracy feature, which is a regular polygon. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [positionFeatureStyle] The style to + * @property {import("ol/style/Style.js").StyleLike} [positionFeatureStyle] The style to * use to sketch the position feature, which is a point. * @property {number} [zoom] If set, in addition to recentering the map view at the location, determines * the zoom level to set when obtaining a new position diff --git a/src/googlestreetview/component.js b/src/googlestreetview/component.js index fc52a4569125..1cb6fcce0ccc 100644 --- a/src/googlestreetview/component.js +++ b/src/googlestreetview/component.js @@ -74,8 +74,7 @@ class Controller { /** * Style for the feature. - * @type {import("ol/style/Style.js").default|Array.| - * ol.FeatureStyleFunction|ol.StyleFunction|undefined} + * @type {import("ol/style/Style.js").StyleLike|undefined} * @export */ this.featureStyle; diff --git a/src/interaction/DrawAzimut.js b/src/interaction/DrawAzimut.js index c846fd365ce2..65b6cae81e78 100644 --- a/src/interaction/DrawAzimut.js +++ b/src/interaction/DrawAzimut.js @@ -7,28 +7,34 @@ import olGeomCircle from 'ol/geom/Circle.js'; import olGeomGeometryCollection from 'ol/geom/GeometryCollection.js'; import olGeomLineString from 'ol/geom/LineString.js'; import olGeomPoint from 'ol/geom/Point.js'; -import olInteractionPointer from 'ol/interaction/Pointer.js'; +import olInteractionPointer from 'ol/interaction/Draw.js'; import olLayerVector from 'ol/layer/Vector.js'; import olSourceVector from 'ol/source/Vector.js'; + +/** + * @typedef {Object} Options + * @property {olSourceVector} source + * @property {import('ol/style/Style.js').StyleLike} style + */ + + /** * Interaction dedicated to measure azimut. */ class DrawAzimut extends olInteractionPointer { /** - * @param {olx.interaction.PointerOptions} options Options. + * @param {Options} options Options. */ constructor(options) { super({ - handleDownEvent: handleDownEvent_, - handleEvent: handleEvent_, - handleUpEvent: handleUpEvent_ + type: undefined }); this.shouldStopEvent = FALSE; /** - * @type {import("ol/Pixel.js").default} + * @type {import("ol/pixel.js").Pixel} * @private */ this.downPx_ = null; @@ -114,8 +120,9 @@ class DrawAzimut extends olInteractionPointer { this.updateSketchFeatures_(); } else { const sketchPointGeom = this.sketchPoint_.getGeometry(); - console.assert(sketchPointGeom instanceof olGeomPoint); - sketchPointGeom.setCoordinates(coordinates); + if (sketchPointGeom instanceof olGeomPoint) { + sketchPointGeom.setCoordinates(coordinates); + } } } @@ -131,7 +138,7 @@ class DrawAzimut extends olInteractionPointer { if (this.sketchPoint_ !== null) { sketchFeatures.push(this.sketchPoint_); } - const source = this.sketchLayer_.getSource(); + const source = /** @type {olSourceVector} */(this.sketchLayer_.getSource()); source.clear(true); source.addFeatures(sketchFeatures); } @@ -151,7 +158,7 @@ class DrawAzimut extends olInteractionPointer { this.sketchFeature_ = new olFeature(); this.sketchFeature_.setGeometry(geometry); this.updateSketchFeatures_(); - /** @type {DrawEvent} */ + /** @type {import('ngeo/interaction/common.js').DrawEvent} */ const evt = new ngeoCustomEvent('drawstart', {feature: this.sketchFeature_}); this.dispatchEvent(evt); } @@ -163,22 +170,26 @@ class DrawAzimut extends olInteractionPointer { */ modifyDrawing_(event) { const coordinate = event.coordinate; - const geometry = this.sketchFeature_.getGeometry(); + const geometry = /** @type {import('ol/geom/GeometryCollection.js').default} */(this.sketchFeature_.getGeometry()); const geometries = geometry.getGeometriesArray(); const line = geometries[0]; - console.assert(line instanceof olGeomLineString); - const coordinates = line.getCoordinates(); - const sketchPointGeom = this.sketchPoint_.getGeometry(); - console.assert(sketchPointGeom instanceof olGeomPoint); - sketchPointGeom.setCoordinates(coordinate); - const last = coordinates[coordinates.length - 1]; - last[0] = coordinate[0]; - last[1] = coordinate[1]; - console.assert(line instanceof olGeomLineString); - line.setCoordinates(coordinates); - const circle = geometries[1]; - circle.setRadius(line.getLength()); - this.updateSketchFeatures_(); + if (line instanceof olGeomLineString) { + const coordinates = line.getCoordinates(); + const sketchPointGeom = this.sketchPoint_.getGeometry(); + if (sketchPointGeom instanceof olGeomPoint) { + sketchPointGeom.setCoordinates(coordinate); + const last = coordinates[coordinates.length - 1]; + last[0] = coordinate[0]; + last[1] = coordinate[1]; + console.assert(line instanceof olGeomLineString); + line.setCoordinates(coordinates); + const circle = geometries[1]; + if (circle instanceof olGeomCircle) { + circle.setRadius(line.getLength()); + this.updateSketchFeatures_(); + } + } + } } /** @@ -192,7 +203,7 @@ class DrawAzimut extends olInteractionPointer { if (sketchFeature !== null) { this.sketchFeature_ = null; this.sketchPoint_ = null; - this.sketchLayer_.getSource().clear(true); + /** @type {olSourceVector} */(this.sketchLayer_.getSource()).clear(true); } return sketchFeature; } @@ -221,7 +232,7 @@ class DrawAzimut extends olInteractionPointer { this.source_.addFeature(sketchFeature); } - /** @type {DrawEvent} */ + /** @type {import('ngeo/interaction/common.js').DrawEvent} */ const event = new ngeoCustomEvent('drawend', {feature: this.sketchFeature_}); this.dispatchEvent(event); } @@ -233,61 +244,52 @@ class DrawAzimut extends olInteractionPointer { olInteractionPointer.prototype.setMap.call(this, map); this.updateState_(); } -} - - -/** - * @param {import("ol/MapBrowserPointerEvent.js").default} event Event. - * @return {boolean} Start drag sequence? - * @this {import("ngeo/interaction/DrawAzimut.js").default} - * @private - */ -function handleDownEvent_(event) { - this.downPx_ = event.pixel; - return true; -} + /** + * @param {import("ol/MapBrowserPointerEvent.js").default} event Event. + * @return {boolean} Start drag sequence? + */ + handleDownEvent(event) { + this.downPx_ = event.pixel; + return true; + } -/** - * @param {import("ol/MapBrowserPointerEvent.js").default} event Event. - * @return {boolean} Stop drag sequence? - * @this {import("ngeo/interaction/DrawAzimut.js").default} - * @private - */ -function handleUpEvent_(event) { - const downPx = this.downPx_; - const clickPx = event.pixel; - const dx = downPx[0] - clickPx[0]; - const dy = downPx[1] - clickPx[1]; - const squaredDistance = dx * dx + dy * dy; - let pass = true; - if (squaredDistance <= this.squaredClickTolerance_) { - this.handlePointerMove_(event); - if (!this.started_) { - this.startDrawing_(event); - } else { - this.finishDrawing_(); + /** + * @param {import("ol/MapBrowserPointerEvent.js").default} event Event. + * @return {boolean} Stop drag sequence? + */ + handleUpEvent(event) { + const downPx = this.downPx_; + const clickPx = event.pixel; + const dx = downPx[0] - clickPx[0]; + const dy = downPx[1] - clickPx[1]; + const squaredDistance = dx * dx + dy * dy; + let pass = true; + if (squaredDistance <= this.squaredClickTolerance_) { + this.handlePointerMove_(event); + if (!this.started_) { + this.startDrawing_(event); + } else { + this.finishDrawing_(); + } + pass = false; } - pass = false; + return pass; } - return pass; -} - -/** - * @param {import("ol/MapBrowserEvent.js").default} mapBrowserEvent Map browser event. - * @return {boolean} `false` to stop event propagation. - * @this {import("ngeo/interaction/DrawAzimut.js").default} - * @private - */ -function handleEvent_(mapBrowserEvent) { - let pass = true; - if (mapBrowserEvent.type === 'pointermove') { - pass = this.handlePointerMove_(mapBrowserEvent); - } else if (mapBrowserEvent.type === 'dblclick') { - pass = false; + /** + * @param {import("ol/MapBrowserEvent.js").default} mapBrowserEvent Map browser event. + * @return {boolean} `false` to stop event propagation. + */ + handleEvent(mapBrowserEvent) { + let pass = true; + if (mapBrowserEvent.type === 'pointermove') { + pass = this.handlePointerMove_(mapBrowserEvent); + } else if (mapBrowserEvent.type === 'dblclick') { + pass = false; + } + return super.handleEvent(mapBrowserEvent) && pass; } - return olInteractionPointer.prototype.handleEvent.call(this, mapBrowserEvent) && pass; } export default DrawAzimut; diff --git a/src/interaction/DrawRegularPolygonFromClick.js b/src/interaction/DrawRegularPolygonFromClick.js index 8ba10f76ec20..d0aa5a9b5089 100644 --- a/src/interaction/DrawRegularPolygonFromClick.js +++ b/src/interaction/DrawRegularPolygonFromClick.js @@ -3,7 +3,7 @@ import * as olEvents from 'ol/events.js'; import olFeature from 'ol/Feature.js'; import {TRUE} from 'ol/functions.js'; import olGeomCircle from 'ol/geom/Circle.js'; -import olGeomPolygon from 'ol/geom/Polygon.js'; +import {fromCircle, makeRegular} from 'ol/geom/Polygon.js'; import olInteractionInteraction from 'ol/interaction/Interaction.js'; @@ -27,7 +27,9 @@ export default class extends olInteractionInteraction { * @param {DrawRegularPolygonFromClickOptions} options Options */ constructor(options) { - super(); + super({ + handleEvent: TRUE + }); /** * @type {number} @@ -52,10 +54,6 @@ export default class extends olInteractionInteraction { * @private */ this.listenerKeys_ = []; - - olInteractionInteraction.call(this, { - handleEvent: TRUE - }); } /** @@ -125,13 +123,13 @@ export default class extends olInteractionInteraction { */ handleMapClick_(evt) { const center = evt.coordinate; - const geometry = olGeomPolygon.fromCircle( + const geometry = fromCircle( new olGeomCircle(center), this.sides_ ); - olGeomPolygon.makeRegular(geometry, center, this.radius_, this.angle_); + makeRegular(geometry, center, this.radius_, this.angle_); - /** @type {DrawEvent} */ + /** @type {import('ngeo/interaction/common.js').DrawEvent} */ const event = new ngeoCustomEvent('drawend', {feature: new olFeature(geometry)}); this.dispatchEvent(event); } diff --git a/src/interaction/Measure.js b/src/interaction/Measure.js index bbfd168372fe..24c9c66b22fc 100644 --- a/src/interaction/Measure.js +++ b/src/interaction/Measure.js @@ -24,9 +24,9 @@ import olStyleStyle from 'ol/style/Style.js'; * then the default behaviour occurs depending on the measure type. * @property {number} [decimals] Defines the number of decimals to keep in the measurement. If not defined, * then the default behaviour occurs depending on the measure type. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [style] The style to be used when + * @property {import("ol/style/Style.js").StyleLike} [style] The style to be used when * drawing is finished. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [sketchStyle] The style to be used + * @property {import("ol/style/Style.js").StyleLike} [sketchStyle] The style to be used * while drawing. */ @@ -37,7 +37,7 @@ import olStyleStyle from 'ol/style/Style.js'; */ /** - * @typedef {ngeo.CustomEvent} MeasureEvent + * @typedef {import('ngeo/CustomEvent.js').default} MeasureEvent */ @@ -55,7 +55,7 @@ class Measure extends olInteractionInteraction { /** * The help tooltip element. - * @type {Element} + * @type {HTMLElement} * @private */ this.helpTooltipElement_ = null; @@ -70,7 +70,7 @@ class Measure extends olInteractionInteraction { /** * The measure tooltip element. - * @type {Element} + * @type {HTMLElement} * @private */ this.measureTooltipElement_ = null; @@ -190,7 +190,7 @@ class Measure extends olInteractionInteraction { * @private */ this.drawInteraction_ = this.createDrawInteraction(options.sketchStyle, - this.vectorLayer_.getSource()); + /** @type {olSourceVector} */(this.vectorLayer_.getSource())); /** * @type {boolean} @@ -217,13 +217,15 @@ class Measure extends olInteractionInteraction { * Creates the draw interaction. * * @abstract - * @param {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction|undefined} + * @param {import("ol/style/Style.js").StyleLike|undefined} * style The sketchStyle used for the drawing interaction. * @param {import("ol/source/Vector.js").default} source Vector source. * @return {import("ol/interaction/Draw.js").default|import("ngeo/interaction/DrawAzimut.js").default|import("ngeo/interaction/MobileDraw.js").default} The interaction * @protected */ - createDrawInteraction(style, source) {} + createDrawInteraction(style, source) { + return undefined; + } /** @@ -248,12 +250,13 @@ class Measure extends olInteractionInteraction { /** * Handle draw interaction `drawstart` event. - * @param {import("ol/interaction/Draw/Event.js").default|DrawEvent} evt Event. + * @param { import('ol/events/Event.js').default|import('ngeo/interaction/common.js').DrawEvent} evt Event. * @private */ onDrawStart_(evt) { + // @ts-ignore: evt should be of type {import('ol/interaction/Draw.js').DrawEvent but he is provate this.sketchFeature = evt.feature || evt.detail.feature; - this.vectorLayer_.getSource().clear(true); + /** @type {olSourceVector} */(this.vectorLayer_.getSource()).clear(true); this.createMeasureTooltip_(); const geometry = this.sketchFeature.getGeometry(); @@ -276,7 +279,7 @@ class Measure extends olInteractionInteraction { /** * Handle draw interaction `drawend` event. - * @param {import("ol/interaction/Draw/Event.js").default|DrawEvent} evt Event. + * @param {import('ol/events/Event.js').default|import('ngeo/interaction/common.js').DrawEvent} evt Event. * @private */ onDrawEnd_(evt) { @@ -386,7 +389,7 @@ class Measure extends olInteractionInteraction { this.createHelpTooltip_(); } } else { - this.vectorLayer_.getSource().clear(true); + /** @type {olSourceVector} */(this.vectorLayer_.getSource()).clear(true); this.getMap().removeOverlay(this.measureTooltipOverlay_); this.removeMeasureTooltip_(); this.removeHelpTooltip_(); @@ -400,7 +403,7 @@ class Measure extends olInteractionInteraction { * where to place the tooltip and determine which help message to display. * * @abstract - * @param {function(string, ?import("ol/coordinate.js").Coordinate)} callback The function + * @param {function(string, ?import("ol/coordinate.js").Coordinate): void} callback The function * to be called. * @protected */ @@ -430,19 +433,13 @@ class Measure extends olInteractionInteraction { } -/** - * @const - * @type {import("ol/Sphere.js").default} - */ - - /** * Calculate the area of the passed polygon and return a formatted string * of the area. * @param {!import("ol/geom/Polygon.js").default} polygon Polygon. * @param {!import("ol/proj/Projection.js").default} projection Projection of the polygon coords. * @param {number|undefined} precision Precision. - * @param {!unitPrefix} format The format function. + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function. * @return {string} Formatted string of the area. * @this {import("ngeo/interaction/Measure.js").default} */ @@ -458,7 +455,7 @@ export function getFormattedArea(polygon, projection, precision, format) { * of the area. * @param {!import("ol/geom/Circle.js").default} circle Circle * @param {number|undefined} precision Precision. - * @param {!unitPrefix} format The format function. + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function. * @return {string} Formatted string of the area. */ export function getFormattedCircleArea(circle, precision, format) { @@ -473,7 +470,7 @@ export function getFormattedCircleArea(circle, precision, format) { * @param {!import("ol/geom/LineString.js").default} lineString Line string. * @param {!import("ol/proj/Projection.js").default} projection Projection of the line string coords. * @param {number|undefined} precision Precision. - * @param {!unitPrefix} format The format function. + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function. * @return {string} Formatted string of length. */ export function getFormattedLength(lineString, projection, precision, format) { @@ -492,7 +489,7 @@ export function getFormattedLength(lineString, projection, precision, format) { * Return a formatted string of the point. * @param {!import("ol/geom/Point.js").default} point Point. * @param {number|undefined} decimals Decimals. - * @param {!numberCoordinates} format A function to format coordinate into text + * @param {!import('ngeo/misc/filters.js').numberCoordinates} format A function to format coordinate into text * @param {string=} opt_template The template. * @return {string} Formatted string of coordinate. */ diff --git a/src/interaction/MeasureArea.js b/src/interaction/MeasureArea.js index 775f8960af97..baba08add12f 100644 --- a/src/interaction/MeasureArea.js +++ b/src/interaction/MeasureArea.js @@ -1,4 +1,4 @@ -import ngeoInteractionMeasure from 'ngeo/interaction/Measure.js'; +import ngeoInteractionMeasure, {getFormattedArea} from 'ngeo/interaction/Measure.js'; import olInteractionDraw from 'ol/interaction/Draw.js'; @@ -9,9 +9,9 @@ import olInteractionDraw from 'ol/interaction/Draw.js'; */ export default class extends ngeoInteractionMeasure { /** - * @param {!unitPrefix} format The format function + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext catalog. - * @param {MeasureOptions=} options Options + * @param {import('ngeo/interaction/Measure.js').MeasureOptions=} options Options */ constructor(format, gettextCatalog, options = {}) { super(options); @@ -33,13 +33,15 @@ export default class extends ngeoInteractionMeasure { /** * The format function - * @type {unitPrefix} + * @type {import('ngeo/misc/filters.js').unitPrefix} */ this.format = format; } /** - * @inheritDoc + * @param {import("ol/style/Style.js").StyleLike|undefined} style The sketchStyle used for the drawing interaction. + * @param {import("ol/source/Vector.js").default} source Vector source. + * @return {olInteractionDraw|import("ngeo/interaction/MobileDraw.js").default} The interaction */ createDrawInteraction(style, source) { return new olInteractionDraw({ @@ -53,10 +55,10 @@ export default class extends ngeoInteractionMeasure { * @inheritDoc */ handleMeasure(callback) { - const geom = this.sketchFeature.getGeometry(); + const geom = /** @type {import('ol/geom/Polygon').default} */(this.sketchFeature.getGeometry()); const proj = this.getMap().getView().getProjection(); console.assert(proj); - const output = ngeoInteractionMeasure.getFormattedArea(geom, proj, this.precision, this.format); + const output = getFormattedArea(geom, proj, this.precision, this.format); const verticesCount = geom.getCoordinates()[0].length; let coord = null; if (verticesCount > 3) { diff --git a/src/interaction/MeasureAreaMobile.js b/src/interaction/MeasureAreaMobile.js index 466576064b5e..03a2b555f7e9 100644 --- a/src/interaction/MeasureAreaMobile.js +++ b/src/interaction/MeasureAreaMobile.js @@ -6,10 +6,9 @@ import ngeoInteractionMobileDraw from 'ngeo/interaction/MobileDraw.js'; * Interaction dedicated to measure Area on mobile devices. * * @constructor - * @extends {import("ngeo/interaction/MeasureArea.js").default} - * @param {!unitPrefix} format The format function + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext catalog. - * @param {MeasureOptions=} options Options + * @param {import('ngeo/interaction/Measure.js').MeasureOptions=} options Options */ class MeasureAreaMobile extends ngeoInteractionMeasureArea { constructor(format, gettextCatalog, options = {}) { @@ -18,7 +17,9 @@ class MeasureAreaMobile extends ngeoInteractionMeasureArea { } /** - * @inheritDoc + * @param {import("ol/style/Style.js").StyleLike|undefined} style The sketchStyle used for the drawing interaction. + * @param {import("ol/source/Vector.js").default} source Vector source. + * @return {ngeoInteractionMobileDraw} The interaction */ createDrawInteraction(style, source) { return new ngeoInteractionMobileDraw({ diff --git a/src/interaction/MeasureAzimut.js b/src/interaction/MeasureAzimut.js index d08e6386db8e..acea818a9d41 100644 --- a/src/interaction/MeasureAzimut.js +++ b/src/interaction/MeasureAzimut.js @@ -59,7 +59,9 @@ export default class extends ngeoInteractionMeasure { */ handleMeasure(callback) { const geom = this.sketchFeature.getGeometry(); - const line = geom.getGeometries()[0]; + const line = /** @type {import('ol/geom/LineString.js').default} */( + /** @type {import('ol/geom/GeometryCollection.js').default} */(geom).getGeometries()[0] + ); const output = getFormattedAzimutRadius( line, this.getMap().getView().getProjection(), this.decimals, this.precision, this.unitPrefixFormat, this.numberFormat); diff --git a/src/interaction/MeasureBaseOptions.js b/src/interaction/MeasureBaseOptions.js index 0ab33f427d88..3cdd414b67ec 100644 --- a/src/interaction/MeasureBaseOptions.js +++ b/src/interaction/MeasureBaseOptions.js @@ -5,6 +5,8 @@ * @property {number} [precision] * @property {boolean} [displayHelpTooltip] * @property {Element} [startMsg] - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [style] - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [sketchStyle] + * @property {import("ol/style/Style.js").StyleLike} [style] + * @property {import("ol/style/Style.js").StyleLike} [sketchStyle] */ + +export default null; diff --git a/src/interaction/MeasureLength.js b/src/interaction/MeasureLength.js index 76a4ffedd4b2..e4bb9019a690 100644 --- a/src/interaction/MeasureLength.js +++ b/src/interaction/MeasureLength.js @@ -1,4 +1,4 @@ -import ngeoInteractionMeasure from 'ngeo/interaction/Measure.js'; +import ngeoInteractionMeasure, {getFormattedLength} from 'ngeo/interaction/Measure.js'; import olInteractionDraw from 'ol/interaction/Draw.js'; @@ -9,9 +9,9 @@ import olInteractionDraw from 'ol/interaction/Draw.js'; */ export default class extends ngeoInteractionMeasure { /** - * @param {!unitPrefix} format The format function + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext catalog. - * @param {MeasureOptions=} options Options + * @param {import('ngeo/interaction/Measure.js').MeasureOptions=} options Options */ constructor(format, gettextCatalog, options = {}) { super(options); @@ -28,13 +28,15 @@ export default class extends ngeoInteractionMeasure { /** * The format function - * @type {unitPrefix} + * @type {import('ngeo/misc/filters.js').unitPrefix} */ this.format = format; } /** - * @inheritDoc + * @param {import("ol/style/Style.js").StyleLike|undefined} style The sketchStyle used for the drawing interaction. + * @param {import("ol/source/Vector.js").default} source Vector source. + * @return {olInteractionDraw|import("ngeo/interaction/MobileDraw.js").default} The interaction */ createDrawInteraction(style, source) { return new olInteractionDraw({ @@ -48,10 +50,10 @@ export default class extends ngeoInteractionMeasure { * @inheritDoc */ handleMeasure(callback) { - const geom = this.sketchFeature.getGeometry(); + const geom = /** @type {import("ol/geom/LineString.js").default} */(this.sketchFeature.getGeometry()); const proj = this.getMap().getView().getProjection(); console.assert(proj); - const output = ngeoInteractionMeasure.getFormattedLength(geom, proj, this.precision, this.format); + const output = getFormattedLength(geom, proj, this.precision, this.format); const coord = geom.getLastCoordinate(); callback(output, coord); } diff --git a/src/interaction/MeasureLengthMobile.js b/src/interaction/MeasureLengthMobile.js index ef9550a8e70f..f6474de7c3e0 100644 --- a/src/interaction/MeasureLengthMobile.js +++ b/src/interaction/MeasureLengthMobile.js @@ -6,9 +6,9 @@ import ngeoInteractionMobileDraw from 'ngeo/interaction/MobileDraw.js'; */ export default class extends ngeoInteractionMeasureLength { /** - * @param {!unitPrefix} format The format function + * @param {!import('ngeo/misc/filters.js').unitPrefix} format The format function * @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext catalog. - * @param {MeasureOptions=} opt_options Options + * @param {import('ngeo/interaction/Measure.js').MeasureOptions=} opt_options Options */ constructor(format, gettextCatalog, opt_options) { const options = opt_options !== undefined ? opt_options : {}; @@ -19,7 +19,10 @@ export default class extends ngeoInteractionMeasureLength { } /** - * @inheritDoc + * @param {import("ol/style/Style.js").StyleLike|undefined} + * style The sketchStyle used for the drawing interaction. + * @param {import("ol/source/Vector.js").default} source Vector source. + * @return {ngeoInteractionMobileDraw} The interaction */ createDrawInteraction(style, source) { return new ngeoInteractionMobileDraw({ diff --git a/src/interaction/MeasurePointMobile.js b/src/interaction/MeasurePointMobile.js index d72fde5d60b4..7982c8e3954f 100644 --- a/src/interaction/MeasurePointMobile.js +++ b/src/interaction/MeasurePointMobile.js @@ -1,4 +1,4 @@ -import ngeoInteractionMeasure from 'ngeo/interaction/Measure.js'; +import ngeoInteractionMeasure, {getFormattedPoint} from 'ngeo/interaction/Measure.js'; import ngeoInteractionMobileDraw from 'ngeo/interaction/MobileDraw.js'; @@ -7,9 +7,9 @@ import ngeoInteractionMobileDraw from 'ngeo/interaction/MobileDraw.js'; */ export default class extends ngeoInteractionMeasure { /** - * @param {numberCoordinates} format the number formatter + * @param {import('ngeo/misc/filters.js').numberCoordinates} format the number formatter * @param {string} coordFormat the coordinates formatter - * @param {MeasureOptions=} options Options + * @param {import('ngeo/interaction/Measure.js').MeasureOptions=} options Options */ constructor(format, coordFormat, options = {}) { Object.assign(options, {displayHelpTooltip: false}); @@ -17,7 +17,7 @@ export default class extends ngeoInteractionMeasure { super(options); /** - * @type {numberCoordinates} + * @type {import('ngeo/misc/filters.js').numberCoordinates} * @private */ this.format_ = format; @@ -44,9 +44,9 @@ export default class extends ngeoInteractionMeasure { * @inheritDoc */ handleMeasure(callback) { - const geom = this.sketchFeature.getGeometry(); + const geom = /** @type {import('ol/geom/Point.js').default} */(this.sketchFeature.getGeometry()); const dec = this.decimals; - const output = ngeoInteractionMeasure.getFormattedPoint(geom, dec, this.format_, this.coordFormat_); + const output = getFormattedPoint(geom, dec, this.format_, this.coordFormat_); const coord = geom.getLastCoordinate(); callback(output, coord); } diff --git a/src/interaction/MobileDraw.js b/src/interaction/MobileDraw.js index 59d5fe6d1148..5eb87253d8d4 100644 --- a/src/interaction/MobileDraw.js +++ b/src/interaction/MobileDraw.js @@ -18,7 +18,7 @@ import olSourceVector from 'ol/source/Vector.js'; * @typedef {Object} MobileDrawOptions * @property {number} [minPoints] The number of points that must be drawn before a polygon ring or line * string can be finished. Default is `3` for polygon rings and `2` for line strings. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [style] Style for sketch features. + * @property {import("ol/style/Style.js").StyleLike} [style] Style for sketch features. * @property {import("ol/geom/GeometryType.js").default} type Drawing type ('Point' or 'LineString'. * @property {boolean} [wrapX] Wrap the world horizontally on the sketch overlay. Default is `false`. */ @@ -36,7 +36,6 @@ import olSourceVector from 'ol/source/Vector.js'; * * @constructor * @fires DrawEvent - * @extends {import("ol/interaction/Interaction.js").default} * @param {MobileDrawOptions} options Options */ export default class extends olInteractionInteraction { @@ -206,13 +205,13 @@ export default class extends olInteractionInteraction { if (this.type_ === 'Point') { if (!this.sketchFeature_) { this.sketchFeature_ = new olFeature(new olGeomPoint(coordinate)); - /** @type {DrawEvent} */ const event = new ngeoCustomEvent('drawstart', {feature: this.sketchFeature_}); this.dispatchEvent(event); } sketchFeatureGeom = this.sketchFeature_.getGeometry(); - console.assert(sketchFeatureGeom instanceof olGeomSimpleGeometry); - sketchFeatureGeom.setCoordinates(coordinate); + if (sketchFeatureGeom instanceof olGeomSimpleGeometry) { + sketchFeatureGeom.setCoordinates(coordinate); + } return; } @@ -222,15 +221,15 @@ export default class extends olInteractionInteraction { if (!this.sketchFeature_) { coordinates = [coordinate.slice(), coordinate.slice()]; this.sketchFeature_ = new olFeature(new olGeomLineString(coordinates)); - /** @type {DrawEvent} */ const event = new ngeoCustomEvent('drawstart', {feature: this.sketchFeature_}); this.dispatchEvent(event); } else { sketchFeatureGeom = this.sketchFeature_.getGeometry(); - console.assert(sketchFeatureGeom instanceof olGeomSimpleGeometry); - coordinates = sketchFeatureGeom.getCoordinates(); - coordinates.push(coordinate.slice()); - sketchFeatureGeom.setCoordinates(coordinates); + if (sketchFeatureGeom instanceof olGeomSimpleGeometry) { + coordinates = sketchFeatureGeom.getCoordinates(); + coordinates.push(coordinate.slice()); + sketchFeatureGeom.setCoordinates(coordinates); + } } } @@ -240,7 +239,6 @@ export default class extends olInteractionInteraction { if (!this.sketchFeature_) { coordinates = [coordinate.slice(), coordinate.slice(), coordinate.slice()]; this.sketchFeature_ = new olFeature(new olGeomPolygon([coordinates])); - /** @type {DrawEvent} */ const event = new ngeoCustomEvent( 'drawstart', { @@ -250,11 +248,12 @@ export default class extends olInteractionInteraction { this.dispatchEvent(event); } else { sketchFeatureGeom = this.sketchFeature_.getGeometry(); - console.assert(sketchFeatureGeom instanceof olGeomPolygon); - const coordinatess = sketchFeatureGeom.getCoordinates(); - coordinates = coordinatess[0]; - coordinates.push(coordinate.slice()); - sketchFeatureGeom.setCoordinates(coordinatess); + if (sketchFeatureGeom instanceof olGeomPolygon) { + const coordinatess = sketchFeatureGeom.getCoordinates(); + coordinates = coordinatess[0]; + coordinates.push(coordinate.slice()); + sketchFeatureGeom.setCoordinates(coordinatess); + } } } @@ -310,7 +309,6 @@ export default class extends olInteractionInteraction { this.set('drawing', false); - /** @type {DrawEvent} */ const event = new ngeoCustomEvent('drawend', {feature: this.sketchFeature_}); this.dispatchEvent(event); } @@ -346,19 +344,21 @@ export default class extends olInteractionInteraction { if (this.type_ === 'LineString') { const sketchFeatureGeom = this.sketchFeature_.getGeometry(); - console.assert(sketchFeatureGeom instanceof olGeomSimpleGeometry); - const coordinates = sketchFeatureGeom.getCoordinates(); - coordinates.pop(); - coordinates.push(center); - sketchFeatureGeom.setCoordinates(coordinates); + if (sketchFeatureGeom instanceof olGeomSimpleGeometry) { + const coordinates = sketchFeatureGeom.getCoordinates(); + coordinates.pop(); + coordinates.push(center); + sketchFeatureGeom.setCoordinates(coordinates); + } } else if (this.type_ === 'Polygon') { const sketchFeatureGeom = this.sketchFeature_.getGeometry(); - console.assert(sketchFeatureGeom instanceof olGeomPolygon); - const coordinatess = sketchFeatureGeom.getCoordinates(); - const coordinates = coordinatess[0]; - coordinates.pop(); - coordinates.push(center); - sketchFeatureGeom.setCoordinates([coordinates]); + if (sketchFeatureGeom instanceof olGeomPolygon) { + const coordinatess = sketchFeatureGeom.getCoordinates(); + const coordinates = coordinatess[0]; + coordinates.pop(); + coordinates.push(center); + sketchFeatureGeom.setCoordinates([coordinates]); + } } const dirty = this.getDirty(); @@ -377,7 +377,7 @@ export default class extends olInteractionInteraction { if (sketchFeature || this.sketchPoints_.length > 0) { this.sketchFeature_ = null; this.sketchPoint_ = null; - this.overlay_.getSource().clear(true); + /** @type {olSourceVector} */(this.overlay_.getSource()).clear(true); } this.sketchPoints_ = []; this.set('dirty', false); @@ -449,7 +449,7 @@ export default class extends olInteractionInteraction { if (this.sketchPoint_) { sketchFeatures.push(this.sketchPoint_); } - const overlaySource = this.overlay_.getSource(); + const overlaySource = /** @type {olSourceVector} */(this.overlay_.getSource()); overlaySource.clear(true); overlaySource.addFeatures(sketchFeatures); overlaySource.addFeatures(this.sketchPoints_); @@ -463,8 +463,11 @@ export default class extends olInteractionInteraction { getSketchPointGeometry_() { console.assert(this.sketchPoint_, 'sketch point should be thruty'); const geometry = this.sketchPoint_.getGeometry(); - console.assert(geometry instanceof olGeomPoint); - return geometry; + if (geometry instanceof olGeomPoint) { + return geometry; + } else { + throw 'Wrong geometry type'; + } } /** diff --git a/src/interaction/Modify.js b/src/interaction/Modify.js index d7e6a624baaa..1cb42855c845 100644 --- a/src/interaction/Modify.js +++ b/src/interaction/Modify.js @@ -39,7 +39,7 @@ import olFeature from 'ol/Feature.js'; */ export default class extends olInteractionInteraction { /** - * @param {olx.interaction.ModifyOptions} options Options. + * @param {import('ol/interaction/Modify.js').Options} options Options. */ constructor(options) { super({ diff --git a/src/interaction/ModifyCircle.js b/src/interaction/ModifyCircle.js index dfb53704ad52..e373a0007b1a 100644 --- a/src/interaction/ModifyCircle.js +++ b/src/interaction/ModifyCircle.js @@ -1,7 +1,7 @@ import ngeoCustomEvent from 'ngeo/CustomEvent.js'; import ngeoFormatFeatureProperties from 'ngeo/format/FeatureProperties.js'; import {getDefaultModifyStyleFunction} from 'ngeo/interaction/common.js'; -import ngeoInteractionMeasureAzimut from 'ngeo/interaction/MeasureAzimut.js'; +import {getAzimut} from 'ngeo/interaction/MeasureAzimut.js'; import {getUid as olUtilGetUid} from 'ol/util.js'; import olFeature from 'ol/Feature.js'; import olMapBrowserPointerEvent from 'ol/MapBrowserPointerEvent.js'; @@ -23,16 +23,17 @@ import olStructsRBush from 'ol/structs/RBush.js'; */ export default class extends olInteractionPointer { /** - * @param {olx.interaction.ModifyOptions} options Options. + * @param {import('ol/interaction/Modify.js').Options} options Options. * @fires import("ngeo/interaction/ModifyCircleEvent.js").default */ constructor(options) { - super({ - handleDownEvent: handleDownEvent_, - handleDragEvent: handleDragEvent_, - handleEvent: handleEvent, - handleUpEvent: handleUpEvent_ - }); + super(); + + this.handleDownEvent = this.handleDownEvent_; + this.handleDragEvent = this.handleDragEvent_; + this.handleEvent = this.handleEvent; + this.handleUpEvent = this.handleUpEvent_; + console.assert(options.features); /** @@ -43,7 +44,7 @@ export default class extends olInteractionPointer { this.vertexFeature_ = null; /** - * @type {import("ol/Pixel.js").default} + * @type {import("ol/pixel.js").Pixel} * @private */ this.lastPixel_ = [0, 0]; @@ -56,7 +57,7 @@ export default class extends olInteractionPointer { /** * Segment RTree for each layer - * @type {import("ol/structs/RBush.js").default.} + * @type {import("ol/structs/RBush.js").default.} * @private */ this.rBush_ = new olStructsRBush(); @@ -139,7 +140,6 @@ export default class extends olInteractionPointer { willModifyFeatures_(evt) { if (!this.modified_) { this.modified_ = true; - /** @type {ModifyEvent} */ const event = new ngeoCustomEvent('modifystart', {features: this.features_}); this.dispatchEvent(event); } @@ -154,7 +154,7 @@ export default class extends olInteractionPointer { // Remove the vertex feature if the collection of canditate features // is empty. if (this.vertexFeature_ && this.features_.getLength() === 0) { - this.overlay_.getSource().removeFeature(this.vertexFeature_); + /** @type {olSourceVector} */(this.overlay_.getSource()).removeFeature(this.vertexFeature_); this.vertexFeature_ = null; } } @@ -165,10 +165,10 @@ export default class extends olInteractionPointer { */ removeFeatureSegmentData_(feature) { const rBush = this.rBush_; - const /** @type {Array.} */ nodesToRemove = []; + const /** @type {Array.} */ nodesToRemove = []; rBush.forEach( /** - * @param {import("ol/ModifySegmentDataType.js").default} node RTree node. + * @param {import("ol/interaction/Modify.js").SegmentData} node RTree node. */ (node) => { if (feature === node.feature) { @@ -219,7 +219,7 @@ export default class extends olInteractionPointer { coordinates = rings[j]; for (i = 0, ii = coordinates.length - 1; i < ii; ++i) { segment = coordinates.slice(i, i + 2); - segmentData = /** @type {import("ol/ModifySegmentDataType.js").default} */ ({ + segmentData = /** @type {import("ol/interaction/Modify.js").SegmentData} */ ({ feature: feature, geometry: geometry, depth: [j], @@ -241,7 +241,7 @@ export default class extends olInteractionPointer { if (!vertexFeature) { vertexFeature = new olFeature(new olGeomPoint(coordinates)); this.vertexFeature_ = vertexFeature; - this.overlay_.getSource().addFeature(vertexFeature); + /** @type {olSourceVector} */(this.overlay_.getSource()).addFeature(vertexFeature); } else { const geometry = /** @type {import("ol/geom/Point.js").default} */ (vertexFeature.getGeometry()); geometry.setCoordinates(coordinates); @@ -259,7 +259,7 @@ export default class extends olInteractionPointer { } /** - * @param {import("ol/Pixel.js").default} pixel Pixel + * @param {import("ol/pixel.js").Pixel} pixel Pixel * @param {import("ol/PluggableMap.js").default} map Map. * @private */ @@ -316,7 +316,7 @@ export default class extends olInteractionPointer { } } if (this.vertexFeature_) { - this.overlay_.getSource().removeFeature(this.vertexFeature_); + /** @type {olSourceVector} */(this.overlay_.getSource()).removeFeature(this.vertexFeature_); this.vertexFeature_ = null; } } @@ -331,130 +331,120 @@ export default class extends olInteractionPointer { geometry.setCoordinates(coordinates); this.changingFeature_ = false; } -} -/** - * @param {import("ol/ModifySegmentDataType.js").default} a The first segment data. - * @param {import("ol/ModifySegmentDataType.js").default} b The second segment data. - * @return {number} The difference in indexes. - */ -function compareIndexes(a, b) { - return a.index - b.index; -} - - -/** - * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. - * @return {boolean} Start drag sequence? - * @this {import("ngeo/interaction/ModifyCircle.js").default} - * @private - */ -function handleDownEvent_(evt) { - this.handlePointerAtPixel_(evt.pixel, evt.map); - this.dragSegments_ = []; - this.modified_ = false; - const vertexFeature = this.vertexFeature_; - if (vertexFeature) { - const geometry = /** @type {import("ol/geom/Point.js").default} */ (vertexFeature.getGeometry()); - const vertex = geometry.getCoordinates(); - const vertexExtent = olExtent.boundingExtent([vertex]); - const segmentDataMatches = this.rBush_.getInExtent(vertexExtent); - const componentSegments = {}; - segmentDataMatches.sort(compareIndexes); - for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) { - const segmentDataMatch = segmentDataMatches[i]; - const segment = segmentDataMatch.segment; - let uid = olUtilGetUid(segmentDataMatch.feature); - const depth = segmentDataMatch.depth; - if (depth) { - uid += `-${depth.join('-')}`; // separate feature components - } - if (!componentSegments[uid]) { - componentSegments[uid] = new Array(2); - } - if (olCoordinate.equals(segment[0], vertex) && - !componentSegments[uid][0]) { - this.dragSegments_.push([segmentDataMatch, 0]); - componentSegments[uid][0] = segmentDataMatch; - } else if (olCoordinate.equals(segment[1], vertex) && - !componentSegments[uid][1]) { - this.dragSegments_.push([segmentDataMatch, 1]); - componentSegments[uid][1] = segmentDataMatch; + /** + * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. + * @return {boolean} Start drag sequence? + * @private + */ + handleDownEvent_(evt) { + this.handlePointerAtPixel_(evt.pixel, evt.map); + this.dragSegments_ = []; + this.modified_ = false; + const vertexFeature = this.vertexFeature_; + if (vertexFeature) { + const geometry = /** @type {import("ol/geom/Point.js").default} */ (vertexFeature.getGeometry()); + const vertex = geometry.getCoordinates(); + const vertexExtent = olExtent.boundingExtent([vertex]); + const segmentDataMatches = this.rBush_.getInExtent(vertexExtent); + const componentSegments = {}; + segmentDataMatches.sort(compareIndexes); + for (let i = 0, ii = segmentDataMatches.length; i < ii; ++i) { + const segmentDataMatch = segmentDataMatches[i]; + const segment = segmentDataMatch.segment; + let uid = olUtilGetUid(segmentDataMatch.feature); + const depth = segmentDataMatch.depth; + if (depth) { + uid += `-${depth.join('-')}`; // separate feature components + } + if (!componentSegments[uid]) { + componentSegments[uid] = new Array(2); + } + if (olCoordinate.equals(segment[0], vertex) && + !componentSegments[uid][0]) { + this.dragSegments_.push([segmentDataMatch, 0]); + componentSegments[uid][0] = segmentDataMatch; + } else if (olCoordinate.equals(segment[1], vertex) && + !componentSegments[uid][1]) { + this.dragSegments_.push([segmentDataMatch, 1]); + componentSegments[uid][1] = segmentDataMatch; + } } } + return !!this.vertexFeature_; } - return !!this.vertexFeature_; -} + /** + * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. + * @private + */ + handleDragEvent_(evt) { + this.willModifyFeatures_(evt); + const vertex = evt.coordinate; + const geometry = /** @type {import("ol/geom/Polygon.js").default}*/ (this.dragSegments_[0][0].geometry); + const center = olExtent.getCenter(geometry.getExtent()); + + const line = new olGeomLineString([center, vertex]); -/** - * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. - * @this {import("ngeo/interaction/ModifyCircle.js").default} - * @private - */ -function handleDragEvent_(evt) { - this.willModifyFeatures_(evt); - const vertex = evt.coordinate; - const geometry = /** @type {import("ol/geom/Polygon.js").default}*/ (this.dragSegments_[0][0].geometry); - const center = olExtent.getCenter(geometry.getExtent()); - const line = new olGeomLineString([center, vertex]); + /** + * @type {import("ol/geom/Circle.js").default} + */ + const circle = new olGeomCircle(center, line.getLength()); + const coordinates = fromCircle(circle, 64).getCoordinates(); + this.setGeometryCoordinates_(geometry, coordinates); + + const azimut = getAzimut(line); + this.features_.getArray()[0].set(ngeoFormatFeatureProperties.AZIMUT, azimut); + + this.createOrUpdateVertexFeature_(vertex); + } /** - * @type {import("ol/geom/Circle.js").default} + * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. + * @return {boolean} Stop drag sequence? + * @private */ - const circle = new olGeomCircle(center, line.getLength()); - const coordinates = fromCircle(circle, 64).getCoordinates(); - this.setGeometryCoordinates_(geometry, coordinates); - + handleUpEvent_(evt) { + this.rBush_.clear(); + this.writeCircleGeometry_(this.dragSegments_[0][0].feature, + this.dragSegments_[0][0].geometry); - const azimut = ngeoInteractionMeasureAzimut.getAzimut(line); - this.features_.getArray()[0].set(ngeoFormatFeatureProperties.AZIMUT, azimut); + if (this.modified_) { + const event = new ngeoCustomEvent('modifyend', {features: this.features_}); + this.dispatchEvent(event); + this.modified_ = false; + } + return false; + } - this.createOrUpdateVertexFeature_(vertex); -} + /** + * Handles the {@link import("ol/MapBrowserEvent.js").default map browser event} and may modify the + * geometry. + * @param {import("ol/MapBrowserEvent.js").default} mapBrowserEvent Map browser event. + * @return {boolean} `false` to stop event propagation. + */ + handleEvent(mapBrowserEvent) { + if (!(mapBrowserEvent instanceof olMapBrowserPointerEvent)) { + return true; + } + let handled; + if (!mapBrowserEvent.map.getView().getInteracting() && + mapBrowserEvent.type == 'pointermove' && !this.handlingDownUpSequence) { + this.handlePointerMove_(mapBrowserEvent); + } -/** - * @param {import("ol/MapBrowserPointerEvent.js").default} evt Event. - * @return {boolean} Stop drag sequence? - * @this {import("ngeo/interaction/ModifyCircle.js").default} - * @private - */ -function handleUpEvent_(evt) { - this.rBush_.clear(); - this.writeCircleGeometry_(this.dragSegments_[0][0].feature, - this.dragSegments_[0][0].geometry); - - if (this.modified_) { - /** @type {ModifyEvent} */ - const event = new ngeoCustomEvent('modifyend', {features: this.features_}); - this.dispatchEvent(event); - this.modified_ = false; + return olInteractionPointer.prototype.handleEvent.call(this, mapBrowserEvent) && !handled; } - return false; } - /** - * Handles the {@link import("ol/MapBrowserEvent.js").default map browser event} and may modify the - * geometry. - * @param {import("ol/MapBrowserEvent.js").default} mapBrowserEvent Map browser event. - * @return {boolean} `false` to stop event propagation. - * @this {import("ngeo/interaction/ModifyCircle.js").default} - * @api + * @param {import("ol/interaction/Modify.js").SegmentData} a The first segment data. + * @param {import("ol/interaction/Modify.js").SegmentData} b The second segment data. + * @return {number} The difference in indexes. */ -function handleEvent(mapBrowserEvent) { - if (!(mapBrowserEvent instanceof olMapBrowserPointerEvent)) { - return true; - } - - let handled; - if (!mapBrowserEvent.map.getView().getInteracting() && - mapBrowserEvent.type == 'pointermove' && !this.handlingDownUpSequence) { - this.handlePointerMove_(mapBrowserEvent); - } - - return olInteractionPointer.prototype.handleEvent.call(this, mapBrowserEvent) && !handled; +function compareIndexes(a, b) { + return a.index - b.index; } diff --git a/src/interaction/ModifyRectangle.js b/src/interaction/ModifyRectangle.js index 5837f0ba7492..3c6437a0b9e8 100644 --- a/src/interaction/ModifyRectangle.js +++ b/src/interaction/ModifyRectangle.js @@ -15,7 +15,7 @@ import olSourceVector from 'ol/source/Vector.js'; */ class ModifyRectangle extends olInteractionPointer { /** - * @param {olx.interaction.ModifyOptions} options Options. + * @param {import('ol/interaction/Modify.js').Options} options Options. * @fires import("ngeo/interaction/ModifyCircleEvent.js").default */ constructor(options) { @@ -104,7 +104,7 @@ class ModifyRectangle extends olInteractionPointer { return; } - const pointSource = this.vectorPoints_.getSource(); + const pointSource = /** @type {olSourceVector} */(this.vectorPoints_.getSource()); // from each corners, create a point feature and add it to the point layer. // each point is then associated with 2 siblings in order to update the @@ -171,7 +171,6 @@ class ModifyRectangle extends olInteractionPointer { willModifyFeatures_(evt) { if (!this.modified_) { this.modified_ = true; - /** @type {ModifyEvent} */ const event = new ngeoCustomEvent('modifystart', {features: this.features_}); this.dispatchEvent(event); this.params_ = this.initializeParams_(); @@ -255,7 +254,7 @@ class ModifyRectangle extends olInteractionPointer { const item = this.cache_[uid]; const corners = item.corners; for (let i = 0; i < corners.length; i++) { - this.vectorPoints_.getSource().removeFeature(corners[i]); + /** @type {olSourceVector} */(this.vectorPoints_.getSource()).removeFeature(corners[i]); } this.feature_ = null; corners.length = 0; @@ -298,8 +297,8 @@ class ModifyRectangle extends olInteractionPointer { handleDown_(evt) { const map = evt.map; - const feature = map.forEachFeatureAtPixel(evt.pixel, feature => - (feature.get('siblingX') && feature.get('siblingY') ? feature : undefined) + const feature = /** @type {olFeature} */(map.forEachFeatureAtPixel(evt.pixel, feature => + (feature.get('siblingX') && feature.get('siblingY') ? feature : undefined)) ); if (feature) { @@ -358,10 +357,10 @@ class ModifyRectangle extends olInteractionPointer { /** * Calculate the new position of a point as projected on a vector from origin to * destination. - * @param {import("ol/Pixel.js").default} origin Pixel of origin (opposite of the drag handle) - * @param {import("ol/Pixel.js").default} destination Pixel of destination (the handle we dragged) - * @param {import("ol/Pixel.js").default} vector The normalized vector to the point - * @return {import("ol/Pixel.js").default} The new pixel of the point + * @param {import("ol/pixel.js").Pixel} origin Pixel of origin (opposite of the drag handle) + * @param {import("ol/pixel.js").Pixel} destination Pixel of destination (the handle we dragged) + * @param {import("ol/pixel.js").Pixel} vector The normalized vector to the point + * @return {import("ol/pixel.js").Pixel} The new pixel of the point * @private */ calculateNewPixel_( @@ -387,7 +386,6 @@ class ModifyRectangle extends olInteractionPointer { */ handleUp_(evt) { if (this.modified_) { - /** @type {ModifyEvent} */ const event = new ngeoCustomEvent('modifyend', {features: this.features_}); this.dispatchEvent(event); this.params_ = null; @@ -406,7 +404,7 @@ class ModifyRectangle extends olInteractionPointer { /** * @typedef {Object} ModifyParams * @property {import("ol/coordinate.js").Coordinate} originCoordinate - * @property {import("ol/Pixel.js").default} originPixel + * @property {import("ol/pixel.js").Pixel} originPixel * @property {import("ol/geom/Point.js").default} siblingXPoint * @property {import("ol/geom/Point.js").default} siblingYPoint * @property {Array} vectorX diff --git a/src/interaction/Rotate.js b/src/interaction/Rotate.js index ef6d0053cf96..d8a2d4dca9b5 100644 --- a/src/interaction/Rotate.js +++ b/src/interaction/Rotate.js @@ -29,7 +29,7 @@ import olSourceVector from 'ol/source/Vector.js'; */ export default class extends olInteractionPointer { /** - * @param {olx.interaction.ModifyOptions} options Options. + * @param {import('ol/interaction/Modify.js').Options} options Options. * @fires import("ngeo/interaction/ModifyCircleEvent.js").default */ constructor(options) { @@ -86,7 +86,7 @@ export default class extends olInteractionPointer { this.feature_ = null; /** - * @type {import("ol/Pixel.js").default} + * @type {import("ol/pixel.js").Pixel} * @private */ this.coordinate_ = null; @@ -170,7 +170,7 @@ export default class extends olInteractionPointer { const point = new olGeomPoint(this.getCenterCoordinate_(geometry)); const centerFeature = new olFeature(point); this.centerFeatures_[uid] = centerFeature; - this.overlay_.getSource().addFeature(centerFeature); + /** @type {olSourceVector} */(this.overlay_.getSource()).addFeature(centerFeature); } /** @@ -180,7 +180,6 @@ export default class extends olInteractionPointer { willModifyFeatures_(evt) { if (!this.modified_) { this.modified_ = true; - /** @type {ModifyEvent} */ const event = new ngeoCustomEvent('modifystart', {features: this.features_}); this.dispatchEvent(event); } @@ -192,13 +191,12 @@ export default class extends olInteractionPointer { */ removeFeature_(feature) { this.feature_ = null; - //this.overlay_.getSource().removeFeature(feature); if (feature) { const uid = olUtilGetUid(feature); if (this.centerFeatures_[uid]) { - this.overlay_.getSource().removeFeature(this.centerFeatures_[uid]); + /** @type {olSourceVector} */(this.overlay_.getSource()).removeFeature(this.centerFeatures_[uid]); delete this.centerFeatures_[uid]; } } @@ -256,7 +254,7 @@ export default class extends olInteractionPointer { if (feature) { this.coordinate_ = evt.coordinate; - this.feature_ = feature; + this.feature_ = /** @type {olFeature} */(feature); const geometry = (this.feature_.getGeometry()); if (geometry !== undefined) { this.centerCoordinate_ = this.getCenterCoordinate_(geometry); diff --git a/src/interaction/Translate.js b/src/interaction/Translate.js index a7cfd9a8123b..88d34d5b07b1 100644 --- a/src/interaction/Translate.js +++ b/src/interaction/Translate.js @@ -15,7 +15,7 @@ import olSourceVector from 'ol/source/Vector.js'; * @typedef {Object} TranslateOptions * @property {import("ol/Collection.js").default.} [features] Only features contained in this collection will be able * to be translated. If not specified, all features on the map will be able to be translated. - * @property {import("ol/style/Style.js").default|Array.|import('ol/style/Style.js').StyleFunction} [style] Style for the center features + * @property {import("ol/style/Style.js").StyleLike} [style] Style for the center features * added by the translate interaction to to show that features can be moved. */ diff --git a/src/map/FeatureOverlayMgr.js b/src/map/FeatureOverlayMgr.js index 91e464a92bf1..d484179f3863 100644 --- a/src/map/FeatureOverlayMgr.js +++ b/src/map/FeatureOverlayMgr.js @@ -150,7 +150,7 @@ FeatureOverlayMgr.prototype.init = function(map) { /** - * @param {import("ol/style/Style.js").default|Array.|import("ol/style/Style.js").StyleFunction} style + * @param {import("ol/style/Style.js").StyleLike} style * Style. * @param {number} groupIndex Group index. * @export