org.hd.d.pg2k.webSvr.virtualHosts.AlohaEarth
Class AEUtils

java.lang.Object
  extended by org.hd.d.pg2k.webSvr.virtualHosts.AlohaEarth.AEUtils

public final class AEUtils
extends java.lang.Object

Support for Aloha Earth virtual site.


Field Summary
private static Name _GVT_CATEGORY
          Category whose LocationMap entries are used by getViewLocationMapVirtualPrefix(); not null.
private static Name _GVT_CATEGORY_LU_PREFIX
          Lookup prefix; not null.
static java.lang.String AE_SELF_RRURL
          Root-relative URL to "page" at which Aloha Earth is shown.
(package private) static DataSourceBean.AEPLinkedKey AEKey
          Key for AE-linked data in DataSourceBean.
static int BASE_2D_EARTH_MAP_HEIGHT
          Height of base image (pixels).
static java.lang.String BASE_2D_EARTH_MAP_RRURL
          Root-relative URL or source/base 2D Earth image for clickable map.
static int BASE_2D_EARTH_MAP_WIDTH
          Width of base image (pixels).
static int DISPLAY_2D_EARTH_MAP_HEIGHT
          Display height of image to show visitor.
static int DISPLAY_2D_EARTH_MAP_WIDTH
          Display width of image to show visitor.
(package private) static int DYN_MAP_IMG_TYPE
          Type of clickable-map image that we dynamically generate.
(package private) static ExhibitMIME.ExhibitTypeParameters ETP
          ExhibitMIME entry for the chosen outout type.
(package private) static int EXHIBIT_MARKER_RGB_COLOUR
          Colour of marker to show location of exhibit on map, in RGB format.
static int INITIAL_ZOOM
          The initial zoom ratio as seen by a visitor.
static int LABEL_CLEARANCE_PX
          Label clearance (ie approximately the typical text height or 1em) in pixels; strictly positive.
static int LABEL_COUNT_MAX
          Maximum number of labels to show; strictly positive.
static boolean LABEL_HORIZ
          True if labels run horizontally, false if vertical.
private static java.lang.String LABEL_HTML_POSTAMBLE
          Postamble for label overlay HTML.
private static java.lang.String LABEL_HTML_PREAMBLE
          Preamble for label overlay HTML.
private static boolean LABEL_PMDS
          If true then do a "poor-man's drop-shadow" to help improve contrast.
static int LABEL_TN_CLEARANCE_PX
          Overlay thumbnail clearance is longest (small) thumbnail dimension.
static java.lang.String MAP_SERVLET_RRURL
          Full root-relative URL given for map image servlet.
static java.lang.String MAPIMG_SERVLET_MOUNT_DIR
          Root-relative URL to base directory on which map image servlet is mounted.
static int MAX_ZOOM
          Maximum zoom ratio from initial base image.
static int MIN_ZOOM
          Minimum zoom ratio from initial base image.
(package private) static int TITLE_AREA_MARKER_RGB_COLOUR
          Colour of marker to show area indicated by title, in RGB format.
static int ZOOM_RATIO
          Zoom ratio: what factor we zoom in/out each time; at least 2.
 
Constructor Summary
AEUtils()
           
 
Method Summary
private static boolean _screenForGetViewTitle(Name prefix, Location.Estd area)
          Screens entry from Location map; returns true if usable.
private static void appendLabelHTML(java.lang.StringBuilder sb, int leftPX, int topPX, boolean strong, java.lang.String labelText, java.lang.String labelColour, java.lang.String labelHref)
          Generate HTML for one overlay label and append to given StringBuilder.
static int applyZoom(int pixels, int zoomFactor)
          Apply zoom to value in pixels.
static AlohaEarthMapCache getAemfb(DataSourceBean dsb)
          Get the filter bean associated with the current DataSourceBean; never null.
static java.lang.String getViewLocationLabels(AEParams aeps, DataSourceBean dsb, AlohaEarthMapCache aemfb, boolean doThumbnails)
          Create HTML label text to overlay the map; returns "" if none, never null.
