react-map-gl#ScaleControl JavaScript Examples

The following examples show how to use react-map-gl#ScaleControl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Map.js    From circles-website with GNU Affero General Public License v3.0 6 votes vote down vote up
render() {
    const { viewport } = this.state;

    return (
      <div style={{ height: 600 }}>
        <MapGL
          {...viewport}
          width="100%"
          height="100%"
          mapStyle="mapbox://styles/mapbox/dark-v9"
          onViewportChange={this._updateViewport}
          mapboxApiAccessToken={TOKEN}
        >
          <Pins data={CITIES} onClick={this._onClickMarker} />

          {this._renderPopup()}

          <div style={geolocateStyle}>
            <GeolocateControl />
          </div>
          <div style={fullscreenControlStyle}>
            <FullscreenControl />
          </div>
          <div style={navStyle}>
            <NavigationControl />
          </div>
          <div style={scaleControlStyle}>
            <ScaleControl />
          </div>

          {/* <ControlPanel containerComponent={this.props.containerComponent} /> */}
        </MapGL>
      </div>
    );
  }
Example #2
Source File: index.js    From covid-trials-dashboard with MIT License 4 votes vote down vote up
Map = ({ pins, handleSelectedId }) => {
  const {
    state: { prefersDarkMode },
  } = useContext(store) || { state: { prefersDarkMode: false } }
  const [popUp, setPopUp] = useState()
  const [viewport, setViewport] = useState({
    latitude: 40.67,
    longitude: -73.94,
    zoom: 0.8,
    bearing: 0,
    pitch: 0,
  })

  useEffect(() => {
    if (typeof navigator !== 'undefined' && 'geolocation' in navigator) {
      navigator.geolocation.getCurrentPosition(
        location => {
          setViewport({
            latitude: location.coords.latitude,
            longitude: location.coords.longitude,
            altitude: location.coords.altitude,
            zoom: 9,
          })
        },
        error => {
          console.log('User did not allow location', error)
        }
      )
    }
  }, [])

  const PinComponent = useMemo(() => {
    const onClick = popupInfo => {
      setPopUp(popupInfo)
      handleSelectedId(popupInfo.productId)
    }
    return (
      <Pins data={pins} onClick={onClick} handleSelectedId={handleSelectedId} />
    )
  }, [pins, handleSelectedId])

  const PopUpComponent = useMemo(() => {
    const onClose = () => {
      setPopUp(null)
      handleSelectedId('clear')
    }
    return (
      <>
        <PopUpDisplay popupInfo={popUp} onClose={onClose} />
      </>
    )
  }, [popUp, handleSelectedId])

  const Controls = useMemo(() => {
    return (
      <>
        <FullscreenControlDiv>
          <FullscreenControl />
        </FullscreenControlDiv>
        <NavDiv>
          <NavigationControl />
        </NavDiv>
        <ScaleControlDiv>
          <ScaleControl />
        </ScaleControlDiv>
      </>
    )
  }, [])

  return (
    <ReactMapGL
      {...viewport}
      onViewportChange={nextViewport => setViewport(nextViewport)}
      mapStyle={
        prefersDarkMode
          ? 'mapbox://styles/mapbox/dark-v10?optimize=true'
          : 'mapbox://styles/adibi2011/ckgtx36fp09lk19n2csgrxnu4'
      }
      mapboxApiAccessToken={mapboxApiKey}
      width='100%'
      height='100%'
    >
      {PinComponent}
      {PopUpComponent}
      {Controls}
    </ReactMapGL>
  )
}