Skip to content

Commit

Permalink
Fix types in gmf objectediting
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Jan 29, 2019
1 parent fedc548 commit 09e9ed6
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 99 deletions.
4 changes: 2 additions & 2 deletions contribs/gmf/src/datasource/ExternalDataSourcesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ export class ExternalDatSourcesManager {
* using the `ol.getUid` method, plus a million.
*
* @param {!Object} layer WMS/WMTS Capability Layer object.
* @return {number} Data source id.
* @return {string} Data source id.
* @export
*/
function getId(layer) {
return olUtilGetUid(layer) + 1000000;
return `${olUtilGetUid(layer)}+1000000`;
}


Expand Down
6 changes: 2 additions & 4 deletions contribs/gmf/src/editing/EditFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ EditingEditFeature.prototype.getFeaturesInExtent = function(layerIds, extent) {
* define the url to the GMF Protocol (layers) a dummy promise returns an
* empty array of features if the url is not defined.
*
* @param {!Array.<number>} layerIds List of layer ids to get the features from.
* @param {!Array.<string>} layerIds List of layer ids to get the features from.
* @param {!Array.<!ComparisonFilter>} filters List of comparison filters
* @return {angular.IPromise} Promise.
*/
EditingEditFeature.prototype.getFeaturesWithComparisonFilters = function(
layerIds, filters
) {
EditingEditFeature.prototype.getFeaturesWithComparisonFilters = function(layerIds, filters) {
const properties = [];
const params = {};

Expand Down
15 changes: 5 additions & 10 deletions contribs/gmf/src/objectediting/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,11 @@ ObjecteditingManagerService.prototype.getFeature = function() {
if (!this.getFeatureDefered_) {
this.getFeatureDefered_ = this.q_.defer();

const geomType = this.ngeoLocation_.getParam(
ObjecteditingParam.GEOM_TYPE);
const id = this.ngeoLocation_.getParam(
ObjecteditingParam.ID);
const layer = this.ngeoLocation_.getParam(
ObjecteditingParam.LAYER);
const property = this.ngeoLocation_.getParam(
ObjecteditingParam.PROPERTY);
const theme = this.ngeoLocation_.getParam(
ObjecteditingParam.THEME);
const geomType = this.ngeoLocation_.getParam(ObjecteditingParam.GEOM_TYPE);
const id = this.ngeoLocation_.getParam(ObjecteditingParam.ID);
const layer = this.ngeoLocation_.getParam(ObjecteditingParam.LAYER);
const property = this.ngeoLocation_.getParam(ObjecteditingParam.PROPERTY);
const theme = this.ngeoLocation_.getParam(ObjecteditingParam.THEME);

if (geomType && id && layer && property && theme) {
this.gmfEditFeature_.getFeaturesWithComparisonFilters(
Expand Down
27 changes: 14 additions & 13 deletions contribs/gmf/src/objectediting/Query.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import angular from 'angular';
import gmfThemeThemes from 'gmf/theme/Themes.js';
import gmfThemeThemes, {getFlatNodes} from 'gmf/theme/Themes.js';
import {WMSInfoFormat} from 'ngeo/datasource/OGC.js';
import olFormatWMSGetFeatureInfo from 'ol/format/WMSGetFeatureInfo.js';
import olSourceImageWMS from 'ol/source/ImageWMS.js';


/**
* A service that collects all queryable layer nodes from all themes, stores
* them and use them to make WMS GetFeatureInfo queries. Queries can be made
Expand Down Expand Up @@ -90,7 +91,7 @@ ObjectEditingQuery.prototype.getQueryableLayersInfo = function() {
*
* @param {Array.<import('gmf/themes.js').GmfTheme>} themes List of theme nodes.
* @param {import('gmf/themes.js').GmfOgcServers} ogcServers List of ogc servers
* @return {Array.<ObjectEditingQueryableLayerInfo>} List of
* @return {Array.<import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo>} List of
* queryable layers information.
* @export
*/
Expand All @@ -101,7 +102,6 @@ function getQueryableLayersInfoFromThemes(
let theme;
let group;
let nodes;
let node;

for (let i = 0, ii = themes.length; i < ii; i++) {
theme = /** @type {import('gmf/themes.js').GmfTheme} */ (themes[i]);
Expand All @@ -114,23 +114,23 @@ function getQueryableLayersInfoFromThemes(
}

nodes = [];
gmfThemeThemes.getFlatNodes(group, nodes);
getFlatNodes(group, nodes);

for (let k = 0, kk = nodes.length; k < kk; k++) {
node = /** @type {import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayerWMS} */ (
nodes[k]);

const nodeGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (nodes[k]);
// Skip groups within groups
if (node.children && node.children.length) {
if (nodeGroup.children && nodeGroup.children.length) {
continue;
}

if (node.childLayers &&
node.childLayers[0] &&
node.childLayers[0].queryable
const nodeWMS = /** @type {import('gmf/themes.js').GmfLayerWMS} */ (nodes[k]);

if (nodeWMS.childLayers &&
nodeWMS.childLayers[0] &&
nodeWMS.childLayers[0].queryable
) {
queryableLayersInfo.push({
layerNode: node,
layerNode: nodeWMS,
ogcServer: ogcServers[group.ogcServer]
});
}
Expand All @@ -148,7 +148,7 @@ function getQueryableLayersInfoFromThemes(
* specific map to fetch a single feature. If no feature is found, a `null`
* value is returned.
*
* @param {ObjectEditingQueryableLayerInfo} layerInfo Queryable layer
* @param {import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo} layerInfo Queryable layer
* information.
* @param {import("ol/coordinate.js").Coordinate} coordinate Coordinate.
* @param {import("ol/Map.js").default} map Map.
Expand All @@ -170,6 +170,7 @@ ObjectEditingQuery.prototype.getFeatureInfo = function(layerInfo, coordinate, ma

const wmsSource = new olSourceImageWMS({
url: ogcServer.url,
projection: undefined,
params: {
layers: layersParam
}
Expand Down
83 changes: 40 additions & 43 deletions contribs/gmf/src/objectediting/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import angular from 'angular';
import gmfEditingEditFeature from 'gmf/editing/EditFeature.js';
import gmfLayertreeSyncLayertreeMap from 'gmf/layertree/SyncLayertreeMap.js';
import gmfLayertreeSyncLayertreeMap, {getLayer as syncLayertreeMapGetLayer} from 'gmf/layertree/SyncLayertreeMap.js';
import gmfLayertreeTreeManager from 'gmf/layertree/TreeManager.js';
import {isEmpty, toXY} from 'gmf/objectediting/geom.js';
import gmfObjecteditingQuery from 'gmf/objectediting/Query.js';
Expand Down Expand Up @@ -28,12 +28,7 @@ import olStyleFill from 'ol/style/Fill.js';
import olStyleStroke from 'ol/style/Stroke.js';
import olStyleStyle from 'ol/style/Style.js';

import {OL3Parser} from 'jsts/io';
const jsts = {
io: {
OL3Parser,
},
};
import jsts from 'jsts';


/**
Expand All @@ -50,6 +45,13 @@ const ObjecteditingState = {
};


/**
* @const
* @private
*/
export const NAMESPACE = 'oe';


/**
* @type {!angular.IModule}
*/
Expand Down Expand Up @@ -233,13 +235,13 @@ function Controller($scope, $timeout, gettextCatalog,
this.gmfObjectEditingQuery_ = gmfObjectEditingQuery;

/**
* @type {Array.<!ObjectEditingQueryableLayerInfo>}
* @type {Array.<!import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo>}
* @export
*/
this.queryableLayersInfo;

/**
* @type {ObjectEditingQueryableLayerInfo}
* @type {import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo}
* @export
*/
this.selectedQueryableLayerInfo;
Expand Down Expand Up @@ -578,7 +580,7 @@ Controller.prototype.undo = function() {
this.skipGeometryChange_ = true;

this.geometryChanges_.pop();
const clone = Controller.cloneGeometry_(
const clone = cloneGeometry(
this.geometryChanges_[this.geometryChanges_.length - 1]);

this.feature.setGeometry(clone);
Expand Down Expand Up @@ -681,7 +683,7 @@ Controller.prototype.unregisterInteractions_ = function() {
Controller.prototype.toggle_ = function(active) {

const keys = this.listenerKeys_;
const uid = `${Controller.NAMESPACE_}-${olUtilGetUid(this)}`;
const uid = `${NAMESPACE}-${olUtilGetUid(this)}`;
const toolMgr = this.ngeoToolActivateMgr_;

if (active) {
Expand Down Expand Up @@ -717,6 +719,7 @@ Controller.prototype.toggle_ = function(active) {
olEvents.listen(
window,
'beforeunload',
// @ts-ignore: strange API
this.handleWindowBeforeUnload_,
this
)
Expand Down Expand Up @@ -758,7 +761,7 @@ Controller.prototype.toggle_ = function(active) {
* @private
*/
Controller.prototype.undoAllChanges_ = function() {
const clone = Controller.cloneGeometry_(
const clone = cloneGeometry(
this.geometryChanges_[0]);
this.feature.setGeometry(clone);

Expand All @@ -780,7 +783,7 @@ Controller.prototype.resetGeometryChanges_ = function() {
}
if (this.geometryChanges_.length === 0) {
const geometry = this.feature.getGeometry();
const clone = Controller.cloneGeometry_(geometry);
const clone = cloneGeometry(geometry);
this.geometryChanges_.push(clone);
}
};
Expand All @@ -793,7 +796,7 @@ Controller.prototype.resetGeometryChanges_ = function() {
* geometries intersects with one an other first. Those that does are merged
* before being pushed to the changes.
*
* @param {import("ol/interaction/Modify/Event.js").default} evt Event.
* @param {import("ol/interaction/Modify.js").ModifyEvent} evt Event.
* @private
*/
Controller.prototype.handleModifyInteractionModifyEnd_ = function(
Expand All @@ -803,14 +806,14 @@ Controller.prototype.handleModifyInteractionModifyEnd_ = function(

if (geometry instanceof olGeomMultiPolygon) {
const jstsGeom = this.jstsOL3Parser_.read(geometry);
const jstsBuffered = jstsGeom.buffer(0);
const jstsBuffered = jstsGeom.buffer(0, undefined, undefined);
geometry = toMulti(this.jstsOL3Parser_.write(jstsBuffered));
this.skipGeometryChange_ = true;
this.feature.setGeometry(geometry.clone());
this.skipGeometryChange_ = false;
}

const clone = Controller.cloneGeometry_(geometry);
const clone = cloneGeometry(geometry);
console.assert(clone);
this.geometryChanges_.push(clone);
this.scope_.$apply();
Expand Down Expand Up @@ -841,14 +844,14 @@ Controller.prototype.initializeStyles_ = function(
fill: new olStyleFill({color: rgbaColor})
});

styles['Point'] = new olStyleStyle({
styles.Point = new olStyleStyle({
image
});
styles['MultiPoint'] = new olStyleStyle({
styles.MultiPoint = new olStyleStyle({
image
});

styles['LineString'] = [
styles.LineString = [
new olStyleStyle({
stroke: new olStyleStroke({
color: color,
Expand All @@ -857,11 +860,11 @@ Controller.prototype.initializeStyles_ = function(
})
];
if (incVertice) {
styles['LineString'].push(
styles.LineString.push(
this.ngeoFeatureHelper_.getVertexStyle(true)
);
}
styles['MultiLineString'] = [
styles.MultiLineString = [
new olStyleStyle({
stroke: new olStyleStroke({
color: color,
Expand All @@ -870,12 +873,12 @@ Controller.prototype.initializeStyles_ = function(
})
];
if (incVertice) {
styles['MultiLineString'].push(
styles.MultiLineString.push(
this.ngeoFeatureHelper_.getVertexStyle(true)
);
}

styles['Polygon'] = [
styles.Polygon = [
new olStyleStyle({
stroke: new olStyleStroke({
color: color,
Expand All @@ -887,11 +890,11 @@ Controller.prototype.initializeStyles_ = function(
})
];
if (incVertice) {
styles['Polygon'].push(
styles.Polygon.push(
this.ngeoFeatureHelper_.getVertexStyle(true)
);
}
styles['MultiPolygon'] = [
styles.MultiPolygon = [
new olStyleStyle({
stroke: new olStyleStroke({
color: color,
Expand All @@ -903,7 +906,7 @@ Controller.prototype.initializeStyles_ = function(
})
];
if (incVertice) {
styles['MultiPolygon'].push(
styles.MultiPolygon.push(
this.ngeoFeatureHelper_.getVertexStyle(true)
);
}
Expand Down Expand Up @@ -957,18 +960,18 @@ Controller.prototype.setFeatureStyle_ = function() {
Controller.prototype.registerTreeCtrl_ = function(treeCtrl) {

// Skip any Layertree controller that has a node that is not a leaf
const node = /** @type {import('gmf/themes.js').GmfGroup|import('gmf/themes.js').GmfLayer} */ (
treeCtrl.node);
if (node.children && node.children.length) {
const nodeGroup = /** @type {import('gmf/themes.js').GmfGroup} */ (treeCtrl.node);
if (nodeGroup.children && nodeGroup.children.length) {
return;
}

const nodeLayer = /** @type {import('gmf/themes.js').GmfLayer} */ (treeCtrl.node);
// Set editable WMS layer for refresh purpose
if (node.id === this.layerNodeId) {
const layer = gmfLayertreeSyncLayertreeMap.getLayer(treeCtrl);
console.assert(
layer instanceof olLayerImage || layer instanceof olLayerTile);
this.editableWMSLayer_ = layer;
if (nodeLayer.id === this.layerNodeId) {
const layer = syncLayertreeMapGetLayer(treeCtrl);
if (layer instanceof olLayerImage || layer instanceof olLayerTile) {
this.editableWMSLayer_ = layer;
}
}

};
Expand Down Expand Up @@ -1009,6 +1012,7 @@ Controller.prototype.handleWindowBeforeUnload_ = function(e) {
const gettextCatalog = this.gettextCatalog_;
if (this.dirty) {
const msg = gettextCatalog.getString('There are unsaved changes.');
// @ts-ignore: strange API
(e || window.event).returnValue = msg;
return msg;
}
Expand Down Expand Up @@ -1094,7 +1098,7 @@ Controller.prototype.handleFeatureGeometryChange_ = function() {


/**
* @param {Array.<ObjectEditingQueryableLayerInfo>} layersInfo List
* @param {Array.<import('gmf/objectediting/toolsComponent.js').ObjectEditingQueryableLayerInfo>} layersInfo List
* of queryable layers information, which contains the node and ogcServer.
* @private
*/
Expand Down Expand Up @@ -1128,7 +1132,7 @@ Controller.prototype.handleDestroy_ = function() {
* @return {?import("ol/geom/Geometry.js").default} A geometry clone or null value.
* @private
*/
export function cloneGeometry(geometry) {
function cloneGeometry(geometry) {
let clone = null;
if (geometry) {
clone = geometry.clone();
Expand All @@ -1137,13 +1141,6 @@ export function cloneGeometry(geometry) {
}


/**
* @const
* @private
*/
export const NAMESPACE = 'oe';


module.controller('GmfObjecteditingController',
Controller);

Expand Down

0 comments on commit 09e9ed6

Please sign in to comment.