static java.util.List<Name> getViewLocationMapLabelPrefixes(AEParams aeps, LocationMap lm, AlohaEarthMapCache cache)
          Gets locationMap keys for labels to add to the map; result may be empty but is never null.
static Name getViewLocationMapVirtualPrefix(AEParams aeps, LocationMap lm)
          This gets a virtual prefix from the LocationMap for the current view or empty String if none suitable; never null.
(package private) static java.awt.image.BufferedImage makeScaledBaseMapFragment(java.awt.Rectangle srcRect, javax.servlet.ServletContext context)
          Make scaled base image fragment given Rectangle bounding source pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AE_SELF_RRURL

public static final java.lang.String AE_SELF_RRURL
Root-relative URL to "page" at which Aloha Earth is shown. This is used to allow the Aloha Earth page to easily refer to itself by name, for example as the target of a form submission.

See Also:
Constant Field Values

BASE_2D_EARTH_MAP_RRURL

public static final java.lang.String BASE_2D_EARTH_MAP_RRURL
Root-relative URL or source/base 2D Earth image for clickable map. This is assumed to be a smallish low-colour image on which we can write red and white markings that will be visible and which we convert back to a clear and small palette-based image in a popular and widely-supported format such as GIF or PNG.

See Also:
Constant Field Values

BASE_2D_EARTH_MAP_WIDTH

public static final int BASE_2D_EARTH_MAP_WIDTH
Width of base image (pixels).

See Also:
Constant Field Values

BASE_2D_EARTH_MAP_HEIGHT

public static final int BASE_2D_EARTH_MAP_HEIGHT
Height of base image (pixels).

See Also:
Constant Field Values

MAPIMG_SERVLET_MOUNT_DIR

public static final java.lang.String MAPIMG_SERVLET_MOUNT_DIR
Root-relative URL to base directory on which map image servlet is mounted. This must match entry in web.xml.

Note that this contains a leading and trailing '/'.

Any URI under this point will be directed to the servlet, so we can pick the "expected" suffix to avoid surprising broswers with the MIME type of the downloaded image.

Because these generated images may have to change the exhibit set or meta data may change it it not appropriate for this to be under /_static.

See Also:
Constant Field Values

DYN_MAP_IMG_TYPE

static final int DYN_MAP_IMG_TYPE
Type of clickable-map image that we dynamically generate. Need not be the same as the raw base image, as long as it can (efficiently) encode the modified image in a byte-indexed format.

Good types to use are PNG and GIF (when the LZW patent expires).

See Also:
Constant Field Values

ETP

static final ExhibitMIME.ExhibitTypeParameters ETP
ExhibitMIME entry for the chosen outout type.


MAP_SERVLET_RRURL

public static final java.lang.String MAP_SERVLET_RRURL
Full root-relative URL given for map image servlet. The extension is chosen to match the MIME type.

We will append GET-style parameters to allow the appropriate zoom and shift to be applied.


ZOOM_RATIO

public static final int ZOOM_RATIO
Zoom ratio: what factor we zoom in/out each time; at least 2. Also determines size of lateral (up/down/left/right) step as fraction of width of whole image as shown to the user.

A value of 2 or 3 is probably good; up to 8 is probably OK.

See Also:
Constant Field Values

MIN_ZOOM

public static int MIN_ZOOM
Minimum zoom ratio from initial base image. A negative value means the image can be zoomed out (shrunk) relative to the base image.

This is in terms of zooms in or out (changes in each dimension) by ZOOM_RATIO.


MAX_ZOOM

public static int MAX_ZOOM
Maximum zoom ratio from initial base image. A positive value means the image can be zoomed in (expanded) relative to the base image. This will determine how many pixels on a side a single source pixel can be expanded to.

This is in terms of zooms in or out (changes in each dimension) by ZOOM_RATIO.

This must be no less than MIN_ZOOM, and is usually positive.

