Browse files

minor bug/code style fixes

  • Loading branch information...
1 parent b4e0442 commit c0e0aee5e093690f98ab284301c4ae6ee2509d13 @mlouro mlouro committed Jan 13, 2012
Showing with 38 additions and 26 deletions.
  1. +12 −11 geotagging/static/js/app/MapView.js
  2. +26 −15 geotagging/static/js/app/Spot.js
View
23 geotagging/static/js/app/MapView.js
@@ -18,7 +18,7 @@ $$.Map = Backbone.Model.extend({
toOpenLayers: function (){
return this.view.map
- },
+ }
});
@@ -39,8 +39,8 @@ $$.MapView = Backbone.View.extend({
zoomLayer: undefined,
mapElemId: '',
layerEl: '',
- static: false,
- },
+ static: false
+ };
this.collection.bind('add', this.addOne);
@@ -64,7 +64,7 @@ $$.MapView = Backbone.View.extend({
{numZoomLevels: 20}
));
- if ( this.settings.static ){
+ if (this.settings.static){
$(this.map.controls).each(function(i, control){
control.deactivate();
this.map.removeControl(control)});
@@ -89,26 +89,27 @@ $$.MapView = Backbone.View.extend({
},
center: function(onLayer){
+ var bounds;
+
if (onLayer){
- var bounds = this.model.collection.get(onLayer).toOpenLayers().getDataExtent();
- }else{
- var bounds = undefined;
+ bounds = this.model.collection.get(onLayer).toOpenLayers().getDataExtent();
+ } else {
this.model.collection.each(function(layer){
- if (_.isUndefined(bounds)){
+ if (_.isUndefined(bounds)) {
bounds = layer.toOpenLayers().getDataExtent();
- }else{
+ } else {
bounds.extend(layer.toOpenLayers().getDataExtent());
}
});
}
var olMap = this.model.toOpenLayers();
olMap.zoomToExtent(bounds);
- if ( olMap.zoom > this.settings.maxZoom ){
+ if (olMap.zoom > this.settings.maxZoom) {
olMap.zoomTo(this.settings.maxZoom);
}
}
});
-$$.maps = new $$.MapCollection()
+$$.maps = new $$.MapCollection();
View
41 geotagging/static/js/app/Spot.js
@@ -3,12 +3,22 @@ $$.Spot = Backbone.Model.extend({
layer: undefined,
initialize: function (options) {
- _.bindAll(this);
+ _.bindAll(this, 'getLatLng');
+
+ return this;
},
- toOpenLayers: function (){
- return this.view.marker
+ toOpenLayers: function () {
+ return this.view.marker;
},
+
+ getLatLng: function () {
+ if (!this.latLng) {
+ this.latLng = new OpenLayers.LonLat(this.get('lng'), this.get('lat'));
+ }
+
+ return this.latLng;
+ }
});
@@ -23,10 +33,10 @@ $$.SpotView = Backbone.View.extend({
events: {},
- initialize: function(options) {
+ initialize: function (options) {
_.bindAll(this, 'render');
this.model.view = this;
- if ( this.model.attributes.style.externalGraphic ) {
+ if (this.model.attributes.style.externalGraphic) {
var w = this.model.attributes.style.graphicWidth ? this.model.attributes.style.graphicWidth : 21;
var h = this.model.attributes.style.graphicHeight ? this.model.attributes.style.graphicHeight : 25;
var size = new OpenLayers.Size(w,h),
@@ -36,14 +46,15 @@ $$.SpotView = Backbone.View.extend({
};
},
- getIcon: function(){
+ getIcon: function () {
return this.icon ? this.icon : this.model.layer.getIcon();
},
render: function () {
this.marker = new OpenLayers.Marker(
- new OpenLayers.LonLat(this.model.get('lng'), this.model.get('lat')),
+ this.model.getLatLng(),
this.getIcon().clone());
+
this.model.layer.toOpenLayers().addMarker(this.marker);
return this;
}
@@ -54,10 +65,6 @@ $$.SpotView = Backbone.View.extend({
$$.Layer = Backbone.Model.extend({
map: undefined,
-
- getIcon: function() {
- return this.icon;
- },
initialize: function (options) {
log('init:layer');
@@ -76,9 +83,13 @@ $$.Layer = Backbone.Model.extend({
this.icon = new OpenLayers.Icon(this.icon, size, offset);
},
+
+ getIcon: function () {
+ return this.icon;
+ },
- toOpenLayers: function (){
- return this.view.layer
+ toOpenLayers: function () {
+ return this.view.layer;
}
});
@@ -111,7 +122,7 @@ $$.LayerView = Backbone.View.extend({
add: function(spot, collection){
//This is bound to a collection
- spot.layer = this.layer
+ spot.layer = this.layer;
spot.view = new $$.SpotView({
model: spot
});
@@ -141,7 +152,7 @@ $$.LayerView = Backbone.View.extend({
var view = new $$.SpotView({
model: spot
});
- view.render()
+ view.render();
}, this);

0 comments on commit c0e0aee

Please sign in to comment.