-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: use geolocation hook of react-util
- Loading branch information
1 parent
4ea49cf
commit f646ed5
Showing
5 changed files
with
87 additions
and
346 deletions.
There are no files selected for viewing
66 changes: 31 additions & 35 deletions
66
src/Button/GeoLocationButton/GeoLocationButton.example.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,61 @@ | ||
This demonstrates the use of the geolocation button. | ||
|
||
|
||
```jsx | ||
import GeoLocationButton from '@terrestris/react-geo/dist/Button/GeoLocationButton/GeoLocationButton'; | ||
import ToggleGroup from '@terrestris/react-geo/dist/Button/ToggleGroup/ToggleGroup'; | ||
import MapComponent from '@terrestris/react-util/dist/Components/MapComponent/MapComponent'; | ||
import MapContext from '@terrestris/react-util/dist/Context/MapContext/MapContext'; | ||
import OlLayerTile from 'ol/layer/Tile'; | ||
import OlMap from 'ol/Map'; | ||
import { fromLonLat } from 'ol/proj'; | ||
import OlSourceOSM from 'ol/source/OSM'; | ||
import OlView from 'ol/View'; | ||
import * as React from 'react'; | ||
|
||
class GeoLocationButtonExample extends React.Component { | ||
|
||
constructor(props) { | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
super(props); | ||
const GeoLocationButtonExample = () => { | ||
|
||
this.mapDivId = `map-${Math.random()}`; | ||
const [map, setMap] = useState(); | ||
|
||
this.map = new OlMap({ | ||
useEffect(() => { | ||
setMap(new OlMap({ | ||
layers: [ | ||
new OlLayerTile({ | ||
name: 'OSM', | ||
source: new OlSourceOSM() | ||
}) | ||
], | ||
view: new OlView({ | ||
center: fromLonLat([37.40570, 8.81566]), | ||
zoom: 4 | ||
center: fromLonLat([8, 50]), | ||
zoom: 9 | ||
}) | ||
}); | ||
} | ||
})); | ||
}, []); | ||
|
||
componentDidMount() { | ||
this.map.setTarget(this.mapDivId); | ||
if (!map) { | ||
return null; | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div | ||
id={this.mapDivId} | ||
return ( | ||
<MapContext.Provider | ||
value={map} | ||
> | ||
<> | ||
<MapComponent | ||
map={map} | ||
style={{ | ||
height: '400px' | ||
}} | ||
/> | ||
<ToggleGroup> | ||
<GeoLocationButton | ||
onGeolocationChange={() => undefined} | ||
map={this.map} | ||
showMarker={true} | ||
follow={true} | ||
> | ||
Track location | ||
</GeoLocationButton> | ||
</ToggleGroup> | ||
</div> | ||
); | ||
} | ||
} | ||
<GeoLocationButton | ||
showMarker={true} | ||
follow={true} | ||
> | ||
Enable GeoLocation | ||
</GeoLocationButton> | ||
</> | ||
</MapContext.Provider> | ||
); | ||
}; | ||
|
||
<GeoLocationButtonExample /> | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.