Since this effectively limits the precision with which a user can select an area to view on the one hand, and yet increases the 'chunkiness' of the maximally zoomed image, is is difficult to chose an optimal value, but one that expand source pixels to no more than about 8--16 pixels on a side is probably reasonable.


INITIAL_ZOOM

public static int INITIAL_ZOOM
The initial zoom ratio as seen by a visitor. The raw image is zoomed by this amount and this determines the size of the derived clickable map to be shown to the visitor at all levels of zoom.

This is usually but not always the same as the MIN_ZOOM, but must be in the inclusive range [MIN_ZOOM, MAX_ZOOM].


DISPLAY_2D_EARTH_MAP_WIDTH

public static final int DISPLAY_2D_EARTH_MAP_WIDTH
Display width of image to show visitor. Determined by original image width and INITIAL_ZOOM.


DISPLAY_2D_EARTH_MAP_HEIGHT

public static final int DISPLAY_2D_EARTH_MAP_HEIGHT
Display height of image to show visitor. Determined by original image height and INITIAL_ZOOM.


EXHIBIT_MARKER_RGB_COLOUR

static final int EXHIBIT_MARKER_RGB_COLOUR
Colour of marker to show location of exhibit on map, in RGB format. Since the map is usually rendered in green (land) and blue (sea) this should probably be red or some other high-contrast colour. This should probably also be fully opaque to minimise encoded image size (eg 0xffff0000 for opaque red).

See Also:
Constant Field Values

TITLE_AREA_MARKER_RGB_COLOUR

static final int TITLE_AREA_MARKER_RGB_COLOUR
Colour of marker to show area indicated by title, in RGB format. Since the map is usually rendered in green (land) and blue (sea) and individual exhibits in red this should probably be orange or some other nearish-red colour. This should probably also be fully opaque to minimise encoded image size (eg 0xffff0000 for opaque red).

See Also:
Constant Field Values

_GVT_CATEGORY

private static final Name _GVT_CATEGORY
Category whose LocationMap entries are used by getViewLocationMapVirtualPrefix(); not null.


_GVT_CATEGORY_LU_PREFIX

private static final Name _GVT_CATEGORY_LU_PREFIX
Lookup prefix; not null.


LABEL_HORIZ

public static final boolean LABEL_HORIZ
True if labels run horizontally, false if vertical.

See Also:
Constant Field Values

LABEL_CLEARANCE_PX

public static final int LABEL_CLEARANCE_PX
Label clearance (ie approximately the typical text height or 1em) in pixels; strictly positive.

See Also:
Constant Field Values

LABEL_TN_CLEARANCE_PX

public static final int LABEL_TN_CLEARANCE_PX
Overlay thumbnail clearance is longest (small) thumbnail dimension.

See Also:
Constant Field Values

LABEL_COUNT_MAX

public static final int LABEL_COUNT_MAX
Maximum number of labels to show; strictly positive. This could be partially determined by the map image size, ie how many labels can be comfortably shown.


LABEL_HTML_PREAMBLE

private static final java.lang.String LABEL_HTML_PREAMBLE
Preamble for label overlay HTML.

See Also:
Constant Field Values

LABEL_HTML_POSTAMBLE

private static final java.lang.String LABEL_HTML_POSTAMBLE
Postamble for label overlay HTML.

See Also:
Constant Field Values

LABEL_PMDS

private static final boolean LABEL_PMDS
If true then do a "poor-man's drop-shadow" to help improve contrast.

See Also:
Constant Field Values

AEKey

static final DataSourceBean.AEPLinkedKey AEKey
Key for AE-linked data in DataSourceBean. Package-only to keep scope as narrow as possible!

Constructor Detail

AEUtils

public AEUtils()
Method Detail

applyZoom

public static int applyZoom(int pixels,
                            int zoomFactor)
Apply zoom to value in pixels. A negative value reduces the value (brings it towards zero) and a positive one increases it; zero returns the value unchanged.

This computes input * (ZOOM_RATIO ^ zoomFactor).


