-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoogle-map.js
79 lines (77 loc) · 2.31 KB
/
google-map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import Ember from 'ember';
import AbstractMapMixin from 'ember-cli-map/mixins/abstract-map';
var gmapView;
gmapView = Ember.Component.extend(AbstractMapMixin, {
mapType: 'asGoogleMap',
initialize: (function() {
var map, marker, options;
options = {
zoom: this.get('zoom'),
center: this.get('center'),
mapTypeId: this.get('mapTypeId')
};
map = new google.maps.Map(this.$().find(".map")[0], options);
marker = this.initMarker(map);
if (!this.get('disableAutocomplete')){
this.initAutocomplete(map, marker);
}
return google.maps.event.addListener(map, 'zoom_changed', (function(_this) {
return function() {
return _this.setZoom(map.getZoom());
};
})(this));
}).on('didInsertElement'),
center: (function() {
var coord;
coord = this.centerCoords();
return new google.maps.LatLng(coord[0], coord[1]);
}).property(),
mapTypeId: (function() {
return google.maps.MapTypeId.ROADMAP;
}).property(),
initMarker: function(map) {
var marker, options;
options = {
position: this.get('center'),
map: map,
draggable: true
};
marker = new google.maps.Marker(options);
google.maps.event.addListener(marker, 'dragend', (function(_this) {
return function(event) {
var pos;
map.setCenter(event.latLng);
pos = marker.getPosition();
return _this.setAttrs(pos.lat(), pos.lng());
};
})(this));
return marker;
},
initAutocomplete: function(map, marker) {
var autocomplete, autocompleteView, input;
autocompleteView = this.get('MapAutocomplete');
input = autocompleteView.$()[0];
autocomplete = new google.maps.places.Autocomplete(input, {
types: ['geocode']
});
return google.maps.event.addListener(autocomplete, 'place_changed', (function(_this) {
return function() {
var place, pos;
place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
pos = place.geometry.location;
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(pos);
map.setZoom(17);
}
marker.setPosition(pos);
return _this.setAttrs(pos.lat(), pos.lng());
};
})(this));
}
});
export default gmapView;