Permalink
Browse files

Fixed #14.

Resized map onload to circumvent grey box bug.
Loaded data asynchronously.
  • Loading branch information...
1 parent 6c15ed3 commit 1db141e8b3709e1f4f7db3d306fc1f98c1ad6877 @master-lincoln master-lincoln committed Apr 18, 2012
Showing with 35 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. +0 −1 public/mobile/index.html
  3. +4 −10 public/mobile/js/application.js
  4. +30 −11 public/mobile/js/map.js
  5. +0 −1 public/mobile/map.html
View
@@ -6,3 +6,4 @@
redis.out
luebeck-parking.sublime-project
luebeck-parking.sublime-workspace
+docs/
@@ -13,7 +13,6 @@
<script src="js/application.js"></script>
<script src="js/map.js"></script>
<script src="js/list.js"></script>
- <script type="text/javascript" src="http://141.83.151.102:8080/json/current?callback=saveJSON"></script>
</head>
<body>
@@ -1,5 +1,5 @@
-var serverUrl = "http://141.83.151.102:8080/json/current",
- data = {},
+var serverUrl = "http://141.83.151.102:8080/json/current?callback=?",
+ data = undefined,
infoWindow = {},
map = {};
@@ -12,14 +12,8 @@ function jsonError() {
}
function updateData(callback) {
- $.ajax({
- url: serverUrl,
- method:"GET",
- dataType:"json",
- success:callback,
- statusCode:{
- 404:jsonError
- }
+ $.getJSON('http://141.83.151.102:8080/json/current?callback=?', function(data) {
+ callback(data);
});
}
@@ -7,6 +7,7 @@ function resizeMap() {
//resize map to fit height
var mapHeight = $(window).height()-$(".ui-header:first").outerHeight();
$('#map-canvas').css('height', mapHeight+'px');
+ google.maps.event.trigger(map, 'resize');
}
function getMarkerAt(position) {
@@ -143,19 +144,25 @@ function buttonHandler(event) {
$(event.currentTarget).addClass("ui-btn-up-b");
}
+function init(d) {
+ data = d;
+ // add city buttons
+ $("#city-labels").empty();
+ $.each(data.cities, function(i, city) {
+ $('<a href="#" data-role="button" data-inline="true" data-theme="a">'+city.name+'</a>')
+ .click(buttonHandler)
+ .appendTo("#city-labels");
+ });
+ // enhance dynamically injected items
+ $("#map").trigger('create');
+}
+
// before changing the page insert dynamically created dom elements
$(document).bind("pagebeforechange", function(e, d) {
// if we are about to switch to the map view
if ( $(d.toPage).attr('id') == 'map' ) {
- /* -- add city buttons -- */
- $("#city-labels").empty();
- $.each(data.cities, function(i, city) {
- $('<a href="#" data-role="button" data-inline="true" data-theme="a">'+city.name+'</a>')
- .click(buttonHandler)
- .appendTo("#city-labels");
- });
- // enhance dynamically injected items
- $("#map").trigger('create');
+ if ( data === undefined )
+ updateData(init);
}
});
@@ -171,9 +178,21 @@ $(document).delegate("#map", "pageshow", function() {
map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
map.markers = [];
infoWindow = new google.maps.InfoWindow();
- initMarkers();
- $("#city-labels a:first").trigger('click');
+
+ if ( data === undefined ) {
+ updateData( function(d) {
+ data = d;
+ initMarkers();
+ $("#city-labels a:first").trigger('click');
+ });
+ } else {
+ initMarkers();
+ $("#city-labels a:first").trigger('click');
+ }
+
// triggerHandler is a lightweight equivalent to trigger
+ // without the resize event, the map stays grey
+ resizeMap();
$(document).trigger('mapLoaded');
});
@@ -12,7 +12,6 @@
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script src="js/application.js"></script>
<script src="js/map.js"></script>
- <script type="text/javascript" src="http://141.83.151.102:8080/json/current?callback=saveJSON"></script>
</head>
<body>

0 comments on commit 1db141e

Please sign in to comment.