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.
Full installation & configuration documentation.
Supports:
- Ember >=1.13
- Google Maps v3
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;
}
Install and Configuration
Component Properties and Events
Elements
- Marker Elements
- Circle Elements
- Polygon Elements
- Polyline Elements
- Rectangle Elements
- Overlay Elements
Services
Selections
- Setup
- Properties
- Events
- Marker Options
- Rectangle Options
- Circle Options
- Polygon Options
- Polyline Options
Heatmap
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:
Adding Markers
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
markers: Ember.A([
{
id: 'unique-marker-id', // Recommended
lat: 33.516674497188255, // Required
lng: -86.80091857910156, // Required
infoWindow: {
content: '<p>Birmingham</p>',
visible: true
},
click: function(event, marker) {},
rightclick: function(event, marker) {},
dblclick: function(event, marker) {},
mouseover: function(event, marker) {},
mouseout: function(event, marker) {},
mouseup: function(event, marker) {},
mousedown: function(event, marker) {},
drag: function(e, marker) {},
dragstart: function(e, marker) {},
dragend: function(e, marker) {}
}
]);
});
}
});
Adding Polygons
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
polygons: Ember.A([
{
id: 'unique-polygon-id', // 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(event, polygon) {},
rightclick: function(event, polygon) {},
dblclick: function(event, polygon) {},
mouseover: function(event, polygon) {},
mouseout: function(event, polygon) {},
mouseup: function(event, polygon) {},
mousedown: function(event, polygon) {},
mousemove: function(event, polygon) {},
drag: function(event, polygon) {},
dragstart: function(event, polygon) {},
dragend: function(event, polygon) {},
set_at: function(polygonPath) {},
insert_at: function(polygonPath) {},
remove_at: function(polygonPath) {}
}
])
});
}
});
Adding Polylines
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
polylines: Ember.A([
{
id: 'unique-polyline-id', // 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(event, polyline) {},
rightclick: function(event, polyline) {},
dblclick: function(event, polyline) {},
mouseover: function(event, polyline) {},
mouseout: function(event, polyline) {},
mouseup: function(event, polyline) {},
mousedown: function(event, polyline) {},
mousemove: function(event, polyline) {},
set_at: function(polylinePath) {},
insert_at: function(polylinePath) {},
remove_at: function(polylinePath) {}
}
])
});
}
});
Adding Circles
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
circles: Ember.A([
{
id: 'unique-circle-id', // Recommended
lat: 32.75494243654723, // Required
lng: -86.8359375, // Required
radius: 500000 // Not Required, but you'll probaby want to see it
click: function(event, circle) {},
rightclick: function(event, circle) {},
dblclick: function(event, circle) {},
mouseover: function(event, circle) {},
mouseout: function(event, circle) {},
mouseup: function(event, circle) {},
mousedown: function(event, circle) {},
mousemove: function(event, circle) {},
drag: function(e, circle) {},
dragstart: function(e, circle) {},
dragend: function(e, circle) {},
radius_changed: function(circle) {},
center_changed: function(circle) {}
}
])
});
}
});
Adding Rectangles
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
rectangles: Ember.A([
{
id: 'unique-rectangle-id', // Recommended
bounds: [
[40.300476079749465, -102.3046875], // NE lat, lng
[26.258936094468414, -73.828125] // SW lat, lng
],
strokeColor: 'green',
strokeOpacity: 1,
strokeWeight: 3,
fillColor: 'green',
fillOpacity: 0.2,
click: function(event, rectangle) {},
rightclick: function(event, rectangle) {},
dblclick: function(event, rectangle) {},
mouseover: function(event, rectangle) {},
mouseout: function(event, rectangle) {},
mouseup: function(event, rectangle) {},
mousedown: function(event, rectangle) {},
mousemove: function(event, rectangle) {},
drag: function(e, rectangle) {},
dragstart: function(e, rectangle) {},
dragend: function(e, rectangle) {},
bounds_changed: function(rectangle) {}
}
])
});
}
});
Adding Overlays
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
// Must be an Ember Array
overlays: Ember.A([
{
id: 'unique-overlay-id', // Recommended
lat: 32.75494243654723, // Required
lng: -86.8359375, // Required
content: '<strong class="my-class">Some HTML</strong>',
verticalAlign: 'top',
horizontalAlign: 'center',
click: function(event, overlay) {},
dblclick: function(event, overlay) {},
mouseup: function(event, overlay) {},
mousedown: function(event, overlay) {},
mouseover: function(event, overlay) {},
mousemove: function(event, overlay) {},
mouseout: function(event, overlay) {}
}
])
});
}
});
Basic G-Map Component Event
export default Ember.Route.extend({
actions: {
onMapEvent: function(event) {
console.info('Click coordinate',
event.latLng.lat(), // Latitude
event.latLng.lng() // Longitude
);
console.info('Map boundaries',
event.bounds[0], // Northeast map coordinate
event.bounds[1] // Southwest map coordinate
);
console.info('Map\'s center',
this.controller.lat,
this.controller.lng
);
event.mapIdle.then(function() { // Promise
console.log('maps done loading tiles and user is not interacting with map');
});
event.mapTilesLoaded.then(function() { // Promise
console.log('Map tiles have finished loading');
});
}
}
});
Setting Map Properties
Full component properties documentation
// Default settings
export default Ember.Route.extend({
setupController: function(controller) {
controller.setProperties({
lat: 33.5205556,
lng: -86.8025,
mapType: 'satellite', // Accepts 'roadmap', 'satellite', 'hybrid', or 'terrain'
showMapTypeControl: true,
draggable: true,
disableDefaultUI: false,
disableDoubleClickZoom: false,
scrollwheel: true,
showZoomControl: true,
showScaleControl: true
});
}
});
React to Map Loading Completion
export default Ember.Route.extend({
actions: {
onMapLoad: function(e) {
console.log(e.map +' has finished loading!');
// > "my-map has finished loading!"
}
}
});
Full component events documentation
- 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
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']
};
Actions
Actions are fired when a selections are completed. Available selections actions are:
- selectionsMarker
- selectionsCircle
- selectionsRectangle
- selectionsPolygon
- selectionsPolyline
Heatmap is an abstraction of the Google Maps Heatmap Layer.
Heatmap Requirements
Heatmap requires the Google Maps Visualization library. To add this library in:
config/environment.js
add:
ENV.googleMap = {
libraries: ['visualization']
};
- Routes
- Controls
- Layers & KML Layers
- Routes
- Info Windows
- Text labels
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',
lazyLoad: false, // default
language: 'ja', // optional
region: 'JA' // optional
}
- Fixes bug when Ember-Data not included
- Adds Map refresh service
- Adds Map theming
- Adds Lazy Load support
- Adds Geocoding
- Adds Google Places Autocomplete
- Wrap GMaps-for-apps geocoding service in Promise
- Adds scale control support
- Adds work client api-key support
- Unit test refactor
- Restructures g-maps core functionality
- Delegated gMap service onLoad to component loaded action
- Fixed some core mixin test race conditions
- Updated readme
- Upgrade to [email protected]
- Reverted to RSVP.Promise for tests
- Unit test for Overlay Mixin
- Travis-CI Badge
- Ember Observer Badge
- Passing Phantom Tests
- Google Maps Overlays child
- README Overlay examples
- Document supported child events
- Google Maps API updates
- Heatmap tests
- Heatmap Extension
- Full test coverage
- 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'
- Added Rectangle Maps Child
- Map selections
- fixed g-maps bindings on center_changed
- Fixed Bower dependency
- GMaps-For-Apps.js rendering layer
- Improved Map Child bindings
- No longer requires id property
- Polyline Map Child
- Performant Map destroy
- Basic Map Component
- Bound MapType
- Map service
- map idle promise
- map tilesLoaded promise
- Marker Map Child
- Circle Map Child
- Polygon Map Child
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.