TMap represents a map window drawn on a web page. A map can display one or more image tiles in a frame, and convert coordinates from graphic to geographic systems.
A map is composed by a set of objects:
String, optional. If you plan to use event hadlers, id should be set equal to the name of a global variable holding a reference to the map object. Please note that if the map object is used in child frames, the "parent." modificator has to be added. Thus, if we have a global variable named "Map" in the parent document, but we draw it on a child frame, id sould set to "parent.Map".
TFrame object embedding the map. The frame can intercept all the mouse events directed to the map. A background color can be set using the TFrame.setBackground method.
Geographic extent of the map, represented by a TRect object.
Number of map tiles concurrently visible along the X and Y axis of the map.
Array holding a reference to the map tiles composing the map. Each element of the array, accessible in the form tiles[row][col], is a TImage object.
drawList is an array of TMapObject objects to be drawn on the map. Geographic coordinates are converted by the TMap object into graphical coordinates. Only objects falling within the visible extent of the map are drawn.
Class constructor, returns a new instance of a TMap object.
varName (string) stores the fully qualified global variable
name for the object pointer (for example 'parent.map');
aWidth and aHeight (integer) specify map total size in pixels;
numTilesX and numTilesY (integer, optional, both default to 1)
give the number of tile columns and rows the map is made of;
aX and aY (integer, optional, both default to 0) give the
position of the upper-left map corner in the web page.
Returns the HTML definition of the map object.
Given an object in graphical (screen) coordinates, returns an
object of the same class in geographical coordinates.
Graphical coordinates are absolute, i.e. relative to the page
origin.
Given an object in geographical coordinates, returns an object
of the same class in graphical (screen) coordinates.
Graphical coordinates are absolute, i.e. relative to the page
origin..
TProjectMap represents a map linked to a TProject object. The TProjectMap allows the user to browse the published maps available through the TProject object.
Inherits from: TMap.
Pointer to the TProject object to which the map is linked.
Small integer, index of the current element in the project.zoomLevels array.
Small integer, index of the current element in the project.themes array.
Small integer, index of the current element in the project.zoomLevels array if the value is between 0 and 99; otherwise, it holds a value for one of the standard map tools: see the setTool() method for a full description.
TPoint object representing the map center geographic coordinates. Instead of modifying center directly, you should use the gotoXY() method to change this value; gotoXY() calls update() as to return the exact map center after having loaded the map tiles.
TPoint object representing the lower-left-corner tile row and column indexes in the current zoomLevel tiles array.
Class constructor.
Returns the HTML definition of the map object. It relies on map center and extent objects, which are calculated by the update() method.
Recalculates the map extent and center before drawing. This method is called automatically by the gotoXY and setZoomLevel, setTheme and setTool methods, but must be manually called in the initialization code after having built the map object.
If the argument list (cZoom, cTheme, cTool, cPosition) is passed to update, statusChanged() will be called in order to trigger document reloading. In the initialization code, a update() call with no parameters should be made, unless you are sure of which frames are already loaded. If you need to force the refresh of the whole interface, call update(1,1,1,1) instead.
If the statusChanged handler has not been defined, a document.location.reload() call will be performed in every frame of the window.
Moves the center of the map at the specified geographic coordinates; a new zoom level can be specified with the newlev parameter.
Pans the map by a specified amount of map units along the X and Y axis. Negative amounts can be specified for indicating west- and southbound movements.
Pans the map by a specified amount of map tiles along the X and Y axis. Negative amounts can be specified for indicating west- and southbound movements. The method calls moveMap multiplying delta by te current zoom's tile width and height.
Changes the current zoom level to newlev. If disableEvents is true, statusChanged is not called.
Changes the current map theme. If disableEvents is true, statusChanged is not called.
If the theme specified is not available at the current zoom level, the defaultTheme() callback function is called to return a proper value.
Changes the current map tool. If disableEvents is true, statusChanged is not called.
Tool value can be one of the following:
If the tool specified is not available at the current zoom level, the defaultTool() callback function is called to return a proper value.
Smallint, must return the default tool whenever a zoom change has invalidated the current tool.
Smallint, must return the default theme whenever a zoom change has invalidated the current one.
Called whenever the map state has changed and there's a need to update the map or the user interface.
Users should implement a stateChanged handler to redraw the map and/or the browser window whenever there's a need to do so. Map update is tipically done by reloading the frame containing the map page. The following is a typical implementation:
// Map points to a TMap instance which has been already defined
// Now we assign our custom function to the statusChanged pointer
Map.statusChanged = Map_statusChanged
function Map_statusChanged(cZoom, cTheme, cTool, cPosition)
{
// the map is drawn in a page loaded in the "mappage" frame
// we have to refresh it always
frames["mappage"].document.location.reload()
// we update the toolbar to reflect changes in the current tools
if (cZoom || cTheme || cTool)
frames["toolbar"].document.location.reload()
// update the locator map just when map position or zoom has changed
if (cZoom || cPosition)
frames["fr_locator"].document.location.reload()
// the "ruler" frame contains a control which allows to change zoom
// and has to be updated as it shows the current zoom also
if (cZoom)
frames["ruler"].document.location.reload()
}
statusChanged() is called by the update() method. It
allows for a full control over document reloading in the process
of updating the user interface. Apart from optimizing document
reloading, it's the right place to put the control code for your
application; for example:
// hide the locator rectangle when at the maximum zoom level:
locator.lrect.visible = (Map.zoomLevel > 0)
// match the current imagemap with the current theme: if (cTheme) Map.tool = Map.theme
// show the graphic map legend by loading the
appropriate file:
if (cTheme) frames['docpage'].document.location.href='legend_' +
Map.theme + '.htm'
If a statusChanged handler hasn't been defined, the
update method will refresh every window's frame instead.
TLocatorMap represents a locator map linked to a TProjectMap object. The locator allows the user to move quickly along a theme's extent by clicking on it, and shows the current position and map extent as an highlighted rectangle.
Inherits from: TMap.
Pointer to the TProjectMap object to which the map is linked.
TMapObject object representing the current map location on the locator. Please refer to TMapObject description about representing hollow rectangles with div tags.
Builds a TLocatorMap object. aProjectMap points to an already existing TMap object. aX, aY, aWidth, aHeight specify the graphical size and position of the locator relative to the web page's origin. aID holds the name of the global variable pointing to the locator object as it is referred from the page in which the locator is inserted. aImgSrg is the full path of the image file of the locator map.
This is an example of the initialization code of a map and its locator:
var Map = new TProjectMap(Project, 'parent.Map', 380, 380, 1, 1) var locator = new TLocatorMap(Map, 'parent.locator', 180,180, 'locator.png') locator.extent.moveTo(1503400, 5025200, 1521400, 5043200) locator.lrect.contents = new TImage('../img/dummy.png', 0, 0)
where Map is an existing TMap object. Please note that the image path is relative to that of the page in which the locator has to be drawn. Both the objects are referred as "parent.objVarName" because they are inserted in subframes of the main window where the variables Map and locator are being defined.
By default, the project's extent is assigned to the locator extent. This can be overridden by specifying the locator extent as shown above.
Inherits from: TFrame.
TMapObject represents a geometric object which can be drawn on a map.
When representing rectangles, note that some browsers don't feature precise absolute <DIV> dimensioning, unless the div itself contains a dimensioned object like an image. A good workaround is, once built the rectangle object, inserting a transparent image in it:
mapObj.contents = new TImage('../img/dummy.png', 0, 0)
The update methods automatically resizes images inserted directly in the rectangle. If you want to use a background image and have full control on it you'd rather use the TMapObject.style.setBackground method (inherited from TFrame).
Points to a geometric object, either a TPoint or a TRect, in geographical coordinates.
Optional string identifying the source table, or class, for the object.
Optional string identifying the unique ID of the object within its class.
Boolean, indicates wether the object has to be drawn inside the map frame (true) or over it (false). If drawn inside, the object will be unaccessible to mouse events.
String of two characters, determines the placement of the frame's rectangle relative to the geo point's coordinates: center ('c'), upper ('u'), lower ('l') for the first char (y coordinate); center ('c'), left ('l') and right ('r') for the second char (x coordinate). For example: cc for center center (i.e. the rect's centroid), ur for upper-right, lc for lower center.
Builds and returns a new TMapObject object.
obj is a geometric object, either a TPoint or a TRect; table and id are optional strings identifying the table (or class) and the unique ID of the object, and can be used in event handlers. imgPath, imgW and imgH specify path name, width and height of an image which can be either a fixed symbol when representing TPoint objects, or a filling texture when representing rectangles. varname is an optional string representing the fully qualified name of the global variable holding the object's instance; options allow to specify centering for point objects by setting ptOffset: see the ptOffset property for details.
Updates object's graphic coordinates according to the visible map extent. map is a variable pointing to a TMap object.
This method is automatically called by TMap.toString() before drawing map objects.
JS-GIS © 2001, 2002 by Luca S. Percich (mailto:luca.percich@reacoop.it)
Last updated: dec 26, 2002