-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created add center control, current location, location marker functio…
…ns, used in both map components Signed-off-by: Luke McFarlane <luke.mcfarlane@rocketlab.com.au>
- Loading branch information
1 parent
e54149d
commit 7ceece0
Showing
5 changed files
with
120 additions
and
105 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Control} from 'ol/control'; | ||
import {Coordinate} from 'ol/coordinate'; | ||
import Map from 'ol/Map'; | ||
import {CreateDomIcon} from '../../gui/components/map/dom-icon'; | ||
import src from '../../target.svg'; | ||
import {transform} from 'ol/proj'; | ||
|
||
export const addCenterControl = (map: Map, coords: Coordinate) => { | ||
const element = document.createElement('div'); | ||
element.className = 'ol-center-box'; | ||
|
||
const button = document.createElement('button'); | ||
button.className = 'ol-center-button'; | ||
|
||
button.appendChild( | ||
CreateDomIcon({ | ||
src, | ||
width: 24, | ||
height: 24, | ||
alt: 'Center map', | ||
}) | ||
); | ||
|
||
button.addEventListener('click', () => { | ||
map.getView().setCenter(transform(coords, 'EPSG:4326', 'EPSG:3857')); | ||
}); | ||
|
||
element.appendChild(button); | ||
|
||
map.addControl( | ||
new Control({ | ||
element: element, | ||
}) | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import GeoJSON from 'ol/format/GeoJSON'; | ||
import VectorSource from 'ol/source/Vector'; | ||
import Map from 'ol/Map'; | ||
import VectorLayer from 'ol/layer/Vector'; | ||
import {Fill, Style} from 'ol/style'; | ||
import CircleStyle from 'ol/style/Circle'; | ||
import {useQuery} from '@tanstack/react-query'; | ||
import {Geolocation} from '@capacitor/geolocation'; | ||
|
||
export const getCurrentLocation = () => | ||
useQuery({ | ||
queryKey: ['current_location'], | ||
queryFn: async (): Promise<[number, number]> => { | ||
const { | ||
coords: {longitude, latitude}, | ||
} = await Geolocation.getCurrentPosition(); | ||
return [longitude, latitude]; | ||
}, | ||
}); | ||
|
||
export const addCurrentLocationMarker = ( | ||
map: Map, | ||
coordinates: [number, number] | ||
) => { | ||
const source = new VectorSource(); | ||
|
||
source.addFeature( | ||
new GeoJSON().readFeature( | ||
{ | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates, | ||
}, | ||
}, | ||
{ | ||
dataProjection: 'EPSG:4326', | ||
featureProjection: map.getView().getProjection(), | ||
} | ||
) | ||
); | ||
|
||
for (const {radius, color} of [ | ||
{radius: 14, color: 'rgba(59, 130, 246, 0.1)'}, | ||
{radius: 8, color: 'rgb(255, 255, 255)'}, | ||
{radius: 6, color: 'rgb(59, 130, 246)'}, | ||
]) { | ||
map.addLayer( | ||
new VectorLayer({ | ||
source: source, | ||
style: new Style({ | ||
image: new CircleStyle({ | ||
radius, | ||
fill: new Fill({color}), | ||
}), | ||
}), | ||
}) | ||
); | ||
} | ||
}; |