Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-g-maps

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-g-maps

An Ember CLI Addon for map driven applications. Built with GMaps, an open source Google Maps project. Currently in Beta.

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Ember CLI G-Maps

Ember CLI G-Maps is a Google Map component for map driven applications.

A map driven application responds to map interactions with fresh data. What this means for the developer is that you will need consistent access to the state of the map as well as intuitive ways to efficiently render large amounts of data.

Ember-cli-g-maps seeks to give you the information you need, when you need it, so that you can make the necessary requests and render the most relevant map data for your users.

Built with the GMaps-For-Apps.js library, a fork of GMaps.

Installation

Requires: Ember-CLI >= 1.13.7 & Ember > 1.13.6

In terminal:

ember install ember-cli-g-maps

This will install the ember-cli-g-maps node module and the gmaps bower component. The g-maps component will be available to your application, however you need to update your environment configuration to avoid violating the content security policy.

Update your config/environment.js Content Security Policy to contain:

ENV.contentSecurityPolicy = {
  'default-src': "'none'",
  'script-src': "'self' 'unsafe-eval' *.googleapis.com maps.gstatic.com",
  'font-src': "'self' fonts.gstatic.com",
  'connect-src': "'self' maps.gstatic.com",
  'img-src': "'self' *.googleapis.com maps.gstatic.com csi.gstatic.com",
  'style-src': "'self' 'unsafe-inline' fonts.googleapis.com maps.gstatic.com"
};

You wont see your map unless it has height. In app/styles/app.css:

.ember-cli-g-map {
    height: 300px;
}

Currently Supports

Usage

Simplest Possible G-Map

In your route:

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({ 
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4
    });
  }
});

In your template:

{{g-maps name="my-map" lat=lat lng=lng zoom=zoom}}

Add Markers

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4,
      // Must be an Ember Array
      markers: Ember.A([
        {
          id: 'jdlkfajs22', // Recommended
          lat: 33.516674497188255, // Required
          lng: -86.80091857910156, // Required
          infoWindow: { 
            content: '<p>Birmingham</p>',
            visible: true
          }, 
          click: function(e, marker) {}
        }
     ]);
    });
  }
});
{{g-maps ... markers=markers}}

Add Polygons

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4,
      // Must be an Ember Array
      polygons: Ember.A([
        {
          id: 'lka234klafj23', // Recommended
          paths: [ // Required
            [35.0041, -88.1955], // Lat, Lng
            [31.0023, -84.9944], // Lat, Lng
            [30.1546, -88.3864], // Lat, Lng
            [34.9107, -88.1461]  // Lat, Lng
          ],
          click: function(e, polygon) {}
        }
      ])
    });
  }
});
{{g-maps ... polygons=polygons}}

Add Polylines

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4,
      // Must be an Ember Array
      polylines: Ember.A([
        {
          id: 'lka234klafj23', // Recommended
          strokeColor: 'blue',
          strokeOpacity: 1,
          strokeWeight: 6,
          path: [ // Required
            [34.220, -100.7], // Lat, Lng
            [33.783, -92.81], // Lat, Lng
            [35.946, -94.83], // Lat, Lng
            [32.458, -95.71], // Lat, Lng
            [33.783, -92.85]  // Lat, Lng
          ],
          click: function(e, polyline) {}
        }
      ])
    });
  }
});
{{g-maps ... polylines=polylines}}

Add Circles

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4,
      // Must be an Ember Array
      circles: Ember.A([
        {
          id: 'lfkjasd23faj2f31', // Recommended
          lat: 32.75494243654723, // Required
          lng: -86.8359375,       // Required
          radius: 500000          // Not Required, but you'll probaby want to see it
          click: function(e, circle) {}
        }
      ])
    });
  }
});
{{g-maps ... circles=circles}}

