Skip to content

Commit

Permalink
Option to specify default_point (defaulting to 0,0), preventing error…
Browse files Browse the repository at this point in the history
…s when there are no location items.
  • Loading branch information
gsterndale committed Sep 29, 2010
1 parent 8ffe848 commit 2fa3c80
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ These are options that can be passed to the `jMapping` function to change specif
* This selector defines where the content for the Google Maps info window for each location marker is.
This element will be searched for inside of the location elements specified in the `location_selector`.
If no element is found no Info Window will be attached to the marker.
* `default_point`:
* *Default*: `{lat: 0.0, lng: 0.0}`
* This point determines the Google Maps location if there are no location elements inside the specified `location_selector`.
* `metadata_options`:
* *Default*: `{type: "attr", name: "data"}`
* This is the set of options passed to the jQuery metadata function. It defines how the necessary
Expand Down
13 changes: 10 additions & 3 deletions jquery.jmapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,16 @@ if (GMap2){
};

var getBounds = function(doUpdate){
var newBounds, swPoint, nePoint;
var places_data = getPlacesData(doUpdate);
var newBounds = new GLatLngBounds(
$.jMapping.makeGLatLng(places_data[0].point),
$.jMapping.makeGLatLng(places_data[0].point) );
if(places_data.length){
nePoint = swPoint = places_data[0].point;
}else{
nePoint = swPoint = settings.default_point;
}
newBounds = new GLatLngBounds(
$.jMapping.makeGLatLng(swPoint),
$.jMapping.makeGLatLng(nePoint) );

for (var i=1, len = places_data.length ; i<len; i++) {
newBounds.extend($.jMapping.makeGLatLng(places_data[i].point));
Expand Down Expand Up @@ -224,6 +230,7 @@ if (GMap2){
link_selector: 'a.map-link',
info_window_selector: '.info-box',
info_window_max_width: 425,
default_point: {lat: 0.0, lng: 0.0},
metadata_options: {type: 'attr', name: 'data-jmapping'}
},
makeGLatLng: function(place_point){
Expand Down
13 changes: 4 additions & 9 deletions jquery.jmapping.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions spec/jmapping_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ Screw.Unit(function(){
});
});

describe("jMapping with no location items", function(){
after(function(){
$('#map').data('jMapping', null);
});
it("should function correctly", function(){
$('#map').jMapping({
side_bar_selector: 'ul#empty-map-side-bar',
});
expect($('#map').data('jMapping')).to(be_true);
});
});

describe("jMapping with options", function(){
before(function(){
// mock out Marker
Expand Down
3 changes: 3 additions & 0 deletions spec/suite.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
</div>
</li>
</ul>

<ul id="empty-map-side-bar">
</ul>
</div>
</body>
</html>

0 comments on commit 2fa3c80

Please sign in to comment.