Git Product home page Git Product logo

google.maps's Introduction

Overview

Add interactive maps to your web applications! ...Without a single line of JavaScript.

The Google Map API, version 3.13, enables you to create rich, interactive maps, street views, route planning, and much more. Go and check out their homepage.

With this WebSharper Extension you can develop WebSharper applications that use the Google Maps API using nothing but F# code.

Installation

This extension is compatible with WebSharper 2.4. To obtain the latest extension binaries, install the WebSharper.Google.Maps NuGet package, and use as you would a regular .NET library.

The source code for the extension is available on both Bitbucket (Mercurial) or GitHub (Git):

Configuration

The Google maps API is a free service that is available to every page that is free for its users. You can check the specific terms of service here.

The version 3.0 of the Google Maps API does not require a key. The extension will generate code similar to the following for your pages:

<script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=true">

Overview

This extension provides a set of classes almost identical to the ones documented in the Google Maps API v3. When used in WebSharper projects, these stub classes delegate the work to the actual classes implemented in Google Maps API.

A Simple Map

Creating a map typically involves 3 steps:

  • Create a container, an Html element that will hold the map object.

  • Initialize the map and attaching it to the container.

  • Set properties, wire events, add overlays or controls to the attached map.

The first two steps are independent of the functionality. For this you can create a simple helper function that receives a function that takes as a parameter the initialized map:

open IntelliFactory.WebSharper.Google

[<JavaScript>]
let Sample buildMap =
    Div [Attr.Style "padding-bottom:20px; width:500px; height:300px;"]
    |>! OnAfterRender (fun mapElement ->
        let center = new Maps.LatLng(37.4419, -122.1419)
        let options = new Maps.MapOptions(center, MapTypeId.ROADMAP, 8)
        let map = new Maps.Map(mapElement.Dom, options)
        buildMap map)

A <div> element is created at line 3. The size of the <div> will determine the size of the map. You can set all the style properties you want in this step, including padding or margins.

It is necessary to initialize the map using the OnAfterRender method (line 4). The Maps API requires that the element is already attached to the DOM before initializing the map. Doing the Map initialization after the widget rendering makes sure that this condition holds.

google.maps's People

Contributors

granicz avatar jand42 avatar jobjo avatar jooseppi12 avatar qwe2 avatar t0yv0 avatar tarmil avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google.maps's Issues

MapTypes.fs Interface Generator Bug

Hi,

I've been trying to use google maps' style types, and I believe you have an unwanted line in MapTypes.fs at line 26:

  24: let MapTypeStyler =
  25: Config "MapTypeStyler"
  26: |+> Static [Constructor T]

If you comment out line 26 and rebuild, clients can use the MapTypeStyler type, otherwise there is a compiler error because of the extra constructor definition.

Here is some code that currently fails to compile (fixed above):

    [<JavaScript>]
    module GoogleMaps =
        open WebSharper.JavaScript
        open WebSharper.Google.Maps

        let mts = new MapTypeStyler()

Build fails with WebSharper 7.0.3 beta3

hi!

I'm trying to build WebSharper.Google.Maps targeting WebSharper 7.0.3 beta3 and after removing some stale references from paket.references files, I'm facing this error message:

WEBSHARPERTASK : WebSharper error WS9001: Error running WIG assembly: System.ArgumentException: An item with the same key has already been added. Key: { Assembly = "WebSharper.Google.Maps" FullName = "WebSharper.Google.Maps.Map" } at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at [email protected](Boolean intfAsClass, TypeDefinition typ) at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc2 action, IEnumerable1 source) in D:\a_work\1\s\src\FSharp.Core\seq.fs:line 603 at WebSharper.Compiler.Reflector.trAsm(IDictionary2 prototypes, AssemblyDefinition assembly, Boolean isTSasm) at WebSharper.Compiler.Reflector.TransformAssembly(IDictionary2 prototypes, AssemblyDefinition assembly) at WebSharper.InterfaceGenerator.Compiler.Compile(Resolver resolver, CompilerOptions options, Assembly assembly, String filePath, FSharpOption1 originalAssembly) at WebSharper.InterfaceGenerator.Compiler.Compile(CompilerOptions options, Assembly assembly, String filePath, FSharpOption1 original) at WebSharper.Compiler.CommandTools.RunInterfaceGenerator(AssemblyResolver aR, FSharpOption`1 snk, WsConfig config, LoggerBase logger) at [email protected](Unit unitVar0) [/home/vagrant/websharper/google.maps/WebSharper.Google.Maps/WebSharper.Google.Maps.fsproj::TargetFramework=netstandard2.0]

I've also removed the net461 reference, leaving only netstandard20.

The screenshot lists (grep command) where this namespace is located:
Screenshot_20240102_212230

My (wild) guess is the compiler is having problem resolving module aliases.

Attached, you find the complete log from the dotnet fake build output.
buid.log

My setup:

> uname -a
Linux vagrant 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

> dotnet --version
7.0.114

Is there any workaround for this issue?

Thanks,
Alex

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.