Add Rectangles

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      zoom: 4,
      // Must be an Ember Array
      rectangles: Ember.A([
        {
          id: 'uaafkjkl2334lkadfj',             // Recommended
          bounds: [
            [40.300476079749465, -102.3046875], // lat, lng
            [26.258936094468414, -73.828125]    // lat, lng
          ],
          strokeColor: 'green',
          strokeOpacity: 1,
          strokeWeight: 3,
          fillColor: 'green',
          fillOpacity: 0.2,
          click: function(e, rectangle) {}
        }
      ])
    });
  }
});
{{g-maps ... rectangles=rectangles}}

Add G-Map Component Events

export default Ember.Route.extend({
  actions: {
    onMapEvent: function(e) {
      console.info('Click coordinate', 
        e.latLng.A, // Latitude
        e.latLng.F  // Longitude
      );
      console.info('Map boundaries',
        e.bounds[0], // Top left map coordinate
        e.bounds[1], // Top right map coordinate
        e.bounds[2], // Bottom left map coordinate
        e.bounds[3]  // Bottom right map coordinate
      );
      console.info('Map\'s center', 
        this.controller.lat, 
        this.controller.lng
      );
      e.mapIdle.then(function() { // Promise
        console.log('maps done loading tiles and user is not interacting with map'); 
      });
      e.mapTilesLoaded.then(function() { // Promise
        console.log('Map tiles have finished loading');
      });
    }
  }
});
{{g-maps ... click="onMapClick"}}

Set Map Type

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      mapType: 'satellite' // Accepts 'roadmap', 'satellite', 'hybrid', or 'terrain'
    });
  }
});
{{g-maps ... mapType=mapType}}

Set Draggable

export default Ember.Route.extend({
  setupController: function(controller) {
    controller.setProperties({
      lat: 32.75494243654723,
      lng: -86.8359375,
      draggable: false // default = true
    });
  }
});
{{g-maps ... draggable=draggable}}

Wait For Map To Load

export default Ember.Route.extend({
  // Inject the gMap service
  gMap: Ember.inject.service(),

  setupController: function(controller) {

    // Schedule after map rendering
    Ember.run.scheduleOnce('afterRender', this, function() {
      
      // Get the service and select desired G-Map
      const mapUtil = this.get('gMap').maps.select('my-map');
      
      // onLoad Promise resolved
      mapUtil.onLoad.then(function() {
        console.log('my-map has finished loading!');
      });
    });
  }
});
{{g-maps name="my-map" ...}}

Supported G-Maps Events

  • click
  • bounds_changed
  • center_changed
  • dblclick
  • drag
  • dragend
  • dragstart
  • heading_changed
  • idle
  • maptypeid_changed
  • mousemove
  • mouseout
  • mouseover
  • projection_changed
  • resize
  • rightclick
  • tilesloaded
  • tilt_changed
  • zoom_changed
{{g-maps
    click="myClickAction"
    bounds_changed="myBounds_changedAction"
    center_changed="myCenter_changedAction"
    dblclick="myDblclickAction"
    drag="myDragAction"
    dragend="myDragendAction"
    dragstart="myDragstartAction"
    heading_changed="myHeading_changedAction"
    idle="myIdleAction"
    maptypeid_changed="myMaptypeid_changedAction"
    mousemove="myMousemoveAction"
    mouseout="myMouseoutAction"
    mouseover="myMouseoverAction"
    projection_changed="myProjection_changedAction"
    resize="myResizeAction"
    rightclick="myRightclickAction"
    tilesloaded="myTilesloadedAction"
    tilt_changed="myTilt_changedAction"
    zoom_changed="myZoom_changedAction"}}

Selections

Repurposed from the Google Maps Drawing Manager, Selections allow you to draw shapes on your map instance. This allows users to select areas on the map to interact with. Supported selection types include:

  • Markers
  • Rectangles
  • Circles
  • Polygons
  • Polylines

Selections Requirements

Selections requires the Google Maps Drawing library. To add this library in: config/environment.js add:

ENV.googleMap = {
  libraries: ['drawing']
};

Main Configuration Property Your g-maps component requires a truthy selections property to be set in order to instantiate. The selections object may contain the following:

