Skip to content

Instantly share code, notes, and snippets.

@aarontam
Created April 3, 2014 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarontam/9963268 to your computer and use it in GitHub Desktop.
Save aarontam/9963268 to your computer and use it in GitHub Desktop.
enyo.kind({
name: 'GoogleMap',
kind: 'Control',
published: {
zoom: 16,
center: null,
mapTypeId: 0,
useDefaultUI: true,
debugMode: false
},
events: {
onMapCreated: ''
},
components: [
{name: 'map', classes: 'enyo-google-map-map'}
],
//* @protected
create: function() {
this.inherited(arguments);
this.center = {
lat: 37.787186,
lng: -122.401037
};
},
rendered: function() {
this.inherited(arguments);
this.createMap();
},
createMap: function() {
this.mapTypeId = this.mapTypeId || google.maps.MapTypeId.ROADMAP;
if (this.map) {
this.destroyMap();
}
if (this.$.map.hasNode()) {
this.map = new google.maps.Map(this.$.map.hasNode(), {
center: new google.maps.LatLng(this.center.lat, this.center.lng),
zoom: this.zoom,
disableDefaultUI: !this.useDefaultUI,
mapTypeId: this.mapTypeId,
modeDiagnostics: this.debugMode
});
this.doMapCreated();
}
},
destroyMap: function() {
this.map = null;
},
updateCenter: function() {
var latlng = new google.maps.LatLng(this.center.lat, this.center.lng);
this.map.panTo(latlng);
},
setCenter: function(inLat, inLng) {
this.center.lat = inLat;
this.center.lng = inLng;
this.updateCenter();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment