How to use @terrestris/base-util - 10 common examples

To help you get started, we’ve selected a few @terrestris/base-util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrestris / react-geo / src / Field / ScaleCombo / ScaleCombo.tsx View on Github external
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));
github terrestris / react-geo / src / Container / AddWmsPanel / AddWmsPanel.tsx View on Github external
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.');
    }
  }
github terrestris / react-geo / src / Field / ScaleCombo / ScaleCombo.tsx View on Github external
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);
github terrestris / react-geo / src / Button / GeoLocationButton / GeoLocationButton.tsx View on Github external
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({
github terrestris / ol-util / src / FeatureUtil / FeatureUtil.js View on Github external
// 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>
github terrestris / ol-util / src / MapUtil / MapUtil.js View on Github external
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;
    }
  }
github terrestris / ol-util / src / MapUtil / MapUtil.js View on Github external
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;
    }
  }
github terrestris / react-geo / src / LayerTree / LayerTree.tsx View on Github external
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);
    }
  }
github terrestris / react-geo / src / Field / NominatimSearch / NominatimSearch.tsx View on Github external
onFetchError(error: string) {
    Logger.error(`Error while requesting Nominatim: ${error}`);
  }
github terrestris / react-geo / src / Field / WfsSearchInput / WfsSearchInput.tsx View on Github external
onFetchError(error: string) {
    const {
      onFetchError
    } = this.props;
    Logger.error(`Error while requesting WFS GetFeature: ${error}`);
    this.setState({
      fetching: false
    }, () => {
      if (isFunction(onFetchError)) {
        onFetchError(error);
      }
    });
  }