@material-ui/icons#CenterFocusWeak TypeScript Examples

The following examples show how to use @material-ui/icons#CenterFocusWeak. 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: BoundaryDropdown.tsx    From prism-frontend with MIT License 5 votes vote down vote up
GotoBoundaryDropdown = () => {
  const map = useSelector(mapSelector);

  const [boundaries, setBoundaries] = useState<string[]>([]);

  const boundaryLayerData = useSelector(layerDataSelector(boundaryLayer.id)) as
    | LayerData<BoundaryLayerProps>
    | undefined;
  const { data } = boundaryLayerData || {};

  const {
    map: { latitude, longitude, zoom },
  } = appConfig;

  const { t } = useSafeTranslation();

  const styles = useStyles();

  if (!data || !map || !enableNavigationDropdown) {
    return null;
  }

  return (
    <div className={styles.dropdownMenu}>
      <CenterFocusWeak fontSize="small" className={styles.icon} />
      <ButtonStyleBoundaryDropdown
        selectedBoundaries={boundaries}
        selectAll={false}
        labelMessage={t('Go To')}
        className={styles.formControl}
        setSelectedBoundaries={(newSelectedBoundaries, appendMany) => {
          setBoundaries(() => {
            if (appendMany === true) {
              return newSelectedBoundaries;
            }

            return newSelectedBoundaries.slice(-1);
          });

          if (newSelectedBoundaries.length === 0) {
            map.flyTo({ center: { lng: longitude, lat: latitude }, zoom });

            return;
          }

          const geometries = data.features
            .filter(f =>
              newSelectedBoundaries.includes(
                f.properties && f.properties[boundaryLayer.adminCode],
              ),
            )
            .filter(f => f.geometry.type === 'MultiPolygon')
            .map(f => f.geometry as MultiPolygon);

          const bboxes = geometries.map(geom => {
            const turfObj = multiPolygon(geom.coordinates);
            const geomBbox = bbox(turfObj);

            return geomBbox;
          });

          const bboxPolygons = bboxes.map(box => bboxPolygon(box));
          const unionBbox = bboxPolygons.reduce((unionPolygon, polygon) => {
            const unionObj = union(unionPolygon, polygon);
            if (!unionObj) {
              return unionPolygon;
            }
            return unionObj as Feature<Polygon>;
          }, bboxPolygons[0]);

          map.fitBounds(bbox(unionBbox) as Extent, {
            padding: 30,
          });
        }}
      />
    </div>
  );
}