ember-google-map-fbs
v0.0.2
Published
An Ember addon to include a google-map Ember friendly component in your apps. See a bare simple demo [there](http://huafu.github.io/ember-google-map/).
Downloads
4
Maintainers
Readme
ember-google-map
An Ember addon to include a google-map Ember friendly component in your apps. See a bare simple demo there.
Be sure to read this and the last paragraph or this before reporting an issue
What is implemented for now:
Here is what is working for now:
{{google-map
lat=centerLat lng=centerLng
zoom=zoom
type=type
markers=markersArray
markerInfoWindowTemplateName='some/custom/template'
infoWindows=infoWindowsArray
infoWindowTemplateName='another/custom/template'
polylines=polylinesArray
circles=circlesArray
autoFitBounds='markers,circles'
fitBoundsArray=arrayOfLatLng
}}
lat
andlng
: bindings or static coordinates of the center (required)zoom
: binding to the current zoomtype
: binding to the type of map (can be found withimport {MAP_TYPES} from 'google-map/components/google-map';
)autoFitBounds
: defines here if you want the map to auto fit bounds on first render so that the map will automatically recenter and change zoom depending on what you set here (default:false
) - possible values are:- ``true`: fit so that anything on the map will be visible
false
: do not auto-fit boundsstring,string,...
(list of string separated by,
): will make the map fit everything you defined in corresponding arrays
fitBoundsArray
: an array of{lat: number, lng: number}
coordinates used so that the map will recenter on first render to fit them all in map (if set,autoFitBounds
will be ignored) (possible values aremarkers
,infoWindows
,polylines
,polygons
orcircles
) - example:markers,circles
markerController
: theObjectController
to use as a marker controller, must extend fromgoogle-map/controllers/marker
markerInfoWindowTemplateName
: default template for a marker info-windowmarkerHasInfoWindow
: whether to disable all markers info window or notmarkers
: binding to an array of markers (all properties are bound back an forth)lat
andlng
: coordinates of the marker position (required)isClickable
: if the marker is clickableisVisible
: marker visibilityisDraggable
: marker draggabilitytitle
: marker's titleopacity
: marker's opacityicon
: marker's iconzIndex
: marker's z-indexgoogleEvents
: an object with a mapping from google event to an Ember action name (string) or a function to be runhasInfoWindow
: whether it has an info window or notdescription
: What to how in the info window if no template specifiedisInfoWindowVisible
: whether the info window is visible initially or notinfoWindowTemplateName
: the template name for the info window
infoWindowTemplateName
: default template to use for all info-windowsinfoWindows
: bindings to an array of info-windows (not attached to any marker)isVisible
: whether the info-window is visible or not (default to true)lat
andlng
: coordinates of the info-window position (required)zIndex
: info-window's z-indextitle
: if using the default templatedescription
: if using the default templatetemplateName
: the name of the template to use with this info-window
polylines
: bindings to an array of polylinesisVisible
: whether the polyline is visibleisEditable
: whether the polyline is editableisDraggable
: whether the polyline is draggablestrokeColor
: the color of the linestrokeWeight
: the weight of the linestrokeOpacity
: the opacity of the linezIndex
: polyline's z-indexpath
: binding to an array of lat/lng array (required)
polygons
: bindings to an array of polygonsisVisible
: whether the polygon is visibleisEditable
: whether the polygon is editableisDraggable
: whether the polygon is draggablestrokeColor
: the color of the linestrokeWeight
: the weight of the linestrokeOpacity
: the opacity of the linefillColor
: the color of inside the polygonfillOpacity
: the opacity of inside the polygonzIndex
: polygon's z-indexpath
: binding to an array of lat/lng array (required)
circles
: bindings to an array of circleslat
andlng
: coordinates of the circle's center (required)radius
: radius of the circle (required)isVisible
: whether the circle is visibleisEditable
: whether the circle is editableisDraggable
: whether the circle is draggablestrokeColor
: the color of the circle borderstrokeOpacity
: the opacity of the circle borderstrokeWeight
: the weight of the circle borderfillColor
: the fill color of the circlefillOpacity
: the fill opacity of the circlezIndex
: circle's z-index
Any component or Ember object corresponding to a Google object can have additional Google options (the hash given to the Google object constructor) defined: they have to be properties on the Ember object, prefixed with
gopt_
. For example to disable the controls of the map (which isdisableDefaultUI
Google option):
{{google-map ... gopt_disableDefaultUI=true}}
TODO:
Implement an auto-complete input for an address:
{{google-address value=theText resolvedGoogleData=thePropertyToStoreGoogleData resolvedLat=thePropertyWhereToStoreAddressLatitude resolvedLng=thePropertyWhereToStoreAddressLongitude boundNorthWestLat=optionalBoundNorthWestLatitude boundNorthWestLng=optionalBoundNorthWestLongitude boundSouthEastLat=optionalBoundSouthEastLatitude boundSouthEastLng=optionalBoundSouthEastLongitude map=theOptionalMapToBeLinked }}
Write unit tests!!!
Installation
npm install --save-dev ember-google-map
Updating
- From
0.0.8
, the component has been renamed toember-google-map
and merged into your application, so when importing in your js files, changegoogle-map/...
to../...
. For example fromapp/controllers/application.js
:
import {MAP_TYPES} from '../components/google-map';
- Until version
0.0.13
it has been tested and working with Ember <1.9
. From version0.0.14
it has been updated to work with Ember1.9.1
and Handlebars2.0.0
, so be sure to upgrade your version of Ember to >=1.9
preior using this component..
Usage & configuration
Google Api key configuration
The google map script tag will be inserted in the head section of your index.html.
Also, if you define a ENV.googleMap.key
variable in your Ember CLI project's configuration file (config/environment.js
), it will be used as an API Key within this script tag.
Here is an example :
ENV.googleMap = {
key: 'AbCDeFgHiJkLmNoPqRsTuVwXyZ'
};
Lazy-loading of the SDK
If you want to have the SDK loaded only when the user would visit the route(s) where the google map component is used, you can set ENV.googleMap.lazyLoad
to true
. Then in each route where you use the component, add this in one of the beforeModel
, model
or afterModel
hooks:
export default Ember.Route.extend({
model: function (params) {
return this.loadGoogleMap();
}
});
It'll return a promise which will resolve to whatever you give as parameter, so if you need to still have your model loaded for example:
export default Ember.Route.extend({
model: function (params) {
return this._super.apply(this, arguments).then(this.loadGoogleMap);
// or without using the default ember-data but your own:
return this.loadGoogleMap(theModelToResolveTo);
}
});
Here is a very basic example:
// app/controllers/application.js
import Ember from 'ember';
import {MAP_TYPES} from '../components/google-map';
export default Ember.Controller.extend({
lat: 0,
lng: 0,
zoom: 5,
type: 'road',
mapTypes: MAP_TYPES,
});
{{! app/templates/application.hbs }}
{{!--
DON'T FORGET TO DEFINE `lat`, `lng` AND `zoom` in your controller or to remove them
from the given parameters here!
--}}
{{google-map lat=lat lng=lng type=type zoom=zoom}}
<h3>Map settings</h3>
<div>
<label>Lat: {{input value=lat}}</label>
<label>Lng: {{input value=lng}}</label>
<label>Zoom: {{input value=zoom}}</label>
<label>Type: {{view Ember.Select content=mapTypes
optionLabelPath='content.label' optionValuePath='content.id' value=type}}
</label>
</div>
DO NOT BIND lat
AND lng
OF THE MAP TO THE SAME OBJECT AS ANOTHER COMPONENT OF THE MAP
{{google-map lat=markersArray.firstObject.lat lng=markersArray.firstObject.lng markers=markersArray}}
THIS IS WRONG AND WILL NOT WORK
Remember that any property is bound, as it is for the map center, so moving the map will change the first marker's lat and lng, and do some infinite loop between observers and bound properties.
For a more complex example, visit the GitHub page of this repository.
Authors
Huafu Gandon - Follow me on twitter: huafu_g