How to use turf-bbox - 6 common examples

To help you get started, we’ve selected a few turf-bbox 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 Vizzuality / gfw / app / javascript / components / world-map / selectors.js View on Github external
...country,
          strokeWidth: index + 1,
          coordinates: COUNTRIES_COORDINATES[country.geo_id],
          geoId: country.geo_id
        }))
      : [];

    const contextFlowsWithCoordinates = contextFlows.filter(
      f => typeof f.coordinates !== 'undefined'
    );

    if (contextFlowsWithCoordinates.length !== contextFlows.length) {
      console.warn('World map flows are missing geoids. Check your database.');
    }

    const [minX, , maxX] = bbox(
      lineString(contextFlowsWithCoordinates.map(f => f.coordinates))
    );
    const medianX = (maxX + minX) / 2;
    const originLeftOfBbox = originCoordinates[0] < medianX;
    const pointOfControl = {
      x: originLeftOfBbox ? minX - 10 : maxX + 10
    };

    const getCurveStyle = destination => {
      if (destination[0] < pointOfControl.x) {
        // left
        return 'forceDown';
      }
      // right
      return 'forceUp';
    };
github geosolutions-it / MapStore2 / web / client / epics / search.js View on Github external
}).concatMap((item) => {
                    // check if the service has been configured to start a GetFeatureInfo request based on the item selected
                    // if so, then do it with a point inside the geometry
                    let bbox = item.bbox || item.properties.bbox || toBbox(item);
                    let actions = [
                        zoomToExtent([bbox[0], bbox[1], bbox[2], bbox[3]], "EPSG:4326", 21),
                        addMarker(item)
                    ];
                    if (item.__SERVICE__ && !isNil(item.__SERVICE__.launchInfoPanel) && item.__SERVICE__.options && item.__SERVICE__.options.typeName) {
                        let coord = pointOnSurface(item).geometry.coordinates;
                        const latlng = { lng: coord[0], lat: coord[1] };
                        const typeName = item.__SERVICE__.options.typeName;
                        if (coord) {
                            let itemId = null;
                            let filterNameList = [];
                            let overrideParams = {};
                            if (item.__SERVICE__.launchInfoPanel === "single_layer") {
                                /* take info from the item selected and restrict feature info to this layer
                                 * and force info_format to application/json for allowing
                                 * filtering results later on (identify epic) */
github Vizzuality / gfw / app / javascript / components / map / components / popup / selectors.js View on Github external
(selected, map) => {
    if (!selected || !map) return null;
    if (map.getZoom() > 12) return false;

    const { data, layer, geometry } = selected;
    const { cartodb_id, wdpaid } = data || {};
    const { analysisEndpoint, tableName } = layer || {};

    const isAdmin = analysisEndpoint === 'admin';
    const isWdpa = analysisEndpoint === 'wdpa' && (cartodb_id || wdpaid);
    const isUse = cartodb_id && tableName;

    if (isAdmin || isWdpa || isUse) return false;

    // get bbox of geometry
    const shapeBbox = bbox(geometry);
    const shapePolygon = bboxPolygon(shapeBbox);
    // get bbox of map
    const mapBounds = map.getBounds();
    const mapPolygon = bboxPolygon([
      mapBounds._sw.lng,
      mapBounds._sw.lat,
      mapBounds._ne.lng,
      mapBounds._ne.lat
    ]);
    // compare size
    const shapeArea = area(shapePolygon);
    const mapArea = area(mapPolygon);
    const ratio = shapeArea / mapArea;

    return ratio < 0.25;
  }
github Vizzuality / gfw / app / javascript / components / map / components / popup / selectors.js View on Github external
theme: `theme-button-small ${data.bbox ? 'theme-button-light' : ''}`
    };

    const buttons = data.bbox
      ? [readMoreBtn].concat([
        {
          text: 'ZOOM',
          theme: 'theme-button-small'
        }
      ])
      : [readMoreBtn];

    let newBbox = data.bbox && JSON.parse(data.bbox).coordinates[0];
    if (newBbox) {
      const bboxCoords = newBbox.slice(0, 4);
      newBbox = bbox(lineString(bboxCoords));
    }

    return {
      ...articleData,
      ...(bbox && {
        bbox: newBbox
      }),
      buttons
    };
  }
);
github Vizzuality / gfw / app / javascript / components / maps / components / menu / components / sections / explore / explore-selectors.js View on Github external
data.map(d => {
      const bboxCoords = d.bbox.slice(0, 4);
      const bboxFromCoords = bbox(lineString(bboxCoords));
      const reverseBbox = [
        bboxFromCoords[1],
        bboxFromCoords[0],
        bboxFromCoords[3],
        bboxFromCoords[2]
      ];

      return {
        id: d.cartodb_id,
        image: d.image,
        imageCredit: d.image_source,
        title: d.name,
        summary: d.description,
        buttons: [
          {
            text: 'READ MORE',
github Vizzuality / gfw / app / javascript / components / map / components / popup / component.jsx View on Github external
handleClickZoom = selected => {
    const { setMapSettings } = this.props;
    const newBbox = bbox(selected.geometry);
    setMapSettings({ canBound: true, bbox: newBbox });
    this.setState({ open: false });
    this.handleClose();
  };

turf-bbox

turf bbox module

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular turf-bbox functions