Skip to content

Commit

Permalink
added Location.css_class and Location.direction methods.
Browse files Browse the repository at this point in the history
these methods can be overridden by subclasses, making it much easier
to customize the appearance of the embedded html fragments.
  • Loading branch information
adammck committed Aug 25, 2010
1 parent f3c636f commit 0938c22
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
28 changes: 28 additions & 0 deletions locations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class Location(models.Model):
class Meta:
abstract = True

# choices for the Location.direction method.
# (values stolen from label-overlay.js)
class Direction:
CENTER = "center"
ABOVE = "above"
RIGHT = "right"
BELOW = "below"
LEFT = "left"

def __unicode__(self):
"""
"""
Expand Down Expand Up @@ -120,6 +129,25 @@ def label(self):

return unicode(self)

@property
def css_class(self):
"""
Return the CSS class name of the label overlay. This method
should be overriden by subclasses wishing to customize the
appearance of the embedded HTML fragment.
"""

return "bubble"

@property
def direction(self):
"""
Return the direction which the embedded HTML fragment should be
offset from the anchor point. Return one of Location.Direction.
"""

return self.Direction.ABOVE


#class Country(Location):
# name = models.CharField(max_length=100)
Expand Down
9 changes: 2 additions & 7 deletions locations/static/javascripts/label-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ adammck.maps = adammck.maps || {};
this.arrow_ = null;

this.paneName = "overlayImage";
this.className = "label";
this.className = "bubble";
this.content = null;
this.minZoom = 0;
this.maxZoom = 99;
this.skin = namespace.Label.Skin.BUBBLE;
this.direction = namespace.Label.Direction.ABOVE;
this.setValues(options);

Expand Down Expand Up @@ -57,16 +56,12 @@ adammck.maps = adammck.maps || {};
"LEFT": "left"
};

namespace.Label.Skin = {
"BUBBLE": "bubble"
};

namespace.Label.prototype =
new google.maps.OverlayView();

namespace.Label.prototype.onAdd = function() {
this.wrapper_ = document.createElement("div");
this.wrapper_.className = "label-wrapper " + this.skin + " " + this.direction;
this.wrapper_.className = "label-wrapper " + this.className + " " + this.direction;

this.arrow_ = document.createElement("div");
this.arrow_.className = "arrow";
Expand Down
3 changes: 2 additions & 1 deletion locations/static/javascripts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jQuery(function() {
"map": map,
"content": loc.html(),
"position": new google.maps.LatLng(lat, lng),
"direction": adammck.maps.Label.Direction.CENTER
"direction": loc.attr("direction"),
"className": loc.attr("class")
});

bounds.extend(label.position);
Expand Down
2 changes: 1 addition & 1 deletion locations/templates/locations/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h2>Map</h2>
<div class="container"></div>

<ul class="labels">{% for type in location_types %}{% for location in type.locations %}
<li lat="{{ location.point.latitude }}" lng="{{ location.point.longitude }}">
<li class="{{ location.css_class }}" direction="{{ location.direction }}" lat="{{ location.point.latitude }}" lng="{{ location.point.longitude }}">
{{ location.as_html }}
</li>{% endfor %}{% endfor %}
</ul>
Expand Down

0 comments on commit 0938c22

Please sign in to comment.