Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Custom location sharing. #7185

Merged
merged 39 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c66d54b
first ugly cut at a location picker via maplibre
ara4n Nov 14, 2021
7970b90
fix css
ara4n Nov 14, 2021
12bb69b
fix dropdown height
ara4n Nov 14, 2021
1b75489
fix form
ara4n Nov 14, 2021
cd9ea95
use right icon
ara4n Nov 14, 2021
3a779b7
hook up locationpicker
ara4n Nov 15, 2021
3b0a3a2
actually send m.location events
ara4n Nov 15, 2021
6ce1e86
view m.location
ara4n Nov 15, 2021
e7cd207
border radius on picker
ara4n Nov 15, 2021
fc41580
fix lint
ara4n Nov 21, 2021
bec7af4
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
d6b5153
Merge branch 'develop' into matthew/location-share
ara4n Nov 21, 2021
ccd416d
fix css var
ara4n Nov 21, 2021
eebf29d
fix types
ara4n Nov 21, 2021
426f7b3
only send loc if you have one
ara4n Nov 21, 2021
94f1ff9
disable the streaming options until they're hooked up
ara4n Nov 21, 2021
6488168
lint
ara4n Nov 21, 2021
644fe03
more lint
ara4n Nov 21, 2021
f774e71
fix i18n
ara4n Nov 21, 2021
80a15a1
show descriptions
ara4n Nov 21, 2021
92ba926
incorporate review
ara4n Nov 22, 2021
5531d09
use fancy optional chaining
ara4n Nov 22, 2021
8fd4310
add createObjectURL mock
ara4n Nov 22, 2021
097c8f7
fix i18n
ara4n Nov 22, 2021
aef8599
add custom location sharing
ara4n Nov 23, 2021
46cd0af
Merge branch 'develop' into matthew/custom-location
ara4n Nov 28, 2021
3dc7b21
Merge branch 'develop' into matthew/location-share
ara4n Nov 28, 2021
982d5b7
warn if API key not set when showing maps
ara4n Nov 28, 2021
6ea351e
Merge branch 'develop' into matthew/location-share
ara4n Dec 4, 2021
49c590c
export LocationShareType enum correctly
ara4n Dec 5, 2021
f088094
hook up map failure error correctly
ara4n Dec 5, 2021
58ebf2a
fix lint
ara4n Dec 5, 2021
e6842ba
fix type
ara4n Dec 5, 2021
d6b805a
fix types
ara4n Dec 5, 2021
21fb29d
Merge branch 'matthew/location-share' into matthew/custom-location
ara4n Dec 5, 2021
07cb647
types & cleanup
ara4n Dec 5, 2021
c4a564d
fix types and arrow fns
ara4n Dec 5, 2021
856b870
Merge branch 'develop' into matthew/custom-location
ara4n Dec 6, 2021
1209d94
remove dup feature_location_share...
ara4n Dec 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 70 additions & 10 deletions src/components/views/location/LocationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const LocationShareTypeDropdown = ({
onChange,
}: IDropdownProps) => {
const options = [
// <div key={LocationShareType.Custom}>{ _t("Share custom location") }</div>,
<div key={LocationShareType.Custom}>{ _t("Share custom location") }</div>,
<div key={LocationShareType.OnceOff}>{ _t("Share my current location as a once off") }</div>,
// <div key={LocationShareType.OneMin}>{ _t("Share my current location for one minute") }</div>,
// <div key={LocationShareType.FiveMins}>{ _t("Share my current location for five minutes") }</div>,
Expand All @@ -56,7 +56,9 @@ const LocationShareTypeDropdown = ({
return <Dropdown
id="mx_LocationShareTypeDropdown"
className="mx_LocationShareTypeDropdown"
onOptionChange={(key: string)=>{ onChange(LocationShareType[LocationShareType[parseInt(key)]]); }}
onOptionChange={(key: string) => {
onChange(LocationShareType[LocationShareType[parseInt(key)]]);
}}
menuWidth={width}
label={label}
value={value.toString()}
Expand All @@ -74,13 +76,14 @@ interface IState {
description: string;
type: LocationShareType;
position?: GeolocationPosition;
manual: boolean;
manualPosition?: GeolocationPosition;
error: Error;
}

@replaceableComponent("views.location.LocationPicker")
class LocationPicker extends React.Component<IProps, IState> {
private map: maplibregl.Map;
private marker: maplibregl.Marker;
private geolocate: maplibregl.GeolocateControl;

constructor(props) {
Expand All @@ -90,7 +93,7 @@ class LocationPicker extends React.Component<IProps, IState> {
description: _t("My location"),
type: LocationShareType.OnceOff,
position: undefined,
manual: false,
manualPosition: undefined,
error: undefined,
};
}
Expand All @@ -113,23 +116,63 @@ class LocationPicker extends React.Component<IProps, IState> {
});
this.map.addControl(this.geolocate);

this.map.on('error', (e)=>{
this.map.on('error', (e) => {
logger.error("Failed to load map: check map_style_url in config.json has a valid URL and API key", e.error);
this.setState({ error: e.error });
});

this.map.on('load', ()=>{
this.map.on('load', () => {
this.geolocate.trigger();
});

this.map.on('click', (e) => {
this.addMarker(e.lngLat);
this.storeManualPosition(e.lngLat);
this.setState({ type: LocationShareType.Custom });
});

this.geolocate.on('geolocate', this.onGeolocate);
}

private addMarker(lngLat: maplibregl.LngLat): void {
if (this.marker) return;
this.marker = new maplibregl.Marker({
draggable: true,
})
.setLngLat(lngLat)
.addTo(this.map)
.on('dragend', () => {
this.storeManualPosition(this.marker.getLngLat());
});
}

private removeMarker(): void {
if (!this.marker) return;
this.marker.remove();
this.marker = undefined;
}

private storeManualPosition(lngLat: maplibregl.LngLat): void {
const manualPosition: GeolocationPosition = {
coords: {
longitude: lngLat.lng,
latitude: lngLat.lat,
altitude: undefined,
accuracy: undefined,
altitudeAccuracy: undefined,
heading: undefined,
speed: undefined,
},
timestamp: Date.now(),
};
this.setState({ manualPosition });
}

componentWillUnmount() {
this.geolocate.off('geolocate', this.onGeolocate);
}

private onGeolocate = (position) => {
private onGeolocate = (position: GeolocationPosition) => {
this.setState({ position });
};

Expand All @@ -146,16 +189,33 @@ class LocationPicker extends React.Component<IProps, IState> {
};

private onOk = () => {
const position = (this.state.type == LocationShareType.Custom) ?
this.state.manualPosition : this.state.position;

this.props.onChoose(
this.state.position ? this.getGeoUri(this.state.position) : undefined,
this.state.position ? this.state.position.timestamp : undefined,
position ? this.getGeoUri(position) : undefined,
position ? position.timestamp : undefined,
this.state.type,
this.state.description,
);
this.props.onFinished();
};

private onTypeChange= (type: LocationShareType) => {
if (type == LocationShareType.Custom) {
if (!this.state.manualPosition) {
this.setState({ manualPosition: this.state.position });
}
if (this.state.manualPosition) {
this.addMarker(new maplibregl.LngLat(
this.state.manualPosition?.coords.longitude,
this.state.manualPosition?.coords.latitude,
));
}
} else {
this.removeMarker();
}

this.setState({ type });
};

Expand Down Expand Up @@ -189,7 +249,7 @@ class LocationPicker extends React.Component<IProps, IState> {
<DialogButtons primaryButton={_t('Share')}
onPrimaryButtonClick={this.onOk}
onCancel={this.props.onFinished}
disabled={!this.state.position} />
primaryDisabled={!this.state.position} />
</form>
</div>
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/components/views/messages/MLocationBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,22 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {

componentDidMount() {
const config = SdkConfig.get();
const coordinates = new maplibregl.LngLat(this.coords.longitude, this.coords.latitude);

this.map = new maplibregl.Map({
container: this.getBodyId(),
style: config.map_style_url,
center: [this.coords.longitude, this.coords.latitude],
center: coordinates,
zoom: 13,
});

new maplibregl.Marker()
.setLngLat([this.coords.longitude, this.coords.latitude])
new maplibregl.Popup({
closeButton: false,
closeOnClick: false,
closeOnMove: false,
})
.setLngLat(coordinates)
.setHTML(this.description)
.addTo(this.map);

this.map.on('error', (e)=>{
Expand All @@ -106,7 +113,6 @@ export default class MLocationBody extends React.Component<IBodyProps, IState> {
return <div className="mx_MLocationBody">
<div id={this.getBodyId()} className="mx_MLocationBody_map" />
{ error }
<span className="mx_EventTile_body">{ this.description }</span>
</div>;
}
}
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,7 @@
"edited": "edited",
"Submit logs": "Submit logs",
"Can't load this message": "Can't load this message",
"Share custom location": "Share custom location",
"Share my current location as a once off": "Share my current location as a once off",
"My location": "My location",
"Type of location share": "Type of location share",
Expand Down