Skip to content

Commit

Permalink
Merge pull request #48 from mike-north/fastboot
Browse files Browse the repository at this point in the history
Fastboot support
  • Loading branch information
asennikov committed May 7, 2016
2 parents 217db0a + c4af345 commit 2df999a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 33 deletions.
12 changes: 8 additions & 4 deletions addon/components/g-map-address-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const GMapAddressMarkerComponent = Ember.Component.extend({
map: computed.alias('mapContext.map'),

didInsertElement() {
this._super();
this._super(...arguments);
this.initPlacesService();
},

Expand All @@ -23,7 +23,9 @@ const GMapAddressMarkerComponent = Ember.Component.extend({
const map = this.get('map');
let service = this.get('placesService');

if (isPresent(map) && isEmpty(service)) {
if (isPresent(map) &&
isEmpty(service) &&
(typeof FastBoot === 'undefined')) {
service = new google.maps.places.PlacesService(map);
this.set('placesService', service);
this.searchLocation();
Expand All @@ -38,11 +40,13 @@ const GMapAddressMarkerComponent = Ember.Component.extend({
const service = this.get('placesService');
const address = this.get('address');

if (isPresent(service) && isPresent(address)) {
if (isPresent(service) &&
isPresent(address) &&
(typeof FastBoot === 'undefined')) {
const request = { query: address };

service.textSearch(request, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if (google && status === google.maps.places.PlacesServiceStatus.OK) {
this.updateLocation(results);
}
});
Expand Down
16 changes: 11 additions & 5 deletions addon/components/g-map-address-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const GMapAddressRouteComponent = Ember.Component.extend({
const map = this.get('map');
let service = this.get('placesService');

if (isPresent(map) && isEmpty(service)) {
if (isPresent(map) &&
isEmpty(service) &&
(typeof FastBoot === 'undefined')) {
service = new google.maps.places.PlacesService(map);
this.set('placesService', service);
this.searchLocations();
Expand All @@ -39,21 +41,25 @@ const GMapAddressRouteComponent = Ember.Component.extend({
const originAddress = this.get('originAddress');
const destinationAddress = this.get('destinationAddress');

if (isPresent(service) && isPresent(originAddress)) {
if (isPresent(service) &&
isPresent(originAddress) &&
(typeof FastBoot === 'undefined')) {
const originRequest = { query: originAddress };

service.textSearch(originRequest, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if (google && status === google.maps.places.PlacesServiceStatus.OK) {
this.updateOriginLocation(results);
}
});
}

if (isPresent(service) && isPresent(destinationAddress)) {
if (isPresent(service) &&
isPresent(destinationAddress) &&
(typeof FastBoot === 'undefined')) {
const destinationRequest = { query: destinationAddress };

service.textSearch(destinationRequest, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if (google && status === google.maps.places.PlacesServiceStatus.OK) {
this.updateDestinationLocation(results);
}
});
Expand Down
21 changes: 13 additions & 8 deletions addon/components/g-map-infowindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,16 @@ const GMapInfowindowComponent = Ember.Component.extend({
},

buildInfowindow() {
const infowindow = new google.maps.InfoWindow({
content: this.get('element')
});

if (isPresent(this.get('attrs.onClose'))) {
infowindow.addListener('closeclick', () => this.handleCloseClickEvent());
if (google) {
const infowindow = new google.maps.InfoWindow({
content: this.get('element')
});

if (isPresent(this.get('attrs.onClose'))) {
infowindow.addListener('closeclick', () => this.handleCloseClickEvent());
}
return infowindow;
}
return infowindow;
},

handleCloseClickEvent() {
Expand Down Expand Up @@ -141,7 +143,10 @@ const GMapInfowindowComponent = Ember.Component.extend({
const lat = this.get('lat');
const lng = this.get('lng');

if (isPresent(infowindow) && isPresent(lat) && isPresent(lng)) {
if (isPresent(infowindow) &&
isPresent(lat) &&
isPresent(lng) &&
(typeof FastBoot === 'undefined')) {
const position = new google.maps.LatLng(lat, lng);
infowindow.setPosition(position);
}
Expand Down
8 changes: 6 additions & 2 deletions addon/components/g-map-marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const GMapMarkerComponent = Ember.Component.extend({

didInsertElement() {
this._super();
if (isEmpty(this.get('marker'))) {
if (isEmpty(this.get('marker')) &&
(typeof FastBoot === 'undefined')) {
const marker = new google.maps.Marker();
this.set('marker', marker);
}
Expand Down Expand Up @@ -114,7 +115,10 @@ const GMapMarkerComponent = Ember.Component.extend({
const lat = this.get('lat');
const lng = this.get('lng');

if (isPresent(marker) && isPresent(lat) && isPresent(lng)) {
if (isPresent(marker) &&
isPresent(lat) &&
isPresent(lng) &&
(typeof FastBoot === 'undefined')) {
const position = new google.maps.LatLng(lat, lng);
marker.setPosition(position);
}
Expand Down
4 changes: 3 additions & 1 deletion addon/components/g-map-route-address-waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const GMapRouteAddressWaypointComponent = Ember.Component.extend({
const map = this.get('map');
let service = this.get('placesService');

if (isPresent(map) && isEmpty(service)) {
if (isPresent(map) &&
isEmpty(service) &&
(typeof FastBoot === 'undefined')) {
service = new google.maps.places.PlacesService(map);
this.set('placesService', service);

Expand Down
4 changes: 3 additions & 1 deletion addon/components/g-map-route-waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const GMapRouteWaypointComponent = Ember.Component.extend({
updateWaypoint() {
const { lat, lng } = this.getProperties(['lat', 'lng']);

if (isPresent(lat) && isPresent(lng)) {
if (isPresent(lat) &&
isPresent(lng) &&
(typeof FastBoot === 'undefined')) {
let location = new google.maps.LatLng(lat, lng);
this.set('waypoint', {
location: location,
Expand Down
16 changes: 10 additions & 6 deletions addon/components/g-map-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const { isEmpty, isPresent, observer, computed, run, assert } = Ember;
const allowedPolylineOptions = Ember.A(['strokeColor', 'strokeWeight', 'strokeOpacity', 'zIndex']);

const TRAVEL_MODES = {
walking: google.maps.TravelMode.WALKING,
bicycling: google.maps.TravelMode.BICYCLING,
transit: google.maps.TravelMode.TRANSIT,
driving: google.maps.TravelMode.DRIVING
walking: Ember.get(window, 'google.maps.TravelMode.WALKING'),
bicycling: Ember.get(window, 'google.maps.TravelMode.BICYCLING'),
transit: Ember.get(window, 'google.maps.TravelMode.TRANSIT'),
driving: Ember.get(window, 'google.maps.TravelMode.DRIVING')
};

const GMapRouteComponent = Ember.Component.extend({
Expand Down Expand Up @@ -49,7 +49,10 @@ const GMapRouteComponent = Ember.Component.extend({
let service = this.get('directionsService');
let renderer = this.get('directionsRenderer');

if (isPresent(map) && isEmpty(service) && isEmpty(renderer)) {
if (isPresent(map) &&
isEmpty(service) &&
isEmpty(renderer) &&
(typeof FastBoot === 'undefined')) {
const rendererOptions = {
map: map,
suppressMarkers: true,
Expand Down Expand Up @@ -81,7 +84,8 @@ const GMapRouteComponent = Ember.Component.extend({

if (isPresent(service) && isPresent(renderer) &&
isPresent(originLat) && isPresent(originLng) &&
isPresent(destinationLat) && isPresent(destinationLng)) {
isPresent(destinationLat) && isPresent(destinationLng) &&
(typeof FastBoot === 'undefined')) {
const origin = new google.maps.LatLng(this.get('originLat'), this.get('originLng'));
const destination = new google.maps.LatLng(this.get('destinationLat'), this.get('destinationLng'));
const travelMode = this.retrieveTravelMode(this.get('travelMode'));
Expand Down
11 changes: 8 additions & 3 deletions addon/components/g-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default Ember.Component.extend({

didInsertElement() {
this._super();
if (isEmpty(this.get('map'))) {
if (isEmpty(this.get('map')) &&
(typeof FastBoot === 'undefined')) {
const canvas = this.$().find('.g-map-canvas').get(0);
const options = this.get('permittedOptions');
this.set('map', new google.maps.Map(canvas, options));
Expand Down Expand Up @@ -74,7 +75,10 @@ export default Ember.Component.extend({
const lat = this.get('lat');
const lng = this.get('lng');

if (isPresent(map) && isPresent(lat) && isPresent(lng)) {
if (isPresent(map) &&
isPresent(lat) &&
isPresent(lng) &&
(typeof FastBoot === 'undefined')) {
const center = new google.maps.LatLng(lat, lng);
map.setCenter(center);
}
Expand Down Expand Up @@ -103,7 +107,8 @@ export default Ember.Component.extend({
return isPresent(marker.get('lat')) && isPresent(marker.get('lng'));
});

if (markers.length > 0) {
if (markers.length > 0 &&
(typeof FastBoot === 'undefined')) {
const map = this.get('map');
const bounds = new google.maps.LatLngBounds();
const points = markers.map((marker) => {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
var content = '';

if (type === 'head') {
var src = "//maps.googleapis.com/maps/api/js";
var src = '//maps.googleapis.com/maps/api/js';
var gMapConfig = config['g-map'] || {};
var params = [];

Expand All @@ -29,7 +29,7 @@ module.exports = {

var protocol = gMapConfig.protocol;
if (protocol) {
src = protocol + ":" + src;
src = protocol + ':' + src;
}

src += '?' + params.join('&');
Expand Down
4 changes: 3 additions & 1 deletion tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default Ember.Controller.extend({
routeColor: 'red',

customOptions: {
mapTypeId: google.maps.MapTypeId.TERRAIN
mapTypeId: computed(function() {
return google ? google.maps.MapTypeId.TERRAIN : null;
})
},

actions: {
Expand Down

0 comments on commit 2df999a

Please sign in to comment.