Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// show contextual menu when clicking on certain types of features
if (feature instanceof olFeature) {
const resolutions = this.map.getView().getResolution();
if (!resolutions) {
throw new Error('Missing resolutions');
}
const vertexInfo = this.ngeoFeatureHelper_.getVertexInfoAtCoordinate(
feature, coordinate, resolutions);
if (vertexInfo) {
this.vertexInfo_ = vertexInfo;
this.menuVertex_.open(coordinate);
} else {
const type = this.ngeoFeatureHelper_.getType(feature);
if (
type === ngeoGeometryType.POLYGON ||
type === ngeoGeometryType.MULTI_POLYGON ||
type === ngeoGeometryType.LINE_STRING ||
type === ngeoGeometryType.MULTI_LINE_STRING
) {
this.menu_.open(coordinate);
}
}
evt.preventDefault();
evt.stopPropagation();
}
}
};
if (feature) {
this.closeMenu_();
/** @type {import('ngeo/Menu').MenuActionOptions[]} */
let actions = [];
const resolution = this.map.getView().getResolution();
if (resolution === undefined) {
throw new Error('Missing resolution');
}
const vertexInfo = this.featureHelper_.getVertexInfoAtCoordinate(feature, coordinate, resolution);
if (!vertexInfo) {
const type = this.featureHelper_.getType(feature);
if (type == ngeoGeometryType.CIRCLE ||
type == ngeoGeometryType.LINE_STRING ||
type == ngeoGeometryType.POLYGON ||
type == ngeoGeometryType.RECTANGLE) {
actions = actions.concat([{
cls: 'fas fa-arrows-alt',
label: gettextCatalog.getString('Move'),
name: 'move'
}, {
cls: 'fas fa-undo fa-flip-horizontal',
label: gettextCatalog.getString('Rotate'),
name: 'rotate'
}]);
}
}
actions = actions.concat([{
cls: 'fa fa-trash',
label: vertexInfo ? gettextCatalog.getString('Delete vertex') :
options.precision = $injector.get('ngeoMeasurePrecision');
}
const measureArea = new ngeoInteractionMeasureArea($filter('ngeoUnitPrefix'), gettextCatalog, options);
if (drawFeatureCtrl.uid) {
measureArea.set(
'ngeo-interaction-draw-uid',
`${drawFeatureCtrl.uid}-area`
);
}
drawFeatureCtrl.registerInteraction(measureArea);
drawFeatureCtrl.measureArea = measureArea;
listen(measureArea, 'measureend', drawFeatureCtrl.handleDrawEnd.bind(
drawFeatureCtrl, ngeoGeometryType.POLYGON
), drawFeatureCtrl);
listen(measureArea, 'change:active', drawFeatureCtrl.handleActiveChange, drawFeatureCtrl);
}
};
this.features = new olCollection();
/**
* @type {string}
*/
this.pointGeomType = ngeoGeometryType.POINT;
/**
* @type {string}
*/
this.lineStringGeomType = ngeoGeometryType.LINE_STRING;
/**
* @type {string}
*/
this.polygonGeomType = ngeoGeometryType.POLYGON;
const vector = new olLayerVector({
source: new olSourceVector({
wrapX: false,
features: this.features
})
});
/**
* @type {import("ol/Map.js").default}
*/
this.map = new olMap({
layers: [
new olLayerTile({
source: new olSourceOSM()
}),