Skip to content

Commit

Permalink
Merge pull request #4792 from camptocamp/cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
fredj committed Apr 3, 2019
2 parents c1aa96d + c68e573 commit 0aad938
Show file tree
Hide file tree
Showing 28 changed files with 46 additions and 59 deletions.
1 change: 0 additions & 1 deletion contribs/gmf/src/controllers/AbstractAppController.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import {findThemeByName} from 'gmf/theme/Themes.js';
* @property {import("ol/Collection.js").default.<import('ol/control/Control.js').default>|Array.<import('ol/control/Control.js').default>} [mapControls]
* @property {import("ol/Collection.js").default.<import('"ol/interaction/Interaction.js').default>|Array.<import('ol/interaction/Interaction.js').default>} [mapInteractions]
* @property {number} [mapPixelRatio]
* }} Config
*/


Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/datasource/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ngeoMiscWMSTime from 'ngeo/misc/WMSTime.js';
import {getUid as olUtilGetUid} from 'ol/util.js';
import * as olEvents from 'ol/events.js';
import olLayerTile from 'ol/layer/Tile.js';
import * as olObj from 'ol/obj.js';
import {clear as clearObject} from 'ol/obj.js';
import olLayerImage from 'ol/layer/Image.js';
import olSourceImageWMS from 'ol/source/ImageWMS.js';
import olSourceTileWMS from 'ol/source/TileWMS.js';
Expand Down Expand Up @@ -401,7 +401,7 @@ export class DatasourceManager {
}

// (2) Clear the cache
olObj.clear(this.dataSourcesCache_);
clearObject(this.dataSourcesCache_);
}

/**
Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/src/editing/EditFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {appendParams as olUriAppendParams} from 'ol/uri.js';
* @property {string} operator The name of the property for the comparison filter.
* @property {string} value The value for the comparison filter that must match the combinaison of
* the operator and property.
* }}
*/


Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/filters/SavedFilters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import angular from 'angular';
import * as olArray from 'ol/array.js';
import {remove as removeFromArray} from 'ol/array.js';


