Giter Site home page Giter Site logo

googlemaps-loader's Introduction

Google Maps API Loader

This little helpers provide a way to load Google Maps API dinamically with AMD, CommonJS and SystemJS.

npm

Please note that, starting from version 3.24, Google Maps API requires for you to get an API Key or a client ID (if you have the old Google Maps for Work Plan) and include said parameter on the URL.

This means that, eventhought client and key are optional fields for the next examples, you must declare one of them or you will get a NoApiKeys warning.

RequireJS installation and config

If you want to use these helpers with RequireJS, then install it with

npm install amd-googlemaps-loader

Then add to your config:

requirejs.config({
  "gmaps": {
    "parameters": {
      "v": "3.exp",
      "libraries": "visualization,places,drawing,geometry"
      //, "client": "optional, your client id for google maps for work"
      //, "key":"optional, API key"
    },
  },

  "map": {
    "*": {
      "gmaps": "path_to/amd-googlemaps-loader/requirejs-gmaps!https://maps.googleapis.com/maps/api/js"
      //, ...other mappings you have...
    }
  }
});

JSPM installation and SystemJS config

If you're using google maps with JSPM and or SystemJS, install it with:

jspm install gmap=npm:amd-googlemaps-loader

Then add to your config:

System.config({
  paths: {
      "github:*": "jspm_packages/github/*",
      "npm:*": "jspm_packages/npm/*",
      "gmaps": "https://maps.googleapis.com/maps/api/js"
      //,  ...other paths...
    },

  meta: {
    "https://maps.googleapis.com/maps/api/*": {
      "build": false,
      "parameters": {
        "v": "3.exp",
        "libraries": "visualization,places,drawing,geometry",
        //, "client": "optional, your client id for google maps for work"
        //, "key":"optional, API key"
      },
      "loader": "gmap"
    }
    //,  ...other meta if you have ...
  }
});

Note: If npm is unresponsive due to a strange anomaly, you can use the github registry:

jspm install gmap=github:huasofoundries/googlemaps-loader

Usage

After installing and adding proper configs to your loader, use it like so:

define([
  'gmaps',
  'jquery'
], function (gmaps, jQuery) {

  jQuery('body').append('<div id="map"/>');
  
  var mapOptions = {
      zoom: 8,
      center: {
        lat: -34.397,
        lng: 150.644
      }
    },
    myMap = new gmaps.Map(document.getElementById('map'), mapOptions);

});

The global google object will still be accesible in the global namespace since that's how google exports its library.

googlemaps-loader's People

Contributors

ffflabs avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

googlemaps-loader's Issues

jspm buildStatic not working

I'm having trouble bundling a static jspm bundle with this library. It errors with this:
TypeError: Global SFX bundle dependency "https://maps.googleapis.com/maps/api/js" must be configured to an environment global via the globalDeps option.

I could add it as a global dependency but I actually want it loaded by SystemJS.

It seems very similar to this issue in a related library HeinrichFilter/systemjs-plugin-googlemaps#5

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.