Skip to content

Commit 79846a4

Browse files
committed
#14 - Added a callback to the map control
1 parent d007764 commit 79846a4

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

docs/documentation/docs/controls/Map.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The `Map` control can be configured with the following properties:
4040
| errorMessage | string | no | Custom error message. | |
4141
| mapsClassName | string | no | Custom CSS class name. | |
4242
| errorMessageClassName | string | no | Custom CSS error class name. | |
43+
| onUpdateCoordinates | (coordinates: ICoordinates) => void | no | Callback to let your solution knows the new coordinates when a search was performed. | |
4344

4445
`ICoordinates` interface:
4546

src/controls/map/IMapProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,8 @@ export interface IMapProps {
4646
* Class Name for the Error Section
4747
*/
4848
errorMessageClassName?: string;
49+
/**
50+
* Get an update when the coordinates are updated
51+
*/
52+
onUpdateCoordinates?: (coordinates: ICoordinates) => void;
4953
}

src/controls/map/Map.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,20 @@ export class Map extends React.Component<IMapProps, IMapState> {
126126
if (mapData && mapData.length > 0) {
127127
const location = mapData[0];
128128

129+
const coordinates = {
130+
latitude: parseFloat(location.lat),
131+
longitude: parseFloat(location.lon)
132+
};
133+
129134
this.setState({
130-
coordinates: {
131-
latitude: parseFloat(location.lat),
132-
longitude: parseFloat(location.lon)
133-
},
135+
coordinates,
134136
showmessageerror: false
135137
});
138+
139+
// Check if the control needs to send an update
140+
if (this.props.onUpdateCoordinates) {
141+
this.props.onUpdateCoordinates(coordinates);
142+
}
136143
}
137144
} catch (error) {
138145
console.error(error);

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
274274
coordinates={{ latitude: 51.507351, longitude: -0.127758 }}
275275
enableSearch={true}
276276
mapType={MapType.normal}
277+
onUpdateCoordinates={(coordinates) => console.log("Updated location:", coordinates)}
277278
// zoom={15}
278279
//mapType={MapType.cycle}
279280
//width="50"

0 commit comments

Comments
 (0)