/**
Expand Down Expand Up @@ -173,7 +173,7 @@ export class SavedFilter {
remove(item) {

// (1) Remove the item
const found = olArray.remove(this.items, item);
const found = removeFromArray(this.items, item);

// (2) Update local storage
if (found && this.useLocalStorage_) {
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/filters/filterselectorComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import ngeoFilterRuleHelper from 'ngeo/filter/RuleHelper.js';

import ngeoFilterComponent from 'ngeo/filter/component.js';
import * as olEvents from 'ol/events.js';
import * as olArray from 'ol/array.js';
import {remove as removeFromArray} from 'ol/array.js';
import ngeoMapFeatureOverlayMgr from 'ngeo/map/FeatureOverlayMgr.js';

import 'bootstrap/js/src/dropdown.js';
Expand Down Expand Up @@ -444,7 +444,7 @@ class Controller {
*/
unregisterDataSource_(dataSource) {
if (dataSource.filtrable) {
olArray.remove(this.filtrableDataSources, dataSource);
removeFromArray(this.filtrableDataSources, dataSource);

if (this.gmfDataSourceBeingFiltered.dataSource === dataSource) {
this.gmfDataSourceBeingFiltered.dataSource = null;
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/layertree/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import ngeoMiscSyncArrays from 'ngeo/misc/syncArrays.js';
import ngeoMiscWMSTime from 'ngeo/misc/WMSTime.js';
import olLayerTile from 'ol/layer/Tile.js';
import olLayerLayer from 'ol/layer/Layer.js';
import * as olObj from 'ol/obj.js';
import {isEmpty} from 'ol/obj.js';
import olSourceImageWMS from 'ol/source/ImageWMS.js';
import olSourceTileWMS from 'ol/source/TileWMS.js';
import olSourceWMTS from 'ol/source/WMTS.js';
Expand Down Expand Up @@ -351,7 +351,7 @@ Controller.prototype.updateLayerDimensions_ = function(layer, node) {
dimensions[key] = node.dimensions[key];
}
}
if (!olObj.isEmpty(dimensions)) {
if (!isEmpty(dimensions)) {
const source = layer.getSource();
if (source instanceof olSourceWMTS) {
source.updateDimensions(dimensions);
Expand Down
3 changes: 1 addition & 2 deletions contribs/gmf/src/map/mousepositionComponent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import angular from 'angular';
import ngeoMiscFilters from 'ngeo/misc/filters.js';
import olControlMousePosition from 'ol/control/MousePosition.js';
import * as olProj from 'ol/proj.js';

import 'bootstrap/js/src/dropdown.js';

Expand Down Expand Up @@ -195,7 +194,7 @@ Controller.prototype.initOlControl_ = function() {
* @param {MousePositionProjection} projection The new projection to use.
*/
Controller.prototype.setProjection = function(projection) {
this.control_.setProjection(olProj.get(projection.code));
this.control_.setProjection(projection.code);
this.projection = projection;
};

Expand Down
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 @@ -47,7 +47,7 @@ module.run(/* @ngInject */ ($templateCache) => {
* @htmlAttribute {import("ol/Map.js").default} gmf-mobile-measurearea-map The map.
* @htmlAttribute {import("ol/style/Style.js").StyleLike=}
* gmf-mobile-measurearea-sketchstyle A style for the measure area.
* @param {string|function(!JQuery=, !angular.IAttributes=)}
* @param {string|function(!JQuery=, !angular.IAttributes=):string}
* gmfMobileMeasureAreaTemplateUrl Template URL for the directive.
* @return {angular.IDirective} The Directive Definition Object.
* @ngInject
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 @@ -47,7 +47,7 @@ module.run(/* @ngInject */ ($templateCache) => {
* @htmlAttribute {import("ol/Map.js").default} gmf-mobile-measurelength-map The map.
* @htmlAttribute {import("ol/style/Style.js").StyleLike=}
* gmf-mobile-measurelength-sketchstyle A style for the measure length.
* @param {string|function(!JQuery=, !angular.IAttributes=)}
* @param {string|function(!JQuery=, !angular.IAttributes=):string}
* gmfMobileMeasureLengthTemplateUrl Template URL for the directive.
* @return {angular.IDirective} The Directive Definition Object.
* @ngInject
Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/src/objectediting/toolsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {getUid as olUtilGetUid} from 'ol/util.js';
* @typedef {Object} ObjectEditingToolsOptions
* @property {number} [regularPolygonRadius=100] The radius of the shapes created by the regular polygon
* radius creation tool. The value is in map units.
* }}
*/


Expand Down
1 change: 0 additions & 1 deletion contribs/gmf/src/query/gridComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import 'bootstrap/js/src/dropdown.js';
* @property {import("ngeo/grid/Config.js").default} configuration Configuration used to initialize a grid.
* @property {import('ngeo/statemanager/WfsPermalink.js').QueryResultSource} source Results of the query
* source.
* }}
*/


Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/query/windowComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ngeoMiscSwipe from 'ngeo/misc/swipe.js';
import ngeoQueryMapQuerent from 'ngeo/query/MapQuerent.js';

import olCollection from 'ol/Collection.js';
import * as olObj from 'ol/obj.js';
import {isEmpty} from 'ol/obj.js';
import olStyleCircle from 'ol/style/Circle.js';
import olStyleFill from 'ol/style/Fill.js';
import olStyleStroke from 'ol/style/Stroke.js';
Expand Down Expand Up @@ -422,7 +422,7 @@ QueryWindowController.prototype.updateQueryResult_ = function(queryResult) {
const source = queryResult.sources[i];
source.features = source.features.filter((feature) => {
console.assert(feature);
return !olObj.isEmpty(getFilteredFeatureValues(feature));
return !isEmpty(getFilteredFeatureValues(feature));
});
this.ngeoQueryResult.sources.push(source);
this.ngeoQueryResult.total += source.features.length;
Expand Down
5 changes: 2 additions & 3 deletions contribs/gmf/src/search/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ngeoMessagePopoverComponent from 'ngeo/message/popoverComponent.js';

import ngeoSearchModule from 'ngeo/search/module.js';
import olFeature from 'ol/Feature.js';
import * as olColor from 'ol/color.js';
import {asArray as asColorArray} from 'ol/color.js';
import olGeomPoint from 'ol/geom/Point.js';
import olFormatGeoJSON from 'ol/format/GeoJSON.js';
import * as olProj from 'ol/proj.js';
Expand Down Expand Up @@ -43,7 +43,6 @@ import {appendParams as olUriAppendParams} from 'ol/uri.js';
* @property {string} url URL of the search service. Must contain a '%QUERY' term that will be
* replaced by the input string.
* @property {string} [datasetTitle]
* }}
*/


Expand Down Expand Up @@ -842,7 +841,7 @@ class SearchController {
console.assert(feature);
const style = this.styles_[feature.get('layer_name')] || this.styles_['default'];
if (this.color) {
const color = olColor.asArray(this.color);
const color = asColorArray(this.color);

const strokeColor = color.slice();
// 100% opacity for the stroke color
Expand Down
1 change: 0 additions & 1 deletion src/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import olOverlayPositioning from 'ol/OverlayPositioning.js';
* @property {boolean} [autoClose=true] Whether to automatically close the contextual menu when an action is
* clicked or not.
* @property {string} [title] A title to display as header of the contextual menu.
* }} MenuOptions
*/


Expand Down
6 changes: 3 additions & 3 deletions src/datasource/WMSGroup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ngeoDatasourceOGCGroup from 'ngeo/datasource/OGCGroup.js';
import ngeoDatasourceOGC from 'ngeo/datasource/OGC.js';
import * as olArray from 'ol/array.js';
import {remove as removeFromArray} from 'ol/array.js';


/**
Expand Down Expand Up @@ -199,12 +199,12 @@ export default class extends ngeoDatasourceOGCGroup {
delete this.wmsDataSourceUnregister_[id];

// Remove DS from the group
olArray.remove(this.dataSources, dataSource);
removeFromArray(this.dataSources, dataSource);

// Remove query source id
const ids = this.ngeoLayerHelper_.getQuerySourceIds(layer);
if (ids) {
olArray.remove(ids, id);
removeFromArray(ids, id);
}

if (this.dataSources.length) {
Expand Down
4 changes: 2 additions & 2 deletions src/filter/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ngeoFormatAttributeType from 'ngeo/format/AttributeType.js';
import ngeoRuleGeometry from 'ngeo/rule/Geometry.js';
import ngeoMapFeatureOverlay from 'ngeo/map/FeatureOverlay.js';
import {getUid as olUtilGetUid} from 'ol/util.js';
import * as olArray from 'ol/array.js';
import {remove as removeFromArray} from 'ol/array.js';
import 'ngeo/sass/font.scss';


Expand Down Expand Up @@ -370,7 +370,7 @@ class FilterController {
removeCustomRule(rule) {
rule.active = false;
this.timeout_(() => {
olArray.remove(this.customRules, rule);
removeFromArray(this.customRules, rule);
this.unregisterRule_(rule);
rule.destroy();
});
Expand Down
4 changes: 2 additions & 2 deletions src/map/FeatureOverlayMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import angular from 'angular';
import ngeoMapFeatureOverlay, {FeatureOverlay} from 'ngeo/map/FeatureOverlay.js';
import {getUid as olUtilGetUid} from 'ol/util.js';
import olLayerVector from 'ol/layer/Vector.js';
import * as olObj from 'ol/obj.js';
import {isEmpty} from 'ol/obj.js';
import olSourceVector from 'ol/source/Vector.js';
import {toFunction as toStyleFunction, createDefaultStyle as olStyleDefaultFunction} from 'ol/style/Style.js';

Expand Down Expand Up @@ -111,7 +111,7 @@ FeatureOverlayMgr.prototype.clear = function(groupIndex) {
for (const featureUid in group.features) {
this.removeFeature(group.features[featureUid], groupIndex);
}
console.assert(olObj.isEmpty(group.features));
console.assert(isEmpty(group.features));
};


Expand Down
6 changes: 3 additions & 3 deletions src/map/LayerHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import olLayerGroup from 'ol/layer/Group.js';
import olLayerImage from 'ol/layer/Image.js';
import olLayerTile from 'ol/layer/Tile.js';
import olLayerLayer from 'ol/layer/Layer.js';
import * as olObj from 'ol/obj.js';
import {isEmpty} from 'ol/obj.js';
import olSourceImageWMS from 'ol/source/ImageWMS.js';
import olSourceTileWMS from 'ol/source/TileWMS.js';
import olSourceWMTS, {optionsFromCapabilities} from 'ol/source/WMTS.js';
Expand Down Expand Up @@ -185,7 +185,7 @@ LayerHelper.prototype.createWMTSLayerFromCapabilitites = function(
layer: layerName
}));
const source = new olSourceWMTS(/** @type {import('ol/source/WMTS.js').Options} */ (options));
if (opt_dimensions && !olObj.isEmpty(opt_dimensions)) {
if (opt_dimensions && !isEmpty(opt_dimensions)) {
source.updateDimensions(opt_dimensions);
}
layer.setSource(source);
Expand Down Expand Up @@ -223,7 +223,7 @@ LayerHelper.prototype.createWMTSLayerFromCapabilititesObj = function(
console.assert(options);
const source = new olSourceWMTS(/** @type {import('ol/source/WMTS.js').Options} */(options));

if (opt_dimensions && !olObj.isEmpty(opt_dimensions)) {
if (opt_dimensions && !isEmpty(opt_dimensions)) {
source.updateDimensions(opt_dimensions);
}

Expand Down
6 changes: 3 additions & 3 deletions src/map/scaleselector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import angular from 'angular';
import * as olArray from 'ol/array.js';
import {numberSafeCompareFunction} from 'ol/array.js';
import olMap from 'ol/Map.js';
import * as olEvents from 'ol/events.js';
import 'bootstrap/js/src/dropdown.js';
Expand Down Expand Up @@ -82,7 +82,7 @@ module.run(/* @ngInject */ ($templateCache) => {
* @htmlAttribute {import("ol/Map.js").default} ngeo-scaleselector-map The map.
* @htmlAttribute {ScaleselectorOptions} ngeo-scaleselector-options
* Optional. The configuration options.
* @param {string|function(!JQuery=, !angular.IAttributes=): any} ngeoScaleselectorTemplateUrl Template URL
* @param {string|function(!JQuery=, !angular.IAttributes=): string} ngeoScaleselectorTemplateUrl Template URL
* for the directive.
* @return {angular.IDirective} Directive Definition Object.
* @ngInject
Expand Down Expand Up @@ -132,7 +132,7 @@ const ScaleselectorController = function($scope, $element, $attrs) {

$scope.$watch(() => Object.keys(this.scales).length, (newLength) => {
this.zoomLevels = Object.keys(this.scales).map(Number);
this.zoomLevels.sort(olArray.numberSafeCompareFunction);
this.zoomLevels.sort(numberSafeCompareFunction);
});

const mapExpr = $attrs['ngeoScaleselectorMap'];
Expand Down
4 changes: 2 additions & 2 deletions src/misc/FeatureHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ngeoFormatFeatureProperties from 'ngeo/format/FeatureProperties.js';
import ngeoGeometryType from 'ngeo/GeometryType.js';
import {getFormattedLength, getFormattedArea, getFormattedPoint} from 'ngeo/interaction/Measure.js';
import {getFormattedAzimutRadius} from 'ngeo/interaction/MeasureAzimut.js';
import * as olColor from 'ol/color.js';
import {fromString as colorFromString} from 'ol/color.js';
import * as olExtent from 'ol/extent.js';
import olFeature from 'ol/Feature.js';
import olGeomLineString from 'ol/geom/LineString.js';
Expand Down Expand Up @@ -952,7 +952,7 @@ FeatureHelper.prototype.getColorProperty = function(feature) {
* @return {import('ol/color.js').Color} Color.
*/
FeatureHelper.prototype.getRGBAColorProperty = function(feature) {
return olColor.fromString(this.getColorProperty(feature));
return colorFromString(this.getColorProperty(feature));
};


Expand Down
5 changes: 1 addition & 4 deletions src/misc/colorpickerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,11 @@ const DEFAULT_COLORS = [
* @constructor
* @private
* @hidden
* @param {angular.IScope} $scope Directive scope.
* @param {JQuery} $element Element.
* @param {angular.IAttributes} $attrs Attributes.
* @ngInject
* @ngdoc controller
* @ngname NgeoScaleselectorController
*/
function Controller($scope, $element, $attrs) {
function Controller() {

/**
* The set of color
Expand Down
4 changes: 1 addition & 3 deletions src/misc/datepickerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ module.directive('ngeoDatePicker', datePickerComponent);
/**
* DatePickerController - directive conttroller
* @param {!angular.IScope} $scope Angular scope.
* @param {!angular.auto.IInjectorService} $injector injector.
* @param {!import("ngeo/misc/Time.js").Time} ngeoTime time service.
* @param {!angular.gettext.gettextCatalog} gettextCatalog service.
* @constructor
Expand All @@ -119,8 +118,7 @@ module.directive('ngeoDatePicker', datePickerComponent);
* @ngdoc controller
* @ngname ngeoDatePickerController
*/
function Controller($scope, $injector,
ngeoTime, gettextCatalog) {
function Controller($scope, ngeoTime, gettextCatalog) {

/**
* @type {!import("ngeo/misc/Time.js").Time}
Expand Down
4 changes: 2 additions & 2 deletions src/print/Service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import angular from 'angular';
import ngeoPrintVectorEncoder from 'ngeo/print/VectorEncoder.js';
import ngeoMapLayerHelper from 'ngeo/map/LayerHelper.js';
import * as olArray from 'ol/array.js';
import {stableSort} from 'ol/array.js';
import olLayerImage from 'ol/layer/Image.js';
import olLayerTile from 'ol/layer/Tile.js';
import olLayerVector from 'ol/layer/Vector.js';
Expand Down Expand Up @@ -189,7 +189,7 @@ PrintService.prototype.encodeMap_ = function(map, scale, object) {
let layers = this.ngeoLayerHelper_.getFlatLayers(mapLayerGroup);

// Sort the layer by ZIndex
olArray.stableSort(layers, (layer_a, layer_b) => (layer_a.getZIndex() || 0) - (layer_b.getZIndex() || 0));
stableSort(layers, (layer_a, layer_b) => (layer_a.getZIndex() || 0) - (layer_b.getZIndex() || 0));
layers = layers.slice().reverse();

layers.forEach((layer) => {
Expand Down

0 comments on commit 0aad938

Please sign in to comment.