How to use the @turf/bbox-polygon function in @turf/bbox-polygon

To help you get started, we’ve selected a few @turf/bbox-polygon 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 osmlab / maproulette3 / src / components / ChallengeTaskMap / ChallengeTaskMap.js View on Github external
},
          })
        })
      }
    }

    // If we have a challenge object, try to get a challenge bounding so we
    // know which part of the map to display. Right now API double-nests
    // bounding, but that will likely change
    bounding = _get(this.props, 'challenge.bounding.bounding') ||
               _get(this.props, 'challenge.bounding')

    // If the challenge doesn't have a bounding polygon, build one from the
    // markers instead
    if (!bounding && markers.length > 0) {
      bounding = bboxPolygon(
        bbox(featureCollection(
          _map(markers, marker => point([marker.position[1], marker.position[0]]))
        ))
      )
    }

    const overlayLayers = _map(this.props.visibleOverlays, (layerId, index) =>
      
    )

    const renderedMarkers = _map(markers, markerData => {
      let icon = statusIcons[markerData.options.status]
      if (this.props.selectedTasks.has(markerData.options.taskId)) {
        icon = _cloneDeep(icon)
        icon.options.style.fill = colors.yellow
      }
github developmentseed / observe / app / selectors / index.js View on Github external
(_visibleBounds, fetchedTiles, zoom, serialNumber) => {
    if (_visibleBounds != null && zoom >= 16) {
      const visibleBounds = JSON.parse(_visibleBounds)
      // determine tile coverage
      const tileKeys = bboxToTiles(visibleBounds)

      // load tiled data (where available)
      const tiles = tileKeys.map(k => fetchedTiles[k]).filter(t => t != null)

      // convert bounds to a polygon for intersection purposes
      const bbox = bboxPolygon(_flatten(visibleBounds))

      // track ids of potentially duplicated features (across tile boundaries)
      const ids = new Set()

      // assemble a list of features intersecting the bounding box
      const visibleFeatures = tiles.reduce((features, { key }) => {
        // load data from an LRU cache to prevent needing to store *all* cached
        // data in memory (in addition to persisting it to disk)
        const data = cache.get(key) || {
          features: []
        }

        const newFeatures = data.features
          // ignore duplicates
          .filter(f => !ids.has(f.id))
          // intersect with the bbox
github uber / nebula.gl / modules / core / src / lib / editable-feature-collection.js View on Github external
_handlePointerMoveForDrawEllipseByBoundingBox(groundCoords: Position) {
    if (this._clickSequence.length === 0) {
      // nothing to do yet
      return;
    }

    const corner1 = this._clickSequence[0];
    const corner2 = groundCoords;

    const minX = Math.min(corner1[0], corner2[0]);
    const minY = Math.min(corner1[1], corner2[1]);
    const maxX = Math.max(corner1[0], corner2[0]);
    const maxY = Math.max(corner1[1], corner2[1]);

    const polygonPoints = bboxPolygon([minX, minY, maxX, maxY]).geometry.coordinates[0];
    const centerCoordinates = getIntermediatePosition(corner1, corner2);

    const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
    const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);

    this._setTentativeFeature(ellipse(centerCoordinates, xSemiAxis, ySemiAxis));
  }
github benjamintd / benmaps.fr / src / components / Map.js View on Github external
moveTo(location, zoom) {
    if (!location) return;
    if (location.bbox) {
      // We have a bbox to fit to
      const distance = turfDistance(
        [location.bbox[0], location.bbox[1]],
        [location.bbox[2], location.bbox[3]]
      );
      const buffered = turfBuffer(
        turfBboxPolygon(location.bbox),
        distance / 2,
        "kilometers"
      );
      const bbox = turfBbox(buffered);
      try {
        this.map.fitBounds(bbox, { linear: true });
      } catch (e) {
        this.map.fitBounds(location.bbox, { linear: true });
      }
    } else {
      // We just have a point
      this.map.easeTo({
        center: location.geometry.coordinates,
        zoom: zoom || 16
      });
    }
github sharedstreets / sharedstreets-js / src / commands / view.ts View on Github external
const bboxToPolygon = (bboxString) => {
        var bboxParts = bboxString.split(",").map((s) => {return Number.parseFloat(s)});
        if(bboxParts.length == 4) {
            var line = turfHelpers.lineString([[bboxParts[0],bboxParts[1]],[bboxParts[2],bboxParts[3]]]);
            var bbox = turfBbox(line);
            var bboxPolygon = turfBboxPolygon(bbox);
            return bboxPolygon;
        }
    };
github nzzdev / Q-editor / client / src / elements / schema-editor / schema-editor-bbox.js View on Github external
setBBox(bboxItem) {
    const bboxFeatureCollection = featureCollection([bboxPolygon(bboxItem)]);
    if (!(this.data === bboxItem)) {
      this.data = bbox(bboxFeatureCollection);
    }
    this.MapboxDraw.set(bboxFeatureCollection);
    this.map.fitBounds(
      [[this.data[0], this.data[1]], [this.data[2], this.data[3]]],
      { padding: 60, duration: 0 }
    );
  }
}
github osmlab / to-fix / src / components / task / index.js View on Github external
getBoundingBox(geojson) {
    const [ minX, minY, maxX, maxY ] = turfBbox(geojson);
    const padX = Math.max((maxX - minX) / 5, 0.0001);
    const padY = Math.max((maxY - minY) / 5, 0.0001);
    const bboxWithPadding = [
      minX - padX,
      minY - padY,
      maxX + padX,
      maxY + padY,
    ];
    const bboxPolygon = turfBboxPolygon(bboxWithPadding);
    return featureCollection([bboxPolygon]);
  }
github terascope / teraslice / packages / xlucene-evaluator / src / parser / functions / geo / helpers.ts View on Github external
export function makeBBox(point1: GeoPoint, point2: GeoPoint) {
    const line = lineString([
        makeCoordinatesFromGeoPoint(point1),
        makeCoordinatesFromGeoPoint(point2)
    ]);
    const box = bbox(line);

    return bboxPolygon(box);
}
github kepta / idly / packages / idly-gl / src / Map / UnloadedTiles.ts View on Github external
export function quadkeyToFeature(quadkey: string): any {
  const { x, y, z } = quadkeyToTile(quadkey);
  return bboxPolygon(mercator.bbox(x, y, z));
}

@turf/bbox-polygon

turf bbox-polygon module

MIT
Latest version published 3 months ago

Package Health Score

96 / 100
Full package analysis

Popular @turf/bbox-polygon functions