makeScaledBaseMapFragment

static java.awt.image.BufferedImage makeScaledBaseMapFragment(java.awt.Rectangle srcRect,
                                                              javax.servlet.ServletContext context)
Make scaled base image fragment given Rectangle bounding source pixels. Returns writable ARGB true colour image fragment suitable to draw on.

May consume significant resources (CPU and memory), so access and concurrency should be controlled.

Parameters:
srcRect - as returned by AEParams.getSourceRectangleToDisplay
context - servlet context to retrieve base image from

getViewLocationMapVirtualPrefix

public static Name getViewLocationMapVirtualPrefix(AEParams aeps,
                                                   LocationMap lm)
This gets a virtual prefix from the LocationMap for the current view or empty String if none suitable; never null. This returns the prefix the best possible match for the current view, or returns ""/EMPTY if it cannot find anything suitable. The prefix returned does contain the category, and is of the form dir/word-{word-}*, eg "places-and-sights/England-London-".

This should always return "" at the outermost level.

This looks up places-and-sights prefixes in the given LocationMap, assuming that each such prefix is a reasonable region. This tries a number of methods to find the "best" match, in this order (excluding any "whole Earth" match:

  1. The smallest location prefix wholly contained in the current view that contains the user's selected target centroid.
  2. The largest location prefix wholly contained in the current view.
  3. The smallest such Estd entry that wholly contains the current view.
  4. The smallest such Estd entry whose centre is in the current view.

      Parameters:
      aeps - parameters with which map to display is chosen; not null
      lm - map to do lookup in; not null
      Returns:
      virtual prefix lookup into LocationMap.getMapFromNamePrefixToLocation() or "" if none

_screenForGetViewTitle

private static boolean _screenForGetViewTitle(Name prefix,
                                              Location.Estd area)
Screens entry from Location map; returns true if usable. Returns true if:
  • Name indicates a places-and-sights entry.
  • The area is smaller than whole Earth area.


getViewLocationMapLabelPrefixes

public static java.util.List<Name> getViewLocationMapLabelPrefixes(AEParams aeps,
                                                                   LocationMap lm,
                                                                   AlohaEarthMapCache cache)
Gets locationMap keys for labels to add to the map; result may be empty but is never null. More important labels are earlier in the list.

We always try to include the title label, if available.

We then count how many uses of each prefix there are in this view, and essentially return the top LABEL_COUNT_MAX of them, but exclude any that are too close to any already selected (and maybe those that are too near an edge to be read properly).

We are only interested in items wholly contained in the current view.

Returns:
best-first list of prefixes thumbnails; never null

getViewLocationLabels

public static java.lang.String getViewLocationLabels(AEParams aeps,
                                                     DataSourceBean dsb,
                                                     AlohaEarthMapCache aemfb,
                                                     boolean doThumbnails)
Create HTML label text to overlay the map; returns "" if none, never null. This creates an unnumbered list with one or more absolutely-positioned (within the encompassing relatively positioned parent element). If there are no labels to show then this does not create the UL element and the result is "".

The first view labels may be rendered more strongly.


appendLabelHTML

private static void appendLabelHTML(java.lang.StringBuilder sb,
                                    int leftPX,
                                    int topPX,
                                    boolean strong,
                                    java.lang.String labelText,
                                    java.lang.String labelColour,
                                    java.lang.String labelHref)
Generate HTML for one overlay label and append to given StringBuilder. The text label's content, colour, position and strength is chose.

Parameters:
labelColour - colour for label text; null if default
labelHref - href for label text; null if none

getAemfb

public static AlohaEarthMapCache getAemfb(DataSourceBean dsb)
                                   throws java.io.IOException
Get the filter bean associated with the current DataSourceBean; never null. A new empty value is created on first use and when the AEP changes.

Throws:
java.io.IOException

DHD Multimedia Gallery V1.53.0

Copyright (c) 1996-2009, Damon Hart-Davis. All rights reserved.