How to use the @turf/center function in @turf/center

To help you get started, we’ve selected a few @turf/center 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 / interactions / Task / AsMappableTask.js View on Github external
calculateCenterPoint() {
    let centerPoint = _get(this, 'location.coordinates')

    // Not all tasks have a center-point. In that case, we try to calculate
    // one ourselves based on the task features.
    if (!centerPoint && this.hasGeometries()) {
      try {
        centerPoint = _get(center(this.geometries), 'geometry.coordinates')
      }
      catch(e) {} // Bad geometry can cause turf to blow up
    }

    // If all our efforts failed, default to (0, 0).
    if (!centerPoint) {
      centerPoint = [0, 0]
    }

    // Our centerpoint is a standard GeoJSON Point, which is (Lng, Lat), but
    // Leaflet maps want (Lat, Lng).
    return latLng(centerPoint[1], centerPoint[0])
  }
github hotosm / imagery-coordination / app / assets / scripts / components / dashboard-map.js View on Github external
this.map.on('click', (e) => {
      var features = this.map.queryRenderedFeatures(e.point, { layers: this.getActiveLayers() });
      if (!features.length) {
        return;
      }

      var feature = features[0];

      // Populate the popup and set its coordinates
      // based on the feature found.
      let popoverContent = document.createElement('div');
      render(, popoverContent);

      new mapboxgl.Popup()
        .setLngLat(center(feature).geometry.coordinates)
        .setDOMContent(popoverContent)
        .addTo(this.map);
    });
github hotosm / imagery-coordination / app / assets / scripts / components / home-map.js View on Github external
if (!nextDue.length) {
          // There aren't any requests with next due information.
          return;
        }
        let nextSorted = _.sortBy(nextDue, o => o.properties.tasksInfo.nextDue.deliveryTime);
        feature = nextSorted[0];
        break;
      case 'full-extent':
        if (this.props.results) {
          this.map.fitBounds(extent(this.props.results));
        }
        return;
    }

    this.map.flyTo({
      center: center(feature).geometry.coordinates,
      zoom: 5
    });
    this.openPopup(feature.properties._id);
  },
github hotosm / imagery-coordination / app / assets / scripts / components / home-map.js View on Github external
openPopup: function (featId) {
    if (this.popup !== null) {
      this.popup.remove();
    }

    // Sub objects get stringified. Use the id to search in the actual data.
    var featureData = _.find(this.props.results.features, o => o.properties._id === featId);

    // Populate the popup and set its coordinates
    // based on the feature found.
    let popoverContent = document.createElement('div');
    render(, popoverContent);

    this.popup = new mapboxgl.Popup()
      .setLngLat(center(featureData).geometry.coordinates)
      .setDOMContent(popoverContent)
      .addTo(this.map);
  },
github hotosm / imagery-coordination / app / assets / scripts / components / dashboard-map.js View on Github external
pointFeats.features.forEach((feat) => {
      feat.geometry = center(feat).geometry;
      return feat;
    });
github Turfjs / turf / packages / turf-buffer / index.js View on Github external
function defineProjection(geojson) {
    var coords = center(geojson).geometry.coordinates.reverse();
    var rotate = coords.map(function (coord) { return -coord; });
    return geoTransverseMercator()
        .center(coords)
        .rotate(rotate)
        .scale(earthRadius);
}
github Turfjs / turf / packages / turf-transform-scale / index.js View on Github external
case 'southeast':
    case 'eastsouth':
    case 'bottomright':
        return point([east, south]);
    case 'nw':
    case 'northwest':
    case 'westnorth':
    case 'topleft':
        return point([west, north]);
    case 'ne':
    case 'northeast':
    case 'eastnorth':
    case 'topright':
        return point([east, north]);
    case 'center':
        return center(geojson);
    case undefined:
    case null:
    case 'centroid':
        return centroid(geojson);
    default:
        throw new Error('invalid origin');
    }
}

@turf/center

turf center module

MIT
Latest version published 3 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/center functions