Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getOptionsFromMap = () => {
const {
map,
resolutionsFilter
} = this.props;
if (!_isEmpty(this.state.scales)) {
Logger.debug('Array with scales found. Returning');
return [];
}
if (!map) {
Logger.warn('Map component not found. Could not initialize options array.');
return [];
}
let scales = [];
let view = map.getView();
// use existing resolutions array if exists
let resolutions = view.getResolutions();
if (_isEmpty(resolutions)) {
for (let currentZoomLevel = view.getMaxZoom(); currentZoomLevel >= view.getMinZoom(); currentZoomLevel--) {
let resolution = view.getResolutionForZoom(currentZoomLevel);
if (resolutionsFilter(resolution)) {
this.pushScale(scales, resolution, view);
}
}
} else {
let reversedResolutions = _reverse(_clone(resolutions));
onLayerAddToMap,
wmsLayers,
map
} = this.props;
if (onLayerAddToMap) {
onLayerAddToMap(wmsLayers);
} else if (map) {
wmsLayers.forEach(layer => {
// Add layer to map if it is not added yet
if (!map.getLayers().getArray().includes(layer) ) {
map.addLayer(layer);
}
});
} else {
Logger.warn('Neither map nor onLayerAddToMap given in props. Will do nothing.');
}
}
getOptionsFromMap = () => {
const {
map,
resolutionsFilter
} = this.props;
if (!_isEmpty(this.state.scales)) {
Logger.debug('Array with scales found. Returning');
return [];
}
if (!map) {
Logger.warn('Map component not found. Could not initialize options array.');
return [];
}
let scales = [];
let view = map.getView();
// use existing resolutions array if exists
let resolutions = view.getResolutions();
if (_isEmpty(resolutions)) {
for (let currentZoomLevel = view.getMaxZoom(); currentZoomLevel >= view.getMinZoom(); currentZoomLevel--) {
let resolution = view.getResolutionForZoom(currentZoomLevel);
if (resolutionsFilter(resolution)) {
this.pushScale(scales, resolution, view);
onGeolocationChange = () => {
const position = this._geoLocationInteraction.getPosition();
const accuracy = this._geoLocationInteraction.getAccuracy();
let heading = this._geoLocationInteraction.getHeading() || 0;
const speed = this._geoLocationInteraction.getSpeed() || 0;
const x = position[0];
const y = position[1];
const fCoords = this._positions.getCoordinates();
const previous = fCoords[fCoords.length - 1];
const prevHeading = previous && previous[2];
if (prevHeading) {
let headingDiff = heading - MathUtil.mod(prevHeading);
// force the rotation change to be less than 180°
if (Math.abs(headingDiff) > Math.PI) {
var sign = (headingDiff >= 0) ? 1 : -1;
headingDiff = -sign * (2 * Math.PI - Math.abs(headingDiff));
}
heading = prevHeading + headingDiff;
}
this._positions.appendCoordinate([x, y, heading, Date.now()]);
// only keep the 20 last coordinates
this._positions.setCoordinates(this._positions.getCoordinates().slice(-20));
this.updateView();
this.props.onGeolocationChange({
// present or value is null).
if (noMatchCnt === Object.keys(feature.getProperties()).length) {
template = template.replace(res, noValueFoundText);
}
});
}
resolved = template;
// Fallback if no feature attribute is found.
if (!resolved) {
resolved = feature.getId();
}
// Replace any HTTP url with an <a> element.
resolved = StringUtil.urlify(resolved);
// Replace all newline breaks with a html <br> tag.
resolved = resolved.replace(/\n/g, '<br>');
return resolved;
}
}</a>
source.getUrls() ? source.getUrls()[0] : ''
: source.getUrl();
const params = {
LAYER: source.getParams().LAYERS,
VERSION: '1.3.0',
SERVICE: 'WMS',
REQUEST: 'getLegendGraphic',
FORMAT: 'image/png'
};
const queryString = UrlUtil.objectToRequestString(
Object.assign(params, extraParams));
return /\?/.test(url) ? `${url}&${queryString}` : `${url}?${queryString}`;
} else {
Logger.warn(`Source of "${layer.get('name')}" is currently not supported `
+ `by MapUtil.getLegendGraphicUrl.`);
return;
}
}
const isImageWMS = source instanceof OlSourceImageWMS;
if (isTiledWMS || isImageWMS) {
const source = layer.getSource();
const url = isTiledWMS ?
source.getUrls() ? source.getUrls()[0] : ''
: source.getUrl();
const params = {
LAYER: source.getParams().LAYERS,
VERSION: '1.3.0',
SERVICE: 'WMS',
REQUEST: 'getLegendGraphic',
FORMAT: 'image/png'
};
const queryString = UrlUtil.objectToRequestString(
Object.assign(params, extraParams));
return /\?/.test(url) ? `${url}&${queryString}` : `${url}?${queryString}`;
} else {
Logger.warn(`Source of "${layer.get('name')}" is currently not supported `
+ `by MapUtil.getLegendGraphicUrl.`);
return;
}
}
setLayerVisibility(layer: OlLayerBase, visibility: boolean) {
if (!(layer instanceof OlLayerBase) || !_isBoolean(visibility)) {
Logger.error('setLayerVisibility called without layer or visiblity.');
return;
}
if (layer instanceof OlLayerGroup) {
layer.getLayers().forEach((subLayer) => {
this.setLayerVisibility(subLayer, visibility);
});
} else {
layer.setVisible(visibility);
}
}
onFetchError(error: string) {
Logger.error(`Error while requesting Nominatim: ${error}`);
}
onFetchError(error: string) {
const {
onFetchError
} = this.props;
Logger.error(`Error while requesting WFS GetFeature: ${error}`);
this.setState({
fetching: false
}, () => {
if (isFunction(onFetchError)) {
onFetchError(error);
}
});
}