Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kuenzli committed Dec 21, 2017
1 parent c68c9e2 commit c2d31f0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 36 deletions.
7 changes: 5 additions & 2 deletions contribs/gmf/examples/xsdattributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ goog.provide('gmfapp.xsdattributes');

goog.require('gmf.XSDAttributes');
/** @suppress {extraRequire} */
goog.require('ngeo.attributesComponent');
goog.require('ngeo.editing.attributesComponent');
goog.require('ol.Feature');


/** @type {!angular.Module} **/
gmfapp.module = angular.module('gmfapp', ['gmf']);
gmfapp.module = angular.module('gmfapp', [
gmf.module.name,
ngeo.editing.attributesComponent.name,
]);


gmfapp.module.value('gmfTreeUrl',
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/directives/editfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ goog.require('gmf.Snapping');
goog.require('gmf.SyncLayertreeMap');
goog.require('gmf.XSDAttributes');
/** @suppress {extraRequire} */
goog.require('ngeo.attributesComponent');
goog.require('ngeo.editing.attributesComponent');
/** @suppress {extraRequire} */
goog.require('ngeo.btnDirective');
/** @suppress {extraRequire} */
goog.require('ngeo.createfeatureDirective');
goog.require('ngeo.editing.createfeatureComponent');
goog.require('ngeo.DecorateInteraction');
goog.require('ngeo.map.LayerHelper');
goog.require('ngeo.misc.EventHelper');
Expand Down
4 changes: 2 additions & 2 deletions contribs/gmf/src/directives/objecteditingtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ goog.require('gmf.objecteditinggetwmsfeatureDirective');
/** @suppress {extraRequire} */
goog.require('ngeo.btnDirective');
/** @suppress {extraRequire} */
goog.require('ngeo.createfeatureDirective');
goog.require('ngeo.editing.createfeatureComponent');
/** @suppress {extraRequire} */
goog.require('ngeo.createregularpolygonfromclickDirective');
goog.require('ngeo.editing.createregularpolygonfromclickComponent');
goog.require('ngeo.DecorateInteraction');
goog.require('ngeo.ToolActivate');
/** @suppress {extraRequire} */
Expand Down
5 changes: 3 additions & 2 deletions examples/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ goog.provide('app.attributes');

goog.require('ngeo.format.XSDAttribute');
/** @suppress {extraRequire} */
goog.require('ngeo.attributesComponent');
goog.require('ngeo.editing.attributesComponent');
goog.require('ol.Feature');

goog.require('ngeo.map.module');
Expand All @@ -11,7 +11,8 @@ goog.require('ngeo.map.module');
/** @type {!angular.Module} */
app.module = angular.module('app', [
ngeo.module.name,
ngeo.map.module.name
ngeo.map.module.name,
ngeo.editing.attributesComponent.name,
]);


Expand Down
3 changes: 2 additions & 1 deletion examples/createfeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ goog.require('ngeo.ToolActivateMgr');
/** @suppress {extraRequire} */
goog.require('ngeo.btnDirective');
/** @suppress {extraRequire} */
goog.require('ngeo.createfeatureDirective');
goog.require('ngeo.editing.createfeatureComponent');
goog.require('ol.Collection');
goog.require('ol.Map');
goog.require('ol.View');
Expand All @@ -22,6 +22,7 @@ app.module = angular.module('app', [
ngeo.module.name,
ngeo.map.module.name,
ngeo.ToolActivateMgr.module.name,
ngeo.editing.createfeatureComponent.name,
]);


Expand Down
File renamed without changes.
26 changes: 16 additions & 10 deletions src/editing/attributescomponent.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
goog.provide('ngeo.attributesComponent');
goog.provide('ngeo.editing.attributesComponent');

goog.require('ol');
goog.require('ol.events');
goog.require('ngeo');
goog.require('ngeo.misc.EventHelper');

// FIXME Dont' forget to add ngeo.misc.EventHelper to the module


ngeo.editing.attributesComponent = angular.module('ngeoAttributes', [
]);

ngeo.module.requires.push(ngeo.editing.attributesComponent.name);

/**
* Component used to render the attributes of a feature into a form.
* Example:
Expand All @@ -26,7 +32,7 @@ goog.require('ngeo.misc.EventHelper');
* @ngdoc component
* @ngname ngeoAttributes
*/
ngeo.attributesComponent = {
ngeo.editing.attributesComponent.component_ = {
controller: 'ngeoAttributesController as attrCtrl',
bindings: {
'attributes': '=ngeoAttributesAttributes',
Expand All @@ -36,10 +42,10 @@ ngeo.attributesComponent = {
require: {
'form': '^'
},
templateUrl: () => `${ngeo.baseTemplateUrl}/attributes.html`
templateUrl: () => `${ngeo.baseModuleTemplateUrl}/editing/attributes.html`
};

ngeo.module.component('ngeoAttributes', ngeo.attributesComponent);
ngeo.editing.attributesComponent.component('ngeoAttributes', ngeo.editing.attributesComponent.component_);


/**
Expand All @@ -53,7 +59,7 @@ ngeo.module.component('ngeoAttributes', ngeo.attributesComponent);
* @ngdoc controller
* @ngname ngeoAttributesController
*/
ngeo.AttributesController = function($scope, ngeoEventHelper, gettextCatalog) {
ngeo.editing.attributesComponent.Controller_ = function($scope, ngeoEventHelper, gettextCatalog) {

/**
* The list of attributes to create the form with.
Expand Down Expand Up @@ -130,7 +136,7 @@ ngeo.AttributesController = function($scope, ngeoEventHelper, gettextCatalog) {
/**
* Initialise the component.
*/
ngeo.AttributesController.prototype.$onInit = function() {
ngeo.editing.attributesComponent.Controller_.prototype.$onInit = function() {
this.properties = this.feature.getProperties();

// Listen to the feature inner properties change and apply them to the form
Expand All @@ -150,7 +156,7 @@ ngeo.AttributesController.prototype.$onInit = function() {
* @param {string} name Attribute name
* @export
*/
ngeo.AttributesController.prototype.handleInputChange = function(name) {
ngeo.editing.attributesComponent.Controller_.prototype.handleInputChange = function(name) {
this.updating_ = true;
const value = this.properties[name];
this.feature.set(name, value);
Expand All @@ -161,7 +167,7 @@ ngeo.AttributesController.prototype.handleInputChange = function(name) {
/**
* Cleanup event listeners.
*/
ngeo.AttributesController.prototype.$onDestroy = function() {
ngeo.editing.attributesComponent.Controller_.prototype.$onDestroy = function() {
const uid = ol.getUid(this);
this.ngeoEventHelper_.clearListenerKey(uid);
};
Expand All @@ -171,7 +177,7 @@ ngeo.AttributesController.prototype.$onDestroy = function() {
* @param {ol.Object.Event} evt Event.
* @private
*/
ngeo.AttributesController.prototype.handleFeaturePropertyChange_ = function(evt) {
ngeo.editing.attributesComponent.Controller_.prototype.handleFeaturePropertyChange_ = function(evt) {
if (this.updating_) {
return;
}
Expand All @@ -180,4 +186,4 @@ ngeo.AttributesController.prototype.handleFeaturePropertyChange_ = function(evt)
};


ngeo.module.controller('ngeoAttributesController', ngeo.AttributesController);
ngeo.editing.attributesComponent.controller('ngeoAttributesController', ngeo.editing.attributesComponent.Controller_);
25 changes: 17 additions & 8 deletions src/editing/createfeaturecomponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
goog.provide('ngeo.createfeatureDirective');
goog.provide('ngeo.editing.createfeatureComponent');

goog.require('ngeo');
/** @suppress {extraRequire} */
Expand All @@ -7,6 +7,7 @@ goog.require('ngeo.interaction.MeasureArea');
goog.require('ngeo.interaction.MeasureLength');
goog.require('ngeo.misc.EventHelper');
goog.require('ngeo.utils');
goog.require('ol');
goog.require('ol.events');
goog.require('ol.Feature');
goog.require('ol.interaction.Draw');
Expand All @@ -15,6 +16,12 @@ goog.require('ol.style.Style');
// Don't forget to add module dependencies


ngeo.editing.createfeatureComponent = angular.module('ngeoCreatefeature', [
]);

ngeo.module.requires.push(ngeo.editing.createfeatureComponent.name);


/**
* A directive used to draw vector features of a single geometry type using
* either a 'draw' or 'measure' interaction. Once a feature is finished being
Expand Down Expand Up @@ -53,9 +60,9 @@ goog.require('ol.style.Style');
* @ngdoc directive
* @ngname ngeoCreatefeature
*/
ngeo.createfeatureDirective = function() {
ngeo.editing.createfeatureComponent.directive_ = function() {
return {
controller: ngeo.CreatefeatureController,
controller: 'ngeoCreatefeatureController',
bindToController: true,
scope: {
'active': '=ngeoCreatefeatureActive',
Expand All @@ -66,7 +73,7 @@ ngeo.createfeatureDirective = function() {
};
};

ngeo.module.directive('ngeoCreatefeature', ngeo.createfeatureDirective);
ngeo.editing.createfeatureComponent.directive('ngeoCreatefeature', ngeo.editing.createfeatureComponent.directive_);


/**
Expand All @@ -83,7 +90,7 @@ ngeo.module.directive('ngeoCreatefeature', ngeo.createfeatureDirective);
* @ngdoc controller
* @ngname ngeoCreatefeatureController
*/
ngeo.CreatefeatureController = function(gettextCatalog, $compile, $filter, $scope,
ngeo.editing.createfeatureComponent.Controller_ = function(gettextCatalog, $compile, $filter, $scope,
$timeout, ngeoEventHelper) {

/**
Expand Down Expand Up @@ -168,7 +175,7 @@ ngeo.CreatefeatureController = function(gettextCatalog, $compile, $filter, $scop
/**
* Initialize the directive.
*/
ngeo.CreatefeatureController.prototype.$onInit = function() {
ngeo.editing.createfeatureComponent.Controller_.prototype.$onInit = function() {
this.active = this.active === true;
const gettextCatalog = this.gettextCatalog_;

Expand Down Expand Up @@ -254,7 +261,7 @@ ngeo.CreatefeatureController.prototype.$onInit = function() {
* @param {ol.interaction.Draw.Event|ngeox.MeasureEvent} event Event.
* @export
*/
ngeo.CreatefeatureController.prototype.handleDrawEnd_ = function(event) {
ngeo.editing.createfeatureComponent.Controller_.prototype.handleDrawEnd_ = function(event) {
let sketch;
if (event.feature) {
// ol.interaction.Draw.Event
Expand Down Expand Up @@ -283,11 +290,13 @@ ngeo.CreatefeatureController.prototype.handleDrawEnd_ = function(event) {
/**
* Cleanup event listeners and remove the interaction from the map.
*/
ngeo.CreatefeatureController.prototype.$onDestroy = function() {
ngeo.editing.createfeatureComponent.Controller_.prototype.$onDestroy = function() {
this.timeout_(() => {
const uid = ol.getUid(this);
this.ngeoEventHelper_.clearListenerKey(uid);
this.interaction_.setActive(false);
this.map.removeInteraction(this.interaction_);
}, 0);
};

ngeo.editing.createfeatureComponent.controller('ngeoCreatefeatureController', ngeo.editing.createfeatureComponent.Controller_);
31 changes: 22 additions & 9 deletions src/editing/createregularpolygonfromclickcomponent.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
goog.provide('ngeo.createregularpolygonfromclickDirective');
goog.provide('ngeo.editing.createregularpolygonfromclickComponent');

goog.require('ngeo');
goog.require('ngeo.interaction.DrawRegularPolygonFromClick');
goog.require('ol.events');
goog.require('ol.Feature');


ngeo.editing.createregularpolygonfromclickComponent = angular.module('ngeoCreateregularpolygonfromclick', [
]);

ngeo.module.requires.push(ngeo.editing.createregularpolygonfromclickComponent.name);


/**
* A directive used to draw vector features of a single geometry type using
* either a 'draw' or 'measure' interaction. Once a feature is finished being
Expand Down Expand Up @@ -51,9 +57,9 @@ goog.require('ol.Feature');
* @ngdoc directive
* @ngname ngeoCreateregularpolygonfromclick
*/
ngeo.createregularpolygonfromclickDirective = function() {
ngeo.editing.createregularpolygonfromclickComponent.directive_ = function() {
return {
controller: ngeo.CreateregularpolygonfromclickController,
controller: 'ngeoCreateregularpolygonfromclickController',
bindToController: true,
scope: {
'active': '=ngeoCreateregularpolygonfromclickActive',
Expand All @@ -66,9 +72,10 @@ ngeo.createregularpolygonfromclickDirective = function() {
};
};

ngeo.module.directive(
ngeo.editing.createregularpolygonfromclickComponent.directive(
'ngeoCreateregularpolygonfromclick',
ngeo.createregularpolygonfromclickDirective);
ngeo.editing.createregularpolygonfromclickComponent.directive_
);


/**
Expand All @@ -80,7 +87,7 @@ ngeo.module.directive(
* @ngdoc controller
* @ngname ngeoCreateregularpolygonfromclickController
*/
ngeo.CreateregularpolygonfromclickController = function($scope) {
ngeo.editing.createregularpolygonfromclickComponent.Controller_ = function($scope) {

// == Scope properties ==

Expand Down Expand Up @@ -149,7 +156,7 @@ ngeo.CreateregularpolygonfromclickController = function($scope) {
/**
* Initialize the directive.
*/
ngeo.CreateregularpolygonfromclickController.prototype.$onInit = function() {
ngeo.editing.createregularpolygonfromclickComponent.Controller_.prototype.$onInit = function() {

this.interaction_ = new ngeo.interaction.DrawRegularPolygonFromClick({
angle: this.angle,
Expand All @@ -175,7 +182,7 @@ ngeo.CreateregularpolygonfromclickController.prototype.$onInit = function() {
* @param {ol.interaction.Draw.Event} evt Event.
* @private
*/
ngeo.CreateregularpolygonfromclickController.prototype.handleDrawEnd_ = function(evt) {
ngeo.editing.createregularpolygonfromclickComponent.Controller_.prototype.handleDrawEnd_ = function(evt) {
const feature = new ol.Feature(evt.feature.getGeometry());
this.features.push(feature);
};
Expand All @@ -185,8 +192,14 @@ ngeo.CreateregularpolygonfromclickController.prototype.handleDrawEnd_ = function
* Cleanup event listeners and remove the interaction from the map.
* @private
*/
ngeo.CreateregularpolygonfromclickController.prototype.handleDestroy_ = function() {
ngeo.editing.createregularpolygonfromclickComponent.Controller_.prototype.handleDestroy_ = function() {
ol.events.unlistenByKey(this.interactionListenerKey_);
this.interaction_.setActive(false);
this.map.removeInteraction(this.interaction_);
};


ngeo.editing.createregularpolygonfromclickComponent.controller(
'ngeoCreateregularpolygonfromclickController',
ngeo.editing.createregularpolygonfromclickComponent.Controller_
);
6 changes: 6 additions & 0 deletions src/editing/module.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
goog.provide('ngeo.editing.module');

goog.require('ngeo.editing.attributesComponent');
goog.require('ngeo.editing.createfeatureComponent');
goog.require('ngeo.editing.createregularpolygonfromclickComponent');

/**
* @type {!angular.Module}
*/
ngeo.editing.module = angular.module('ngeoEditingModule', [
ngeo.editing.attributesComponent.name,
ngeo.editing.createfeatureComponent.name,
ngeo.editing.createregularpolygonfromclickComponent.name,
]);

0 comments on commit c2d31f0

Please sign in to comment.