diff --git a/frontend/interchange.iml b/frontend/interchange.iml
index b9c9373..35b9537 100644
--- a/frontend/interchange.iml
+++ b/frontend/interchange.iml
@@ -12,6 +12,7 @@
+
diff --git a/frontend/package.json b/frontend/package.json
index 7a9f461..0362bf0 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
+ "kotlinx-coroutines-core": "^1.3.2",
"react": "^16.11.0",
"react-dom": "^16.11.0",
"react-map-gl": "^5.1.2"
diff --git a/frontend/src/app/App.css b/frontend/src/app/App.css
index e69de29..0fe7d63 100644
--- a/frontend/src/app/App.css
+++ b/frontend/src/app/App.css
@@ -0,0 +1,5 @@
+.Marker {
+ transform: translate(-50%, -50%);
+ font-size: 25px;
+ color: #f08300;
+}
\ No newline at end of file
diff --git a/frontend/src/app/App.kt b/frontend/src/app/App.kt
index 2bb2fc2..1c6bb99 100644
--- a/frontend/src/app/App.kt
+++ b/frontend/src/app/App.kt
@@ -1,10 +1,15 @@
package app
+import Marker
import logo.logo
import react.*
import react.dom.*
import search.search
import ReactMapGL
+import kotlinx.coroutines.MainScope
+import kotlinx.coroutines.await
+import kotlinx.coroutines.launch
+import kotlin.browser.window
interface ViewportState: RState {
var width: String
@@ -12,18 +17,56 @@ interface ViewportState: RState {
var latitude: Number
var longitude: Number
var zoom: Number
+ var waypointsResult: WaypointsResult
+}
+
+typealias Location = Array
+
+interface Waypoint {
+ val name: String
+ val location: Location
+}
+
+interface Intersection {
+ val name: String
+ val classifications: Array
+ val location: Location
+}
+
+interface Route {
+ val duration: Number
+ val distance: Number
+ val intersections: Array
+}
+
+interface WaypointsResult {
+ val waypoints: Array
+ val routes: Array
+}
+
+class EmptyWaypointsResult : WaypointsResult {
+ override val waypoints: Array = emptyArray()
+ override val routes: Array = emptyArray()
}
class App : RComponent() {
- init {
- state.width = "100vw"
- state.height = "100vh"
- state.latitude = 52.132633
- state.longitude = 5.291266
- state.zoom = 7
- }
+ override fun ViewportState.init() {
+ width = "100vw"
+ height = "100vh"
+ latitude = 52.132633
+ longitude = 5.291266
+ zoom = 11
+ waypointsResult = EmptyWaypointsResult()
+ val mainScope = MainScope()
+ mainScope.launch {
+ val result = fetchWaypointsResult()
+ setState {
+ waypointsResult = result
+ }
+ }
+ }
override fun RBuilder.render() {
div {
@@ -39,6 +82,7 @@ class App : RComponent() {
longitude = state.longitude
zoom = state.zoom
onViewportChange = { viewport ->
+ console.log(viewport)
setState {
width = viewport.width
height = viewport.height
@@ -48,9 +92,31 @@ class App : RComponent() {
}
}
}
+
+ for (route in state.waypointsResult.routes) {
+ for (intersection in route.intersections) {
+ Marker {
+ attrs {
+ longitude = intersection.location[0]
+ latitude = intersection.location[1]
+ }
+
+ div("Marker") {
+ +"🍿"
+ }
+ }
+ }
+ }
}
}
+ suspend fun fetchWaypointsResult(): WaypointsResult {
+ val responsePromise = window.fetch("https://api.myjson.com/bins/19rdz4")
+ val response = responsePromise.await()
+ val jsonPromise = response.json()
+ val json = jsonPromise.await()
+ return json.unsafeCast()
+ }
}
fun RBuilder.app() = child(App::class) {}
diff --git a/frontend/src/logo/Logo.css b/frontend/src/logo/Logo.css
index 6090fad..f307a49 100644
--- a/frontend/src/logo/Logo.css
+++ b/frontend/src/logo/Logo.css
@@ -8,6 +8,7 @@
font-size: 80px;
text-align: right;
line-height: 55px;
+ text-shadow: 0 0 10px rgba(0,0,0,.2);
}
.Small {
diff --git a/frontend/src/map/react-map-gl.kt b/frontend/src/map/react-map-gl.kt
index c7e347d..2eff1ba 100644
--- a/frontend/src/map/react-map-gl.kt
+++ b/frontend/src/map/react-map-gl.kt
@@ -21,3 +21,11 @@ external interface ReactMapGLProps : RProps {
var zoom: Number
var onViewportChange: (ReactMapGLViewport) -> Unit
}
+
+@JsName("Marker")
+external val Marker : RClass
+
+external interface MarkerProps : RProps {
+ var longitude: Number
+ var latitude: Number
+}
diff --git a/frontend/src/search/Search.kt b/frontend/src/search/Search.kt
index 8a69ce7..df4aa39 100644
--- a/frontend/src/search/Search.kt
+++ b/frontend/src/search/Search.kt
@@ -20,8 +20,8 @@ interface SearchState: RState {
class Search(props: SearchProps): RComponent(props) {
init {
- state.from = ""
- state.to = ""
+ state.from = "Codestar"
+ state.to = "Codestarwars"
}
override fun RBuilder.render() {