Additional Configuration Properties

  • selectionsDelay // [number] Time until selection is removed. {default} 400.
  • selectionsMode // [string] Current selection tool. Accepts value 'marker', 'circle', 'rectangle', 'polygon', and 'polyline'. {default} ''.
  • selectionsModes // [array] Supported selection modes. Accpets string values: 'marker', 'circle', 'rectangle', 'polygon', and 'polyline'. {default} ['marker', 'circle', 'rectangle', 'polygon', 'polyline']
  • selectionsPosition // [string] Location of selection controls. Accepts values: 'top', 'top-left', 'top-right', 'left-top', 'right-top', 'left', 'left-center', 'right', 'right-center', 'left-bottom', 'right-bottom', 'bottom', 'bottom-center', 'bottom-left', 'bottom-right'. {default} 'top'.

Actions Actions are fired when a selections are completed. Available selections actions are:

  • selectionsMarker
  • selectionsCircle
  • selectionsRectangle
  • selectionsPolygon
  • selectionsPolyline

Selections Example

{{g-maps
  ...
  selections=selections
  selectionsDelay=delay
  selectionsMode=activeMode
  selectionsModes=supportedModes
  selectionsPosition=position
  selectionsMarker="onMarkerSelect"
  selectionsCircle="onCircleSelect"
  selectionsRectangle="onRectangleSelect"
  selectionsPolygon="onPolygonSelect"
  selectionsPolyline="onPolylineSelect"}}

Heatmap

Heatmap is an abstraction of the Google Maps Heatmap Layer.

Heatmap Requirements

Selections requires the Google Maps Visualization library. To add this library in: config/environment.js add:

ENV.googleMap = {
  libraries: ['visualization']
};

Main Configuration Property

  • heatmapMarkers // [Array] Required property to enable Heatmap. May contain array of [lat, lng], or heatmap-marker config object. -- [1, 1] // lat, lng -- { location: [1, 1], weight: 3 } // location: lat,lng array, optional weight parameter --- WeightedLocation
  • heatmapRadius [Number] Size of all heatmap markers {default} 0.
  • heatmapDissipating [Boolean] Specifies whether heatmaps dissipate on zoom. When dissipating is false the radius of influence increases with zoom level to ensure that the color intensity is preserved at any given geographic location. {default} false.
  • heatmapOpacity [Number] The opacity of the heatmap, expressed as a number between 0 and 1. {default} 1.
  • heatmapGradient [Array] The color gradient of the heatmap, specified as an array of CSS color strings. -- Supports all CSS3 colors — including RGBA (except: extended named colors and HSL(A)).
  • heatmapVisible // [boolean] Show or hide the Heatmap Layer. {default} true.

Planned Features

Customization

In config/environment.js

ENV.googleMap = {
  // your configuration goes in here
  libraries: ['places', 'geometry'], // milage varies based on g-maps supported features
  version: '3', // not recommended
  apiKey: 'your-unique-google-map-api-key'
}

Changelog

0.2.0

  • Heatmap Extension

0.1.2

  • Full test coverage

0.1.1-beta

  • Fixed GMap zooming lat lng hijacking
  • Added warnings for invalid selections' props
  • Added syncing of DrawingManager controls to selectionsMode
  • Fix auto setting of map type to 'undefined'

0.1.0-beta

  • Added Rectangle Maps Child
  • Map selections
  • fixed g-maps bindings on center_changed

0.0.14-beta

  • Fixed Bower dependency

0.0.13-beta

  • GMaps-For-Apps.js rendering layer
  • Improved Map Child bindings
    • No longer requires id property
  • Polyline Map Child
  • Performant Map destroy

0.0.12-beta

  • Basic Map Component
    • Bound MapType
  • Map service
    • map idle promise
    • map tilesLoaded promise
  • Marker Map Child
  • Circle Map Child
  • Polygon Map Child

License

The MIT License (MIT)

Copyright (c) 2015 Matt Jensen. github.com/Matt-Jensen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 31 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc