utils#handleLocationButton JavaScript Examples

The following examples show how to use utils#handleLocationButton. 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: ol-init.js    From raster-playground with GNU General Public License v3.0 4 votes vote down vote up
export default function OlInit() {
  const [shape] = useQueryParam(URL_SHAPE, StringParam);
  const [tiles] = useQueryParam(URL_TILES, StringParam);
  const [colors] = useQueryParam(URL_COLORS, StringParam);
  const [opacity] = useQueryParam(URL_OPACITY, StringParam);

  const prevTiles = usePrevious(tiles);
  const prevShape = usePrevious(shape);

  useEffect(() => {
    const olInstances = olMain({ shape, tiles, colors, opacity });
    setSource(olInstances.map.getLayers().getArray()[0].values_.source);

    if (olInstances.rasterSource && shape && prevTiles !== tiles) {
      olInstances.rasterSource.setUrl(tiles);
      olInstances.rasterSource.refresh();
    }

    if (olInstances.shapeSource && shape && prevShape !== shape) {
      olInstances.shapeSource.setUrl(shape);
      olInstances.shapeSource.refresh();

      olInstances.shapeSource.on('change', () => {
        let shapeExtentArray = olInstances.shapeSource.getExtent();
        if (
          shapeExtentArray &&
          !shapeExtentArray.includes(Infinity) &&
          !shapeExtentArray.includes(-Infinity)
        ) {
          olInstances.map.getView().fit(olInstances.shapeSource.getExtent(), {
            padding: [20, 20, 20, 420],
          });
        }
      });
    }

    if (olInstances.rasterLayer) {
      olInstances.rasterLayer.setOpacity(parseFloat(opacity));
    }

    if (olInstances.rasterSource) {
      olInstances.rasterSource.refresh();
    }
  }, [shape, tiles, colors, opacity, prevTiles, prevShape]);

  return (
    <>
      <div>
        <div id="map" className="main-map">
          <div className="ol-control location-btn">
            <button onClick={() => handleLocationButton()}>
              <FontAwesomeIcon icon={faCompass} />
            </button>
          </div>
        </div>
        <div id="popup" class="ol-popup">
          <div className="powered">
            Powered by{' '}
            <a href="http://blueskyhq.in/" target="_blank" rel="noreferrer">
              Blue Sky Analytics
            </a>{' '}
            | Made on{' '}
            <a href="https://openlayers.org/" target="_blank" rel="noreferrer">
              OpenLayers
            </a>{' '}
            | Basemap by{' '}
            <a href="mapbox.com" target="_blank" rel="noreferrer">
              Mapbox
            </a>
          </div>
          <div className="badges">
            {FOOTER_ICON.map(footer => (
              <a href={footer.url} target="_blank" rel="noreferrer">
                <img src={footer.img} alt={footer.label} />
              </a>
            ))}
          </div>
        </div>
      </div>
    </>
  );
}