Skip to content

Instantly share code, notes, and snippets.

@yelirekim
Created October 11, 2011 22:32
Show Gist options
  • Save yelirekim/1279667 to your computer and use it in GitHub Desktop.
Save yelirekim/1279667 to your computer and use it in GitHub Desktop.
game map settings object
define([
'/dev/js/main.js',
'/dev/js/types.js',
'async!http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places',
rmod('maps'),
rmod('common'),
rmod('dynamic')],function(main, types, google_maps, maps, common, dynamic){
return function(config, game_config, gmap_config) {
this.default_settings = {
element_id: null
}
var _settings = $.extend(this.settings, config);
this.default_game = {
center: {
latitude: game_default_center.latitude,
longitude: game_default_center.longitude
},
radius: game_default_radius
};
var _game = new game($.extend(true, this.default_game, game_config));
this.gmap_default_options = {
zoom: 11,
minZoom: 9,
maxZoom: 15,
streetViewControl: false,
backgroundColor: "#FFFFFF",
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var _gmap_options = $.extend(this.gmap_default_options, gmap_config);
_gmap_options.center = maps.position_to_LatLng(_game.center);
if(!common.is_empty(_settings.element_id)) {
_gmap = new google.maps.Map(document.getElementById(_settings.element_id), _gmap_options);
} else {
_gmap = null;
}
var _radius_options = {
strokeColor: '#112233',
strokeOpacity: 0.75,
strokeWeight: 1,
fillColor: '#AABBCC',
fillOpacity: 0.33,
map: _gmap,
center: _gmap.center,
radius: parseInt(_game.radius),
draggable:true
};
var _bounds_circle = new google.maps.Circle(_radius_options);
this.add_listener = function(evt, fn) {
google.maps.event.addListener(_gmap, evt, fn);
if(evt == 'click') {
google.maps.event.addListener(_bounds_circle, evt, fn);
}
}
this.get_radius = function() {
return _game.radius;
}
this.get_center = function() {
return maps.position_to_LatLng(_game.center);
}
this.get_latitude = function() {
return _game.center.latitude;
}
this.get_longitude = function() {
return _game.center.longitude;
}
this.get_zoom = function() {
return _gmap.getZoom();
}
function _set_radius(meters) {
_game.radius = meters;
return _bounds_circle.setRadius(meters);
}
function _set_center(latlng) {
_game.center = maps.LatLng_to_position(latlng);
return _bounds_circle.setCenter(latlng);
}
function _set_latitude(lat) {
return _set_center(new google.maps.LatLng(lat, _game.center.longitude));
}
function _set_longitude(lng) {
return _set_center(new google.maps.LatLng(_game.center.latitude, lng));
}
this.set_radius = dynamic.animated_setter(this, 'radius', this.get_radius, _set_radius);
this.set_longitude = dynamic.animated_setter(this, 'center', this.get_longitude, _set_longitude);
this.set_latitude = dynamic.animated_setter(this, 'center', this.get_latitude, _set_latitude);
this.set_center = function(latlng, animated, easing, callback) {
this.set_latitude(latlng.lat(), animated, easing, callback);
this.set_longitude(latlng.lng(), animated, easing, callback);
_gmap.panTo(latlng);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment