Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createDrawInteraction = pressed => {
const {
drawType,
map,
onDrawEnd,
onDrawStart,
digitizeLayerName,
drawInteractionConfig
} = this.props;
let geometryFunction;
let type = drawType;
// check whether the digitizeLayer is in map and set it from state if not
let digitizeLayer = MapUtil.getLayerByName(map, digitizeLayerName);
if (!digitizeLayer) {
map.addLayer(this.state.digitizeLayer);
}
if (drawType === DigitizeButton.RECTANGLE_DRAW_TYPE) {
geometryFunction = createBox();
type = DigitizeButton.CIRCLE_DRAW_TYPE as DrawType;
} else if (drawType === DigitizeButton.TEXT_DRAW_TYPE) {
type = DigitizeButton.POINT_DRAW_TYPE as DrawType;
this._digitizeFeatures.on('add', this.handleTextAdding);
}
const drawInteraction = new OlInteractionDraw({
source: this.state.digitizeLayer.getSource(),
type: type,
geometryFunction: geometryFunction,
initVectorLayer = map => {
const {
features,
featureStyle,
layerName
} = this.props;
if (!(map instanceof OlMap)) {
return;
}
if (MapUtil.getLayerByName(map, layerName)) {
return;
}
const source = new OlSourceVector({
features: features
});
const layer = new OlLayerVector({
name: layerName,
source: source,
style: featureStyle
});
map.addLayer(layer);
this._source = source;
createMeasureLayer() {
const {
measureLayerName,
fillColor,
strokeColor,
map
} = this.props;
let measureLayer = MapUtil.getLayerByName(map, measureLayerName);
if (!measureLayer) {
measureLayer = new OlLayerVector({
name: measureLayerName,
source: new OlSourceVector({
features: new OlCollection()
}),
style: new OlStyleStyle({
fill: new OlStyleFill({
color: fillColor
}),
stroke: new OlStyleStroke({
color: strokeColor,
width: 2
}),
image: new OlStyleCircle({
initVectorLayer = map => {
const {
features,
featureStyle,
layerName
} = this.props;
if (!(map instanceof OlMap)) {
return;
}
if (MapUtil.getLayerByName(map, layerName)) {
return;
}
const source = new OlSourceVector({
features: features
});
const layer = new OlLayerVector({
name: layerName,
source: source,
style: featureStyle
});
map.addLayer(layer);
this._source = source;
it ('creates a digitize vector layer, adds this to the map and assigns its value to state', () => {
let digitizeLayer = MapUtil.getLayerByName(map, 'react-geo_digitize');
expect(digitizeLayer).toBeUndefined();
const wrapper = setupWrapper();
digitizeLayer = MapUtil.getLayerByName(map, 'react-geo_digitize');
expect(digitizeLayer).toBeDefined();
expect(wrapper.instance()._digitizeLayer).toBe(digitizeLayer);
});
});
createDigitizeLayer = () => {
const {
digitizeLayerName,
map
} = this.props;
let digitizeLayer = MapUtil.getLayerByName(map, digitizeLayerName);
if (!digitizeLayer) {
digitizeLayer = new OlLayerVector({
name: digitizeLayerName,
source: new OlSourceVector({
features: new OlCollection(),
})
});
map.addLayer(digitizeLayer);
}
digitizeLayer.setStyle(this.getDigitizeStyleFunction);
this.setState({digitizeLayer});
}
it ('creates a digitize vector layer, adds this to the map and assigns its value to state', () => {
let digitizeLayer = MapUtil.getLayerByName(map, 'react-geo_digitize');
expect(digitizeLayer).toBeUndefined();
const wrapper = setupWrapper();
digitizeLayer = MapUtil.getLayerByName(map, 'react-geo_digitize');
expect(digitizeLayer).toBeDefined();
expect(wrapper.instance()._digitizeLayer).toBe(digitizeLayer);
});
});