How to use @mapbox/geo-viewport - 10 common examples

To help you get started, we’ve selected a few @mapbox/geo-viewport 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 keplergl / kepler.gl / src / deckgl-layers / cluster-layer / cluster-layer.js View on Github external
getClusters() {
    const {geoJSON} = this.state;
    const {clusterRadius, mapState} = this.props;
    const {longitude, latitude, zoom, width, height} = mapState;
    // zoom needs to be an integer for the different map utils. Also helps with cache key.
    const zoomRound = Math.round(zoom);
    const bbox = geoViewport.bounds([longitude, latitude], zoomRound, [
      width,
      height
    ]);

    const clusters = clustersAtZoom({bbox, clusterRadius, geoJSON, zoom: zoomRound});

    this.setState({clusters});
  }
github DefinitelyTyped / DefinitelyTyped / types / mapbox__geo-viewport / mapbox__geo-viewport-tests.ts View on Github external
import { viewport, bounds } from '@mapbox/geo-viewport';

const geoViewport = viewport([
    5.668343999999995,
    45.111511000000014,
    5.852471999999996,
    45.26800200000002,
], [640, 480]);

const boundingBox = bounds({
    lon: 100,
    lat: 200,
}, 14, [640, 480]);

const boundingBox2 = bounds([100, 200], 14, [640, 480]);
github DefinitelyTyped / DefinitelyTyped / types / mapbox__geo-viewport / mapbox__geo-viewport-tests.ts View on Github external
import { viewport, bounds } from '@mapbox/geo-viewport';

const geoViewport = viewport([
    5.668343999999995,
    45.111511000000014,
    5.852471999999996,
    45.26800200000002,
], [640, 480]);

const boundingBox = bounds({
    lon: 100,
    lat: 200,
}, 14, [640, 480]);

const boundingBox2 = bounds([100, 200], 14, [640, 480]);
github forest-watcher / forest-watcher / app / helpers / map.js View on Github external
export function getMapZoom(region) {
  if (!region.longitude || !region.latitude) return 0;
  const bounds = [
    region.longitude - region.longitudeDelta / 2.5,
    region.latitude - region.latitudeDelta / 2.5,
    region.longitude + region.longitudeDelta / 2.5,
    region.latitude + region.latitudeDelta / 2.5
  ];

  return geoViewport.viewport(bounds, [width, height], 0, 18, 256).zoom || 0;
}
github EvictionLab / eviction-maps / src / app / map-tool / map-tool.service.ts View on Github external
setMapBounds(mapBounds: Array) {
    this.activeMapView = mapBounds.map(b => +b);
    this.mapConfig = {
      ...this.mapConfig,
      ...geoViewport.viewport(this.activeMapView,
        [this.platform.viewportWidth, this.platform.viewportHeight])
    };
  }
github novalabio / react-native-maps-super-cluster / ClusteredMapView.js View on Github external
getClusters(region) {
    const bbox = regionToBoundingBox(region),
          viewport = (region.longitudeDelta) >= 40 ? { zoom: this.props.minZoom } : GeoViewport.viewport(bbox, this.dimensions)

    return this.index.getClusters(bbox, viewport.zoom)
  }
github Vizzuality / trase / frontend / scripts / react-components / tool / map / map.hooks.js View on Github external
const fitToBounds = () => {
      const selectedGeoNodesIds = selectedGeoNodes.map(n => n.geoId);
      const selectedUnitLayer =
        unitLayers && unitLayers.find(u => u.id.startsWith(sourceLayer.toLowerCase()));
      if (!selectedUnitLayer) return;
      const features = map
        .querySourceFeatures(selectedUnitLayer.id, { sourceLayer })
        .filter(f => selectedGeoNodesIds.includes(f.id));
      if (features?.length) {
        const bounds = bbox({ type: 'FeatureCollection', features });
        const { width, height } = containerDimensions;
        const updatedViewport = geoViewport.viewport(bounds, [width, height]);

        const [longitude, latitude] = updatedViewport.center;
        setViewport({ ...viewport, latitude, longitude, zoom: updatedViewport.zoom - 1 });
      }
    };
    if (map && selectedGeoNodes) {
github EvictionLab / eviction-maps / src / app / map-tool / map-tool.service.ts View on Github external
setMapBounds(mapBounds: Array) {
    this.activeMapView = mapBounds.map(b => +b);
    this.mapConfig = {
      ...this.mapConfig,
      ...geoViewport.viewport(this.activeMapView,
        [this.platform.viewportWidth, this.platform.viewportHeight])
    };
  }
github keplergl / kepler.gl / src / reducers / map-state-updaters.js View on Github external
export const fitBoundsUpdater = (state, action) => {
  const bounds = action.payload;
  const {center, zoom} = geoViewport.viewport(bounds, [
    state.width,
    state.height
  ]);

  return {
    ...state,
    latitude: center[1],
    longitude: center[0],
    zoom
  };
};
github CatalystCode / project-fortis / project-fortis-interfaces / src / components / dialogs / MapViewPort.js View on Github external
render() {
    const geoJsonFeatures = this.props.coordinates.map(coordinatePair => Object.assign({}, {
        "type": "Feature",
        "properties": {},
        "geometry": {
          "type": "Point",
          "coordinates": coordinatePair
        }
      }
    ));

    const geoJson = Object.assign({}, {"type": "FeatureCollection", "features": geoJsonFeatures});
    const bounds = bbox(geoJson);
    const vp = geoViewport.viewport(bounds, this.props.mapSize);
    const pins = this.props.coordinates.map(coordinatePair => `pin-${PIN_SIZE}-cross+${PIN_COLOR}(${coordinatePair.join(",")})`);
    const mapImageSrc = `${reactAppMapboxTileServerUrl}/${pins.join(',')}/${vp.center.join(',')},${pins.length > 1 ? vp.zoom : DEFAULT_ZOOM}@2x/${this.props.mapSize.join('x')}.png?access_token=${this.props.accessToken}`;

    return (
      <img width="100%" alt="" src="{mapImageSrc}">
    );
  }
}

@mapbox/geo-viewport

convert between viewports and extents

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular @mapbox/geo-viewport functions