Skip to content

Commit

Permalink
Merge pull request #4554 from camptocamp/fix-measure
Browse files Browse the repository at this point in the history
Fix measure
  • Loading branch information
sbrunner committed Jan 25, 2019
2 parents a625a4c + a207661 commit ba2779d
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 106 deletions.
2 changes: 1 addition & 1 deletion contribs/gmf/src/mobile/measure/areaComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default=}
* @htmlAttribute {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction=}
* gmf-mobile-measurearea-sketchstyle A style for the measure area.
* @param {string|function(!JQuery=, !angular.IAttributes=)}
* gmfMobileMeasureAreaTemplateUrl Template URL for the directive.
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/mobile/measure/baseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default}
* @type {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction}
* @export
*/
this.sketchStyle = new olStyleStyle({
Expand Down
2 changes: 1 addition & 1 deletion contribs/gmf/src/mobile/measure/lengthComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default=}
* @htmlAttribute {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction=}
* gmf-mobile-measurelength-sketchstyle A style for the measure length.
* @param {string|function(!JQuery=, !angular.IAttributes=)}
* gmfMobileMeasureLengthTemplateUrl Template URL for the directive.
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/mobile/measure/pointComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default=}
* @htmlAttribute {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction=}
* gmf-mobile-measurepoint-sketchstyle A style for the measure point.
* @param {string|function(!JQuery=, !angular.IAttributes=)}
* gmfMobileMeasurePointTemplateUrl Template URL for the directive.
Expand Down Expand Up @@ -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").default>|import("ol/StyleFunction.js").default}
* @type {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction}
* @export
*/
this.sketchStyle;
Expand Down
10 changes: 5 additions & 5 deletions src/draw/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import olFeature from 'ol/Feature.js';
* @ngdoc controller
* @ngname ngeoDrawfeatureController
*/
function Controller($scope, $sce, gettextCatalog,
export function DrawController($scope, $sce, gettextCatalog,
ngeoFeatureHelper, ngeoFeatures) {

/**
Expand Down Expand Up @@ -144,7 +144,7 @@ function Controller($scope, $sce, gettextCatalog,
* @param {import("ol/interaction/Interaction.js").default} interaction Interaction to register.
* @export
*/
Controller.prototype.registerInteraction = function(
DrawController.prototype.registerInteraction = function(
interaction) {
this.interactions_.push(interaction);
interaction.setActive(false);
Expand All @@ -160,7 +160,7 @@ Controller.prototype.registerInteraction = function(
* @param {import("ol/Object/Event.js").default} event Event.
* @export
*/
Controller.prototype.handleActiveChange = function(event) {
DrawController.prototype.handleActiveChange = function(event) {
this.active = this.interactions_.some(interaction => interaction.getActive(), this);
};

Expand All @@ -172,7 +172,7 @@ Controller.prototype.handleActiveChange = function(event) {
* @param {import("ol/interaction/Draw/Event.js").default|MeasureEvent} event Event.
* @export
*/
Controller.prototype.handleDrawEnd = function(type, event) {
DrawController.prototype.handleDrawEnd = function(type, event) {
let sketch;
if (event.feature) {
// ol.interaction.Draw.Event
Expand Down Expand Up @@ -243,7 +243,7 @@ const module = angular.module('ngeoDrawfeatureController', [
ngeoMiscBtnComponent.name,
ngeoMiscFeatureHelper.name,
]);
module.controller('ngeoDrawfeatureController', Controller);
module.controller('ngeoDrawfeatureController', DrawController);


export default module;
4 changes: 2 additions & 2 deletions src/geolocation/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default} [accuracyFeatureStyle] The style to
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [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").default>|import("ol/StyleFunction.js").default} [positionFeatureStyle] The style to
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [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.
Expand Down
4 changes: 2 additions & 2 deletions src/geolocation/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default} [accuracyFeatureStyle] The style to
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [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").default>|import("ol/StyleFunction.js").default} [positionFeatureStyle] The style to
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [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
Expand Down
10 changes: 6 additions & 4 deletions src/interaction/Measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ import olStyleStyle from 'ol/style/Style.js';
* just activated the interaction.
* @property {Element} [continueMsg] Element including the message to display in the help tooltip when the
* user already added the first point.
* @property {number} [precision] Defines the number of decimals to keep in the measurement. If not defined,
* @property {number} [precision] Defines the number of digits 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").default>|import("ol/StyleFunction.js").default} [style] The style to be used when
* @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").default>|import('ol/style/Style.js').StyleFunction} [style] The style to be used when
* drawing is finished.
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default} [sketchStyle] The style to be used
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [sketchStyle] The style to be used
* while drawing.
*/

Expand Down Expand Up @@ -215,7 +217,7 @@ class Measure extends olInteractionInteraction {
* Creates the draw interaction.
*
* @abstract
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default|undefined}
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction|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
Expand Down
28 changes: 14 additions & 14 deletions src/interaction/MeasureAzimut.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ export default class extends ngeoInteractionMeasure {
* @return {string} Formatted measure.
*/
getFormattedAzimut(line, decimals, format) {
const azimut = this.getAzimut(line);
const azimut = getAzimut(line);
return `${format(azimut, decimals)}°`;
}
}

/**
* Compute azimut from a 2 points line.
* @param {import("ol/geom/LineString.js").default} line LineString.
* @return {number} Azimut value.
*/
getAzimut(line) {
const coords = line.getCoordinates();
const dx = coords[1][0] - coords[0][0];
const dy = coords[1][1] - coords[0][1];
const rad = Math.acos(dy / Math.sqrt(dx * dx + dy * dy));
const factor = dx > 0 ? 1 : -1;
return (factor * rad * 180 / Math.PI) % 360;
}
/**
* Compute azimut from a 2 points line.
* @param {import("ol/geom/LineString.js").default} line LineString.
* @return {number} Azimut value.
*/
export function getAzimut(line) {
const coords = line.getCoordinates();
const dx = coords[1][0] - coords[0][0];
const dy = coords[1][1] - coords[0][1];
const rad = Math.acos(dy / Math.sqrt(dx * dx + dy * dy));
const factor = dx > 0 ? 1 : -1;
return (factor * rad * 180 / Math.PI) % 360;
}


Expand Down
4 changes: 2 additions & 2 deletions src/interaction/MeasureBaseOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
* @property {number} [precision]
* @property {boolean} [displayHelpTooltip]
* @property {Element} [startMsg]
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default} [style]
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default} [sketchStyle]
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [style]
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [sketchStyle]
*/
2 changes: 1 addition & 1 deletion src/interaction/MobileDraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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").default>|import("ol/StyleFunction.js").default} [style] Style for sketch features.
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [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`.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/interaction/Translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import olSourceVector from 'ol/source/Vector.js';
* @typedef {Object} TranslateOptions
* @property {import("ol/Collection.js").default.<import("ol/Feature.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").default>|import("ol/StyleFunction.js").default} [style] Style for the center features
* @property {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} [style] Style for the center features
* added by the translate interaction to to show that features can be moved.
*/

Expand Down
4 changes: 2 additions & 2 deletions src/interaction/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {createEditingStyle} from 'ol/style/Style.js';


/**
* @return {import("ol/StyleFunction.js").default} Styles.
* @return {import('ol/style/Style.js').StyleFunction} Styles.
*/
export function getDefaultDrawStyleFunction() {
const style = createEditingStyle();
Expand All @@ -24,7 +24,7 @@ export function getDefaultDrawStyleFunction() {


/**
* @return {import("ol/StyleFunction.js").default} Styles.
* @return {import('ol/style/Style.js').StyleFunction} Styles.
*/
export function getDefaultModifyStyleFunction() {
const style = createEditingStyle();
Expand Down
15 changes: 9 additions & 6 deletions src/map/BackgroundLayerMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import ngeoLayerHelper from 'ngeo/map/LayerHelper.js';


/**
* @typedef {import("ngeo/CustomEvent.js").default.<{
* @typedef {Object} BackgroundEventDetails
* @property {import("ol/layer/Base.js").default} current
* @property {import("ol/layer/Base.js").default} previous
* }>} BackgroundEvent
*/


/**
* @typedef {import("ngeo/CustomEvent.js").default.<BackgroundEventDetails>} BackgroundEvent
*/


Expand Down Expand Up @@ -64,7 +68,7 @@ const BACKGROUNDLAYERGROUP_NAME = 'background';
*/
class BackgroundLayerMgr extends olObservable {
/**
* @param {import("ngeo/map/LayerHelper.js").default} ngeoLayerHelper Themes service.
* @param {import("ngeo/map/LayerHelper.js").LayerHelper} ngeoLayerHelper Themes service.
* @ngInject
*/
constructor(ngeoLayerHelper) {
Expand All @@ -78,7 +82,7 @@ class BackgroundLayerMgr extends olObservable {
this.mapUids_ = {};

/**
* @type {import("ngeo/map/LayerHelper.js").default}
* @type {import("ngeo/map/LayerHelper.js").LayerHelper}
* @private
*/
this.ngeoLayerHelper_ = ngeoLayerHelper;
Expand Down Expand Up @@ -187,8 +191,7 @@ class BackgroundLayerMgr extends olObservable {
}

layers.forEach((layer) => {
console.assert(layer instanceof olLayerLayer);
if (layer) {
if (layer instanceof olLayerLayer) {
let hasUpdates = false;
const updatedDimensions = {};
for (const key in layer.get('dimensions')) {
Expand Down
6 changes: 3 additions & 3 deletions src/map/FeatureOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as olEvents from 'ol/events.js';

/**
* @constructor
* @param {import("ngeo/map/FeatureOverlayMgr.js").default} manager The feature overlay manager.
* @param {import("ngeo/map/FeatureOverlayMgr.js").FeatureOverlayMgr} manager The feature overlay manager.
* @param {number} index This feature overlay's index.
*/
export function FeatureOverlay(manager, index) {

/**
* @type {import("ngeo/map/FeatureOverlayMgr.js").default}
* @type {import("ngeo/map/FeatureOverlayMgr.js").FeatureOverlayMgr}
* @private
*/
this.manager_ = manager;
Expand Down Expand Up @@ -85,7 +85,7 @@ FeatureOverlay.prototype.setFeatures = function(features) {

/**
* Set a style for the feature overlay.
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default} style
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import('ol/style/Style.js').StyleFunction} style
* Style.
* @export
*/
Expand Down
22 changes: 10 additions & 12 deletions src/map/FeatureOverlayMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import {getUid as olUtilGetUid} from 'ol/util.js';
import olLayerVector from 'ol/layer/Vector.js';
import * as olObj from 'ol/obj.js';
import olSourceVector from 'ol/source/Vector.js';
import olStyleStyle, {toFunction as toStyleFunction, createDefaultStyle as olStyleDefaultFunction} from 'ol/style/Style.js';
import {toFunction as toStyleFunction, createDefaultStyle as olStyleDefaultFunction} from 'ol/style/Style.js';


/**
* @typedef {Object}
* @property {import("ol/StyleFunction.js").default} styleFunction
* features: Object.<string, ol.Feature>
* }} MapFeatureOverlayGroup
* @typedef {Object} MapFeatureOverlayGroup
* @property {import('ol/style/Style.js').StyleFunction} styleFunction
* @property {Object.<string, import('ol/Feature.js').default>} features
*/


Expand All @@ -37,16 +36,16 @@ import olStyleStyle, {toFunction as toStyleFunction, createDefaultStyle as olSty
* @ngdoc service
* @ngname ngeoFeatureOverlayMgr
*/
function FeatureOverlayMgr() {
export function FeatureOverlayMgr() {

/**
* @type {Object.<string, number>}
* @type {Object<string, number>}
* @private
*/
this.featureUidToGroupIndex_ = {};

/**
* @type {Array.<MapFeatureOverlayGroup>}
* @type {Array<MapFeatureOverlayGroup>}
* @private
*/
this.groups_ = [];
Expand Down Expand Up @@ -128,7 +127,7 @@ FeatureOverlayMgr.prototype.getLayer = function() {


/**
* @return {import("ngeo/map/FeatureOverlay.js").default} Feature overlay.
* @return {import("ngeo/map/FeatureOverlay.js").FeatureOverlay} Feature overlay.
* @export
*/
FeatureOverlayMgr.prototype.getFeatureOverlay = function() {
Expand All @@ -151,16 +150,15 @@ FeatureOverlayMgr.prototype.init = function(map) {


/**
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/StyleFunction.js").default} style
* @param {import("ol/style/Style.js").default|Array.<import("ol/style/Style.js").default>|import("ol/style/Style.js").StyleFunction} style
* Style.
* @param {number} groupIndex Group index.
* @export
*/
FeatureOverlayMgr.prototype.setStyle = function(style, groupIndex) {
console.assert(groupIndex >= 0);
console.assert(groupIndex < this.groups_.length);
this.groups_[groupIndex].styleFunction = style === null ?
olStyleStyle.defaultFunction : toStyleFunction(style);
this.groups_[groupIndex].styleFunction = style === null ? olStyleDefaultFunction : toStyleFunction(style);
};


Expand Down
Loading

0 comments on commit ba2779d

Please sign in to comment.