Skip to content

coreyauger/scalajs-google-maps

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

scalajs-google-maps

Type-safe and Scala-friendly library over Google Maps.

Dependency Info

Scala.js.

Google Maps api v3

Get started

I assume that you have setup a ScalaJS project before. If this is not the case you can follow the instructions and some basic example on the Scala.js homepage.

To get started you will need a google maps api key. You can get an api key here.

Include google maps on your page

 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=API_KEY"></script>

Build.sbt

Add the following dependency to your porject.

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

"io.surfkit" %%% "scalajs-google-maps" % "0.0.3-SNAPSHOT",

Some Examples

Here are some of the google maps examples demonstrated in a type safe scalaJS way.

Simple Map

Initialize a map to a location and zoom level.

object ScalaJSGMapExample extends js.JSApp {
  def main(): Unit = {
    
    def initialize() = js.Function {
      val opts = google.maps.MapOptions(
        center = new LatLng(51.201203, -1.724370),
        zoom = 8,
        panControl = false,
        streetViewControl = false,
        mapTypeControl = false)
        val gmap = new google.maps.Map(document.getElementById("map-canvas"), opts)
    }
    google.maps.event.addDomListener(window, "load", initialize)
  }
}

Place a marker

Add a marker to the map.

object ScalaJSGMapExample extends js.JSApp {
  def main(): Unit = {
    
    def initialize() = js.Function {
      val opts = google.maps.MapOptions(
        center = new LatLng(51.201203, -1.724370),
        zoom = 8,
        panControl = false,
        streetViewControl = false,
        mapTypeControl = false)
        val gmap = new google.maps.Map(document.getElementById("map-canvas"), opts)
        
        val marker = new google.maps.Marker(google.maps.MarkerOptions(
          position = gmap.getCenter(),
          map = gmap,
          title = "Marker"
        ))
    }
    google.maps.event.addDomListener(window, "load", initialize)
  }
}

Respond to events + Info Window

object ScalaJSGMapExample extends js.JSApp {
  def main(): Unit = {
    
    def initialize() = js.Function {
      val opts = google.maps.MapOptions(
        center = new LatLng(51.201203, -1.724370),
        zoom = 8,
        panControl = false,
        streetViewControl = false,
        mapTypeControl = false)
        val gmap = new google.maps.Map(document.getElementById("map-canvas"), opts)
        
        val marker = new google.maps.Marker(google.maps.MarkerOptions(
          position = gmap.getCenter(),
          map = gmap,
          title = "Marker"
        ))
        
         val contentString = """
            <div id="content">
            <h1 id="firstHeading" class="firstHeading">Hello World !!</h1>
            </div>
            """

        val infowindow = new google.maps.InfoWindow(google.maps.InfoWindowOptions(
          content=contentString
        ))

        google.maps.event.addListener(marker, "click", () => {
          println("Marker click !")
          infowindow.open(gmap,marker)
        })
    }
    google.maps.event.addDomListener(window, "load", initialize)
  }
}

About

Type-safe and Scala-friendly library over Google Maps.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages