@@ -12,57 +12,111 @@ const drawSource = new VectorSource()
1212let drawLayer
1313
1414const actions : PolarActionTree < RoutingState , RoutingGetters > = {
15- setupModule ( { rootGetters : { configuration, map } , dispatch } ) {
15+ initializeTool ( {
16+ rootGetters : { configuration, map } ,
17+ dispatch,
18+ commit,
19+ state,
20+ } ) {
1621 console . error ( configuration )
1722 dispatch ( 'initializeConfigStyle' )
1823 drawLayer = createDrawLayer ( drawSource )
1924 map . addLayer ( drawLayer )
2025 console . error ( map . getLayers ( ) . getArray ( ) )
26+ map . on ( 'click' , function ( event ) {
27+ const formattedCoordinate = event . coordinate
28+ console . error ( 'formatierte Koordinate: ' + formattedCoordinate )
29+
30+ // prüfen, ob im state schon startAddress vorhanden ist - falls ja, die neue Koordinate als endAddress speichern
31+ if ( state . start . length === 0 ) {
32+ commit ( 'setStart' , formattedCoordinate )
33+ } else if ( state . end . length === 0 ) {
34+ commit ( 'setEnd' , formattedCoordinate )
35+ }
36+ console . error ( event )
37+ console . error ( 'Start:' + state . start + 'Ende: ' + state . end )
38+ } )
39+ } ,
40+ limitNumberWithinRange ( value ) {
41+ const MIN = 1
42+ const MAX = 20
43+ const parsed = parseInt ( value )
44+ return Math . min ( Math . max ( parsed , MIN ) , MAX )
45+ } ,
46+ translateCoordinateToWGS84 ( { rootGetters : { configuration } } , Coordinate ) {
47+ console . error ( 'Translate Methode' , configuration ?. epsg , Coordinate )
48+ const wgs84Coordinate = transform (
49+ Coordinate ,
50+ configuration ?. epsg ,
51+ 'EPSG:4326'
52+ )
53+ console . error ( 'Koordinate in WGS84: ' , wgs84Coordinate )
54+ return wgs84Coordinate
2155 } ,
2256 resetCoordinates ( { commit, state } ) {
2357 // TODO: Fehler beheben: "unknown local mutation type: resetCoordinates"
24- commit ( 'setStart' , [ 0.0 , '' ] )
25- commit ( 'setEnd' , [ 0.0 , '' ] )
58+ commit ( 'setStart' , [ ] )
59+ commit ( 'setEnd' , [ ] )
2660 console . error (
2761 'Start- und Endpunkt im Store nach reset:' ,
2862 state . start ,
2963 state . end
3064 )
3165 } ,
32- sendRequest ( { commit, dispatch } ) {
33- const searchCoordinates = [ [ 10.011687335562508 , 53.553460000125064 ] , [ 10.00032456432135 , 53.54922700402619 ] ]
66+ createUrl ( { rootGetters : { configuration } , state } ) {
67+ // TODO: Travel-Modes mit Switch Case (?) in finale Form bringen o. bessere Lösung finden
68+ const url =
69+ configuration ?. routing ?. serviceUrl +
70+ state . selectedTravelMode +
71+ '/' +
72+ configuration ?. routing ?. format
73+
74+ console . error ( url )
75+ return url
76+ } ,
77+ async sendRequest ( { commit, dispatch, state } ) {
78+ const searchCoordinates = [
79+ await dispatch ( 'translateCoordinateToWGS84' , state . start ) ,
80+ await dispatch ( 'translateCoordinateToWGS84' , state . end ) ,
81+ ]
82+ console . error ( searchCoordinates )
83+ const url = await dispatch ( 'createUrl' )
84+ console . error ( 'Die übergebene URL: ' , url )
3485 const fetchDirections = async ( ) => {
3586 try {
36- const response = await fetch (
37- 'https://geodienste.hamburg.de/web_ors/v2/directions/driving-car/geojson' ,
38- {
39- method : 'POST' ,
40- headers : {
41- 'Content-Type' : 'application/json' ,
42- } ,
43- body : JSON . stringify ( {
44- coordinates : searchCoordinates ,
45- geometry : true ,
46- instructions : true ,
47- language : 'en' ,
48- options : {
49- avoid_polygons : {
50- coordinates : [ ] ,
51- type : 'MultiPolygon' ,
52- } ,
87+ const response = await fetch ( url , {
88+ method : 'POST' ,
89+ headers : {
90+ 'Content-Type' : 'application/json' ,
91+ } ,
92+ body : JSON . stringify ( {
93+ coordinates : searchCoordinates ,
94+ geometry : true ,
95+ instructions : true ,
96+ language : 'en' ,
97+ options : {
98+ avoid_polygons : {
99+ coordinates : [ ] ,
100+ type : 'MultiPolygon' ,
53101 } ,
54- preference : 'recommended' ,
55- units : 'm ' ,
56- } ) ,
57- }
58- )
102+ } ,
103+ preference : 'recommended ' ,
104+ units : 'm' ,
105+ } ) ,
106+ } )
59107 if ( ! response . ok ) {
60108 throw new Error ( `HTTP error! Status: ${ response . status } ` )
61109 }
62110 const data = await response . json ( )
63111 console . error ( 'Response:' , data )
64112 commit ( 'setSearchResponseData' , data )
65113 dispatch ( 'drawRoute' )
114+ console . error (
115+ 'Zu vermeidende Routen aus dem Store:' ,
116+ state . selectedRouteTypesToAvoid
117+ )
118+ console . error ( 'Travel Mode aus dem Store:' , state . selectedTravelMode )
119+ console . error ( 'Preference aus dem Store:' , state . selectedPreference )
66120 } catch ( error ) {
67121 console . error ( 'Error:' , error )
68122 }
@@ -72,9 +126,9 @@ const actions: PolarActionTree<RoutingState, RoutingGetters> = {
72126 drawRoute ( { rootGetters : { configuration } , state } ) {
73127 console . error ( `stored response: ` , state . searchResponseData )
74128 const transformedCoordinates =
75- state . searchResponseData . features [ 0 ] . geometry . coordinates . map ( ( coordinate ) =>
76- transform ( coordinate , 'EPSG:4326' , 'EPSG:25832' )
77- )
129+ state . searchResponseData . features [ 0 ] . geometry . coordinates . map (
130+ ( coordinate ) => transform ( coordinate , 'EPSG:4326' , 'EPSG:25832' )
131+ )
78132 console . error (
79133 `coordinates transformed for drawing purpose: ` ,
80134 transformedCoordinates
0 commit comments