Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.3' into 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 20, 2019
2 parents 6d970e0 + 05e1254 commit 35a7e2e
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 49 deletions.
5 changes: 0 additions & 5 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ env:
jasmine: true
parserOptions:
ecmaVersion: 2017
plugins:
- '@openlayers'
rules:
no-console: 0
comma-dangle: 0
import/no-unresolved: 0
valid-jsdoc: 0
'@openlayers/valid-tsdoc':
- error
- requireReturn: false
max-len:
- error
- code: 110
Expand Down
3 changes: 3 additions & 0 deletions contribs/gmf/apps/desktop/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import EPSG2056 from '@geoblocks/proj/src/EPSG_2056.js';
import EPSG21781 from '@geoblocks/proj/src/EPSG_21781.js';
import Raven from 'raven-js/src/raven.js';
import RavenPluginsAngular from 'raven-js/plugins/angular.js';
import olSourceVector from 'ol/source/Vector.js';

if (!window.requestAnimationFrame) {
alert('Your browser is not supported, please update it or use another one. You will be redirected.\n\n'
Expand Down Expand Up @@ -121,6 +122,8 @@ const module = angular.module('Appdesktop', [
gmfControllersAbstractDesktopController.name,
]);

module.value('ngeoSnappingSource', new olSourceVector());

module.value('gmfContextualdatacontentTemplateUrl', 'gmf/contextualdata');
module.run(/* @ngInject */ ($templateCache) => {
// @ts-ignore: webpack
Expand Down
58 changes: 50 additions & 8 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import olInteractionSnap from 'ol/interaction/Snap.js';
* @constructor
* @param {angular.IHttpService} $http Angular $http service.
* @param {angular.IQService} $q The Angular $q service.
* @param {!angular.IScope} $rootScope Angular rootScope.
* @param {angular.IScope} $rootScope Angular rootScope.
* @param {angular.auto.IInjectorService} $injector Angular injector.
* @param {angular.ITimeoutService} $timeout Angular timeout service.
* @param {import("gmf/theme/Themes.js").ThemesService} gmfThemes The gmf Themes service.
* @param {import("gmf/layertree/TreeManager.js").LayertreeTreeManager} gmfTreeManager The gmf TreeManager
Expand All @@ -34,7 +35,9 @@ import olInteractionSnap from 'ol/interaction/Snap.js';
* @ngname gmfSnapping
* @hidden
*/
export function EditingSnappingService($http, $q, $rootScope, $timeout, gmfThemes, gmfTreeManager) {
export function EditingSnappingService(
$http, $q, $rootScope, $injector, $timeout, gmfThemes, gmfTreeManager
) {

// === Injected services ===

Expand Down Expand Up @@ -62,6 +65,12 @@ export function EditingSnappingService($http, $q, $rootScope, $timeout, gmfTheme
*/
this.timeout_ = $timeout;

/**
* @type {angular.auto.IInjectorService}
* @private
*/
this.injector_ = $injector;

/**
* @type {import("gmf/theme/Themes.js").ThemesService}
* @private
Expand Down Expand Up @@ -113,13 +122,32 @@ export function EditingSnappingService($http, $q, $rootScope, $timeout, gmfTheme
*/
this.ogcServers_ = null;

/**
* @type {ol.source.Vector|undefined}
* @private
*/
this.ngeoSnappingSource_ = this.injector_.has('ngeoSnappingSource') ?
this.injector_.get('ngeoSnappingSource') : undefined;
}


class CustomSnap extends olInteractionSnap {
constructor(options) {
super(options);
document.body.addEventListener('keydown', (evt) => {
this.setActive(evt.keyCode !== 17); // Ctrl key
});
document.body.addEventListener('keyup', () => {
this.setActive(true);
});
}
}


/**
* In order for a `ol.interaction.Snap` to work properly, it has to be added
* to the map after any draw interactions or other kinds of interactions that
* ineracts with features on the map.
* interacts with features on the map.
*
* This method can be called to make sure the Snap interactions are on top.
*
Expand All @@ -130,7 +158,7 @@ EditingSnappingService.prototype.ensureSnapInteractionsOnTop = function() {

let item;
for (const uid in this.cache_) {
item = this.cache_[+uid];
item = this.cache_[uid];
if (item.active) {
console.assert(item.interaction);
map.removeInteraction(item.interaction);
Expand Down Expand Up @@ -257,11 +285,11 @@ EditingSnappingService.prototype.registerTreeCtrl_ = function(treeCtrl) {
*/
EditingSnappingService.prototype.unregisterAllTreeCtrl_ = function() {
for (const uid in this.cache_) {
const item = this.cache_[+uid];
const item = this.cache_[uid];
if (item) {
item.stateWatcherUnregister();
this.deactivateItem_(item);
delete this.cache_[+uid];
delete this.cache_[uid];
}
}
};
Expand Down Expand Up @@ -396,7 +424,7 @@ EditingSnappingService.prototype.activateItem_ = function(item) {
const map = this.map_;
console.assert(map);

const interaction = new olInteractionSnap({
const interaction = new CustomSnap({
edge: item.snappingConfig.edge,
features: item.features,
pixelTolerance: item.snappingConfig.tolerance,
Expand Down Expand Up @@ -443,6 +471,7 @@ EditingSnappingService.prototype.deactivateItem_ = function(item) {
}

item.active = false;
this.refreshSnappingSource_();
};


Expand All @@ -453,7 +482,7 @@ EditingSnappingService.prototype.loadAllItems_ = function() {
this.mapViewChangePromise_ = null;
let item;
for (const uid in this.cache_) {
item = this.cache_[+uid];
item = this.cache_[uid];
if (item.active) {
this.loadItemFeatures_(item);
}
Expand Down Expand Up @@ -526,6 +555,7 @@ EditingSnappingService.prototype.loadItemFeatures_ = function(item) {
const readFeatures = new olFormatWFS().readFeatures(response.data);
if (readFeatures) {
item.features.extend(readFeatures);
this.refreshSnappingSource_();
}
});

Expand All @@ -547,6 +577,18 @@ EditingSnappingService.prototype.handleMapMoveEnd_ = function() {
);
};

/**
* @private
*/
EditingSnappingService.prototype.refreshSnappingSource_ = function() {
this.ngeoSnappingSource_.clear();
for (const uid in this.cache_) {
const item = this.cache_[uid];
if (item.active) {
this.ngeoSnappingSource_.addFeatures(item.features.getArray());
}
}
};

/**
* @typedef {Object<number, CacheItem>} Cache
Expand Down
1 change: 0 additions & 1 deletion examples/drawfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const module = angular.module('app', [
ngeoMiscToolActivateMgr.name,
]);


/**
* @param {!angular.IScope} $scope Angular scope.
* @param {import("ol/Collection.js").default.<import("ol/Feature.js").default>} ngeoFeatures Collection
Expand Down
41 changes: 26 additions & 15 deletions src/editing/createfeatureComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ module.directive('ngeoCreatefeature', editingCreateFeatureComponent);


/**
* @param {!angular.gettext.gettextCatalog} gettextCatalog Gettext catalog.
* @param {!angular.ICompileService} $compile Angular compile service.
* @param {!angular.IFilterService} $filter Angular filter
* @param {!angular.IScope} $scope Scope.
* @param {!angular.ITimeoutService} $timeout Angular timeout service.
* @param {!import("ngeo/misc/EventHelper.js").EventHelper} ngeoEventHelper Ngeo event helper service
* @param {angular.gettext.gettextCatalog} gettextCatalog Gettext catalog.
* @param {angular.ICompileService} $compile Angular compile service.
* @param {angular.IFilterService} $filter Angular filter
* @param {angular.auto.IInjectorService} $injector Angular injector service.
* @param {angular.IScope} $scope Scope.
* @param {angular.ITimeoutService} $timeout Angular timeout service.
* @param {import("ngeo/misc/EventHelper.js").EventHelper} ngeoEventHelper Ngeo event helper service
* @constructor
* @private
* @hidden
* @ngInject
* @ngdoc controller
* @ngname ngeoCreatefeatureController
*/
function Controller(gettextCatalog, $compile, $filter, $scope, $timeout, ngeoEventHelper) {
function Controller(gettextCatalog, $compile, $filter, $injector, $scope, $timeout, ngeoEventHelper) {

/**
* @type {boolean}
Expand All @@ -109,46 +110,52 @@ function Controller(gettextCatalog, $compile, $filter, $scope, $timeout, ngeoEve
this.geomType;

/**
* @type {!import("ol/Map.js").default}
* @type {import("ol/Map.js").default}
*/
this.map;

/**
* @type {!angular.gettext.gettextCatalog}
* @type {angular.gettext.gettextCatalog}
* @private
*/
this.gettextCatalog_ = gettextCatalog;

/**
* @type {!angular.ICompileService}
* @type {angular.ICompileService}
* @private
*/
this.compile_ = $compile;

/**
* @type {!angular.IFilterService}
* @type {angular.IFilterService}
* @private
*/
this.filter_ = $filter;

/**
* @type {!angular.IScope}
* @type {angular.IScope}
* @private
*/
this.scope_ = $scope;

/**
* @type {!angular.ITimeoutService}
* @type {angular.ITimeoutService}
* @private
*/
this.timeout_ = $timeout;

/**
* @type {!import("ngeo/misc/EventHelper.js").EventHelper}
* @type {import("ngeo/misc/EventHelper.js").EventHelper}
* @private
*/
this.ngeoEventHelper_ = ngeoEventHelper;

/**
* @type {angular.auto.IInjectorService}
* @private
*/
this.injector_ = $injector;

/**
* The draw or measure interaction responsible of drawing the vector feature.
* The actual type depends on the geometry type.
Expand Down Expand Up @@ -198,7 +205,11 @@ Controller.prototype.$onInit = function() {
{
style: new olStyleStyle(),
startMsg: this.compile_(`<div translate>${helpMsg}</div>`)(this.scope_)[0],
continueMsg: this.compile_(`<div translate>${contMsg}</div>`)(this.scope_)[0]
continueMsg: this.compile_(`<div translate>${contMsg}</div>`)(this.scope_)[0],
tolerance: this.injector_.has('ngeoSnappingTolerance') ?
this.injector_.get('ngeoSnappingTolerance') : undefined,
source: this.injector_.has('ngeoSnappingSource') ?
this.injector_.get('ngeoSnappingSource') : undefined,
}
);
} else if (this.geomType === ngeoGeometryType.POLYGON ||
Expand Down
2 changes: 1 addition & 1 deletion src/editing/createregularpolygonfromclickComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Controller.prototype.$onInit = function() {
*/
Controller.prototype.handleDrawEnd_ = function(evt) {
// @ts-ignore: evt should be of type {import('ol/interaction/Draw.js').DrawEvent but he is private
const feature = new olFeature(evt.feature.getGeometry());
const feature = new olFeature(evt.detail.feature.getGeometry());
this.features.push(feature);
};

Expand Down
2 changes: 1 addition & 1 deletion src/interaction/DrawRegularPolygonFromClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class extends olInteractionInteraction {
this.sides_ = options.sides !== undefined ? options.sides : 3;

/**
* @type {!Array.<import("ol/events.js").EventsKey>}
* @type {Array<import("ol/events.js").EventsKey>}
* @private
*/
this.listenerKeys_ = [];
Expand Down
6 changes: 2 additions & 4 deletions src/interaction/Measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ 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 {number} [tolerance] Defines the tolerance.
* @property {import("ol/style/Style.js").StyleLike} [style] The style to be used when
* drawing is finished.
* @property {import("ol/style/Style.js").StyleLike} [sketchStyle] The style to be used
* while drawing.
* @property {import('ol/source/Vector.js').default} [source] The source.
*/


Expand Down Expand Up @@ -219,13 +221,11 @@ class Measure extends olInteractionInteraction {
/**
* Creates the draw interaction.
*
* @abstract
* @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) {
return undefined;
Expand Down Expand Up @@ -406,10 +406,8 @@ class Measure extends olInteractionInteraction {
* Function implemented in inherited classes to compute measurement, determine
* where to place the tooltip and determine which help message to display.
*
* @abstract
* @param {function(string, ?import("ol/coordinate.js").Coordinate): void} callback The function
* to be called.
* @protected
*/
handleMeasure(callback) {}

Expand Down

0 comments on commit 35a7e2e

Please sign in to comment.