Skip to content

Commit

Permalink
Add example in desktop interface and fix issue with snapping
Browse files Browse the repository at this point in the history
  • Loading branch information
llienher committed Jul 25, 2019
1 parent 851613e commit eabe6c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 4 additions & 0 deletions contribs/gmf/apps/desktop/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ngeoProjEPSG21781 from 'ngeo/proj/EPSG21781.js';
import * as olBase from 'ol/index.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 @@ -123,6 +124,9 @@ exports.module = angular.module('Appdesktop', [
gmfControllersAbstractDesktopController.module.name,
]);

exports.module.value('ngeoSnappingTolerance', 20);
exports.module.value('ngeoSnappingSource', new olSourceVector());

This comment has been minimized.

Copy link
@arnaud-morvan

arnaud-morvan Aug 22, 2019

Member

Hello @llienher : this should go in abstract controller for the desktop and desktop_alt applications.


exports.module.value('gmfContextualdatacontentTemplateUrl', 'gmf/contextualdata');
exports.module.run(/* @ngInject */ ($templateCache) => {
$templateCache.put('gmf/contextualdata', require('./contextualdata.html'));
Expand Down
21 changes: 8 additions & 13 deletions contribs/gmf/src/editing/Snapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import * as olBase from 'ol/index.js';
import * as olEvents from 'ol/events.js';
import olCollection from 'ol/Collection.js';
import olFormatWFS from 'ol/format/WFS.js';
import olInteractionSnap from 'ol/interaction/Snap.js';
import olInteractionSnap, {handleEvent as snapHandleEvent} from 'ol/interaction/Snap.js';
import {handleEvent as handlePointerEvent} from 'ol/interaction/Pointer.js';


/**
* The snapping service of GMF. Responsible of collecting the treeCtrls that
Expand Down Expand Up @@ -139,19 +141,12 @@ class CustomSnap extends olInteractionSnap {
document.body.addEventListener('keyup', () => {
this.modifierPressed = false;
});
}

handleEvent(evt) {
if (this.modifierPressed) {
return;
} else {
const result = this.snapTo(evt.pixel, evt.coordinate, evt.map);
if (result.snapped) {
evt.coordinate = result.vertex.slice(0, 2);
evt.pixel = result.vertexPixel;
this.handleEvent = (evt) => { // horrible hack
if (!this.modifierPressed) {
return snapHandleEvent.call(this, evt);
}
return super.handleEvent(evt);
}
return handlePointerEvent.call(this, evt);
};
}
}

Expand Down

0 comments on commit eabe6c7

Please sign in to comment.