Williamsburger Maps, v2.5
Tuesday, August 2nd, 2005

For version 2.5 of Williamsburger Maps, I focused on the following:

  1. bug fixes
  2. performance
  3. code cleanup

And a new (albeit mostly transparent) feature snuck its way in there, too!

New Feature

  • Add a PHP method, autocomplete_map_coordinates, to automatically recenter maps on the actual center of its locations rather than the center hardcoded in the database.
    /**
     * Given a map, change the lat/lng to be the center of all of its
     * locations.
     *
     * NOTE: does an inplace modification of the map input.
     *
     * @param map a map
     * @return the same map, with updated lat/lng property
     */
    
    function autoupdate_map_coordinates( $map ) {
      $border_coordinates = _get_map_border_coordinates( $map->pk );
    
      if ( $border_coordinates ) {
        $new_lat = ( $border_coordinates[ 0 ]->min_lat + $border_coordinates[ 0 ]->max_lat ) / 2;
        $new_lng = ( $border_coordinates[ 0 ]->min_lng + $border_coordinates[ 0 ]->max_lng ) / 2;
    
        $map->lat = $new_lat;
        $map->lng = $new_lng;
      }
    
      return $map;
    }
    
    
    /**
     * Given a map ID, return a set of the locations captured within that
     * map.
     *
     * @param map_id a numeric map ID
     */
    
    function _get_map_border_coordinates( $map_id ) {
      $select_query =
        "SELECT min( l.lat ) AS min_lat,
                max( l.lat ) AS max_lat,
                min( l.lng ) AS min_lng,
                max( l.lng ) AS max_lng
         FROM wbmaps_maps map, wbmaps_locations l, wbmaps_map_locations ml
         WHERE ml.mapkey='" . $map_id . "'
           AND ml.mapkey=map.pk
           AND ml.locationkey=l.pk ";
    
      global $wpdb;
      return $wpdb->get_results( $select_query );
    }
    

Bug Fixes

  • Fixed expand/collapse bug by ending each expansion by setting the div’s height to null during Effect.Size’s complete function instead of leaving it set explicitly to the original offsetHeight.
    WbMaps.EffectsUtil._resetCollapse = function( divId, milliSeconds ) {
      if ( milliSeconds == undefined ) {
        milliSeconds = WbMaps.EffectsUtil._collapseOriginalHeights.get( divId ) * 2;
      }
    
      var originalOverflow = WbMaps.EffectsUtil._collapseOriginalOverflowSettings.get( divId );
    
      new Effect.Size( divId,
                       null,
                       WbMaps.EffectsUtil._collapseOriginalHeights.get( divId ),
                       milliSeconds,
                       Math.round( milliSeconds / 60 ),
                       { complete:function( ) {
                           getDivStyle( divId ).display = 'block';
                           getDivStyle( divId ).overflow = originalOverflow;
                           getDivStyle( divId ).height = null;
                         }
                       } );
    };
    
  • Give the two different “ALL” buttons distinct IDs so that the mouseover color change only affects the one the mouse is over instead of affecting the first one on the page.

Performance

  • Pull basic Location information (ID, lat/long, name, etc.) in the initial feed, with a subsequent request for full information when the user chooses to expand the side panel. The hope is that this will reduce the memory usage and allow for more locations to be held in memory at once in the future.
  • Switch order of panel collapses to collapse the type buttons before generating the map.
  • Remove a few of the static maps: locationIdsMap and sideHtmlsMap. This may cause memory problems with the high number of String concatenations within the Location object done with each side panel cell expansion, but that’s a problem I can solve with better caching within the Location object rather than a big global cache of html.

Code Cleanup

  • Upgrade to ArrayMap v1.3, which now contains values( ) and entrySet( ) methods.
  • Create both WbMaps.Map and WbMaps.MapInfo objects to encapsulate various parts of the Map functionality.
  • Use MapInfo object to store the results of the map info XML query rather than pulling from the XML every time it was needed.
  • Rename static variables into static WbMaps.* variables.
  • Moved the majority of the map logic into the WbMaps.Map class.
  • Create WbMaps.EffectsUtil to hold the collapse/expand methods, as well as future common visual methods.
  • Call out to WbMaps.EffectsUtil.buttonMouseOver and WbMaps.EffectsUtil.buttonMouseOut for button mouseovers rather than hardcoding colors into the php.
  • Remove unused PHP methods (most html creation has been moved into javascript).

At this point, there are only a few methods left in the Williamsburger Maps JavaScript which don’t fall into the Prototype packaging structure. I’ll clean those up in a future release, especially since they all seem to relate to the type / rating buttons, which I intend to eventually migrate over into JavaScript from PHP anyway.

Leave a Reply