+41
-16
lines changedFilter options
+41
-16
lines changed Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
1
1
package example
2
2
3
+
import com.thoughtworks.binding.Binding.Var
3
4
import com.thoughtworks.binding.{Binding, dom}
4
-
import google.maps.LatLng
5
+
import google.maps._
5
6
import org.scalajs.dom.raw.HTMLElement
6
-
import org.scalajs.dom.{document, window}
7
+
import org.scalajs.dom.{Event, document, window}
7
8
8
9
import scala.language.implicitConversions
9
10
import scala.scalajs.js
@@ -16,27 +17,51 @@ object ScalaJSExample extends js.JSApp {
16
17
17
18
dom.render(document.getElementById("map-control"), render)
18
19
19
-
val initialize = js.Function {
20
-
val opts = google.maps.MapOptions(
21
-
center = new LatLng(51.201203, -1.724370),
22
-
zoom = 8,
23
-
panControl = false,
24
-
streetViewControl = false,
25
-
mapTypeControl = false)
26
-
new google.maps.Map(document.getElementById("map-canvas"), opts)
27
-
"" // this function needs a String as return type?!
28
-
}
29
-
30
20
google.maps.event.addDomListener(window, "load", initialize)
21
+
31
22
}
32
23
33
-
@dom lazy val render: Binding[HTMLElement] = {
24
+
@dom private lazy val render: Binding[HTMLElement] = {
25
+
val search: Var[String] = Var("")
26
+
34
27
<div>
35
-
<input class="prompt" type="text" placeholder="Address..." />
36
-
<button class="ui primary button">
28
+
<input id="searchInput" class="prompt" type="text" placeholder="Address..." oninput={event: Event => search.value = searchInput.value}/>
29
+
<button class="ui primary button" onclick={event: Event =>
30
+
geocodeAddress(search.value)}>
37
31
Search Address
38
32
</button>
33
+
<div>Your input is {search.bind}</div>
39
34
</div>
40
35
}
41
36
37
+
private lazy val opts = google.maps.MapOptions(
38
+
center = new LatLng(51.201203, -1.724370),
39
+
zoom = 8,
40
+
panControl = false,
41
+
streetViewControl = false,
42
+
mapTypeControl = false)
43
+
44
+
private lazy val gmap = new google.maps.Map(document.getElementById("map-canvas"), opts)
45
+
46
+
private lazy val initialize = js.Function {
47
+
gmap // the map must be initialized in this function
48
+
"" // this function needs a String as return type?!
49
+
}
50
+
51
+
private def geocodeAddress(address: String) {
52
+
val geocoder = new Geocoder()
53
+
val callback = (results: js.Array[GeocoderResult], status: GeocoderStatus) =>
54
+
if (status == GeocoderStatus.OK) {
55
+
gmap.setCenter(results(0).geometry.location)
56
+
val marker = new google.maps.Marker(
57
+
google.maps.MarkerOptions(map = gmap
58
+
, position = results(0).geometry.location))
59
+
} else {
60
+
window.alert("Geocode was not successful for the following reason: " + status)
61
+
}
62
+
63
+
geocoder.geocode(GeocoderRequest(address), callback)
64
+
}
65
+
66
+
42
67
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4