Code Monkey home page Code Monkey logo

ocaml-googlemaps's Introduction

#GoogleMaps binding for OCaml

Dependencies :

To be able to compile and run correctly this binding, you need to install the following packages in opam :

js_of_ocaml

gen_js_api

Installation :

To install it via opam use the folowing commands :

opam pin add ocaml-googlemaps https://github.com/besport/ocaml-googlemaps.git
opam install ocaml-googlemaps

Usage :

A minimal example can be found in the folder example. You only need to type make in the example folder to get example.js, open index.html to see the result

Compilation :

First, compile your source code into ocaml bytecode :

ocamlfind ocamlc -o example.byte -no-check-prims -package js_of_ocaml,gen_js_api,ocaml-googlemaps -linkpkg example.ml

Then you can get a js file from your bytecode thanks to js_of_ocaml :

js_of_ocaml -o example.js +gen_js_api/ojs_runtime.js example.byte

Documentation and conventions used :

You can find the official documentation: https://developers.google.com/maps/documentation/javascript/3.24/reference

The conventions used are gen_js_api 's :

  • An upper X letter becomes _x
  • Javascript new MyClass becomes MyClass.new_my_class
  • Javascript records ("Object" in Google Maps API documentation) become a module containing function :
    • create : which creates the object. Its parameters are all labelled by fields name
    • foofield : a getter for the field called foofield
    • set_foofield : a setter for the field called foofield

WARNING : Some objects in Google Map API contain a field called type. As type is a keyword in OCaml, you need to use type'

Example in Javascript :

var opts = 
  {
    center: {lat: -34.397, lng: 150.644},
    zoom: 10
  };
opts.zoom = 8;
var map = new google.maps.Map(document.getElementById('map'), opts);

Becomes in OCaml (supposing map is the Dom element where to place the map) :

open Googlemaps
let position = LatLng.new_lat_lng (-34.397) 150.644 in
let opts = MapOptions.create ~center:position ~zoom:10 () in
let () = MapOptions.set_zoom opts 8 in
let map = Map.new_map maps opts ()

Here, as the last arguments of create and new_map are optional, we also need to give ()

Version used :

This binding is using Google Map v3.24

Known bugs:

  • The namespace Dataisn't done yet

ocaml-googlemaps's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ocaml-googlemaps's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.