Click or drag to resize

Telogis.GeoBase.MapLayers.XSLTObjectLayer

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release

MapLayers.XSLTObjectLayer inherits from MapLayers.AbstractLayer.

Creates a layer to contain a large number of objects that are read from an XML file and displayed. It uses XSLT for handling object clipping to the viewport, which loads more quickly than the RTree used in MapLayers.ObjectLayer at the cost of flexibility. Markers are loaded cell-by-cell in a grid (whose pitch may be specified with the MapLayers.XSLTObjectLayer.config.cellCount configuration property) and are specified by data read from the XML by specified XPath expressions (relative to each marker tag). Note: In IE9, you must add the following header to the HTML file when using XSLTObjectLayer:

JavaScript
<meta http-equiv="X-UA-Compatible" content="IE=8">
Constructor
NameDescription
MapLayers.XSLTObjectLayer(config)

Arguments

  • config (Object) - Configuration options for the MapLayers.XSLTObjectLayer.

    Properties
    NameTypeDescription
    anchorPointPoint

    An object describing the point in each marker image that should correspond to the actual location it represents on the map. The coordinates in this point are proportions of the image's width and height.

    Defaults to new Point (0.5).
    balloonConfigObject

    The configuration object for the balloons for each XML marker, if desired. Note that using balloons requires a great deal more DOM manipulation of the layer, decreasing its efficiency. Of these configuration properties, MapLayers.Balloon.config.layer and MapLayers.Balloon.config.silent cannot be overridden.

    Defaults to null.
    balloonContentFunc (Object data) Function

    A function to call to generate HTML content to fill balloons with, if MapLayers.XSLTObjectLayer.config.balloonConfig is supplied. Note that the dynamicBalloonContent property determines how often this is called.

    Arguments
    • data (Object) - The data, evaluated from the XML, that pertain to the current map object. This includes by default the following properties (which may be overridden), but will also contain any extra data specified with the MapLayers.XSLTObjectLayer.config.extraData configuration property. Note: XSLTObjectLayer does not work in IE9 unless the following header is added to the HTML file: <meta http-equiv="X-UA-Compatible" content-"IE=8">

      Properties
      NameTypeDescription
      idString

      The string ID of the marker, which will correspond to its DOM ID unless overridden by additional data instructions.

      locLatLon

      The latitude-longitude coordinates of the marker, as used to clip it to the viewport.

      posPoint

      The x-y coordinates of the marker on the map. These are specified relative to the map-layer container div.

      srcString

      The image src attribute of the marker image, as read from the XML. This is the 'raw' source rather than the final one, since it is the result of MapLayers.XSLTObjectLayer.config.imgSrcFunc called with this data object that generates the actual value.

    Returns

    String - The HTML string to populate the balloon with.

    cellCountPoint

    The number of cells to divide the viewport into in the x- and y- directions.

    Defaults to new Point (3, 3).
    dynamicBalloonContentBoolean

    Whether the content of the balloon is expected to change if it is hidden and shown again. If set, then the specified balloonContentFunc will be called each time the balloon is shown.

    Defaults to false.
    extraDataObject

    An object containing as its keys any extra properties to read from the object data in the XML file, with the corresponding XPath expressions (relative to the base marker tag, as specified by MapLayers.XSLTObjectLayer.config.objTagName) as the values for each. These extra properties are augmented with additional per-marker data (latitude-longitude coordinates, x-y coordinates, an ID and a raw icon string) and passed to MapLayers.XSLTObjectLayer.config.balloonContentFunc and MapLayers.XSLTObjectLayer.config.imgSrcFunc. For example, to read a 'name' attribute for each marker:

    extraData: {name: '@name'} Defaults to {}.
    imgPathString

    A filesystem path to an image to use for all objects on the layer. Overrides MapLayers.XSLTObjectLayer.config.imgXPath if present. If set to '', MapLayers.XSLTObjectLayer.config.imgXPath is used instead.

    Defaults to ''.
    imgSrcFunc (Object data) Function

    A function to map the raw image source read from the XML file to an actual filesystem path, to allow for the case where this attribute specifies an ID rather than an actual URI. For example, if the XML data specify as attributes a base filename ('icon'), extension ('ext'), and directory ('dir') -- which need to be combined to retrieve the image path -- the MapLayers.XSLTObjectLayer.config.extraData property could be specified as:

    JavaScript
    imgXPath: '@icon',
    extraData: {
    
        extension: '@ext',
        directory: '@dir'
    }

    and the corresponding MapLayers.XSLTObjectLayer.config.imgSrcFunc would be:

    JavaScript
    imgSrcFunc: function (data) {return data.directory + '"' + data.src + data.extension;}
    Arguments
    • data (Object) - The data, evaluated from the XML, that pertain to the current map object. This includes by default the following properties (which may be overridden), but will also contain any extra data specified with the MapLayers.XSLTObjectLayer.config.extraData configuration property. Note: XSLTObjectLayer does not work in IE9 unless the following header is added to the HTML file: <meta http-equiv="X-UA-Compatible" content-"IE=8">

      Properties
      NameTypeDescription
      idString

      The string ID of the marker, which will correspond to its DOM ID unless overridden by additional data instructions.

      locLatLon

      The latitude-longitude coordinates of the marker, as used to clip it to the viewport.

      posPoint

      The x-y coordinates of the marker on the map. These are specified relative to the map-layer container div.

      srcString

      The image src attribute of the marker image, as read from the XML. This is the 'raw' source rather than the final one, since it is the result of MapLayers.XSLTObjectLayer.config.imgSrcFunc called with this data object that generates the actual value.

    Returns

    String - The actual path to the image.

    imgXPathString

    An XPath expression detailing the path to the image source for each object in the XML, if a different image is being used for each object. This should be relative to the marker tag specified by the MapLayers.XSLTObjectLayer.config.objTagName property.

    Defaults to null.
    latXPathString

    An XPath expression detailing the path to the latitude data of each object in the XML. This should be relative to the marker tag specified by the MapLayers.XSLTObjectLayer.config.objTagName property.

    Defaults to '@lat'.
    lonXPathString

    An XPath expression detailing the path to the longitude data of each object in the XML. This should be relative to the marker tag specified by the MapLayers.XSLTObjectLayer.config.objTagName property.

    Defaults to '@lon'.
    objTagNameString

    The tag name to search for (recursively) in the MapLayers.XSLTObjectLayer's XML document in order to select the relevant marker nodes.

    Defaults to 'p'.
    queryFiltersString

    An XSL string of additional filters to run as tests for each object tag in the XML. If any of these tests fail, the corresponding objects will not be processed at all. Notice that it is important for string literals in this expression to be quoted in the correct XPath manner -- that is, with single quotes.

    Defaults to 'true()'.
    showCallback (Object data) Function

    A function to be called each time a balloon is displayed, if MapLayers.XSLTObjectLayer.config.balloonConfig is supplied.

    Arguments
    • data (Object) - The data, evaluated from the XML, that pertain to the current map object. This includes by default the following properties (which may be overridden), but will also contain any extra data specified with the MapLayers.XSLTObjectLayer.config.extraData configuration property. Note: XSLTObjectLayer does not work in IE9 unless the following header is added to the HTML file: <meta http-equiv="X-UA-Compatible" content-"IE=8">

      Properties
      NameTypeDescription
      idString

      The string ID of the marker, which will correspond to its DOM ID unless overridden by additional data instructions.

      locLatLon

      The latitude-longitude coordinates of the marker, as used to clip it to the viewport.

      posPoint

      The x-y coordinates of the marker on the map. These are specified relative to the map-layer container div.

      srcString

      The image src attribute of the marker image, as read from the XML. This is the 'raw' source rather than the final one, since it is the result of MapLayers.XSLTObjectLayer.config.imgSrcFunc called with this data object that generates the actual value.

    sizeSize

    The pixel dimensions with which to display each image on the layer.

    Defaults to MapLayers.XSLTObjectLayer.DEFAULT_SIZE.
    srcString

    A string path to an XML file to load the layer from. If not supplied, a call to MapLayers.XSLTObjectLayer.loadXMLFromFile can be made after construction.

    Defaults to null.
    xmlXMLDoc

    An XML object to load the layer from. If not supplied, a call to MapLayers.XSLTObjectLayer.LoadXML can be made after construction.

    Defaults to null.
Functions
NameDescription
destroy ()

Disposes of any resources used by the MapLayers.XSLTObjectLayer. Call this if the layer is no longer needed and you want to quickly reclaim resources.

getLocation (String test)

Gets the latitude-longitude location of one of the objects being managed by the MapLayers.XSLTObjectLayer, described by an XPath expression.

Arguments
  • test (String) - An XPath expression that should evaluate to true if the context node is the desired marker in the layer's XML document. If this is true for multiple markers, the location of the first of these is returned.

Returns

LatLon - The location of the described object.

isLoaded ()

Finds whether the MapLayers.XSLTObjectLayer has been completely loaded in the current map viewport.

Returns

Boolean - True if all cells of markers have been loaded; false otherwise.

loadXML (String xml)

Loads the XML describing the objects in the layer from a string.

Arguments
  • xml (String or Object or XMLDoc) - A string containing the XML describing the objects, or the XML object itself.

loadXMLFromFile (String src, Function callback)

Loads the XML describing the objects in the layer from a file.

Arguments
  • src (String) - The URI of the XML file to load from.

  • callback (Function) - An optional callback to be executed once the XML has been loaded and parsed.

reconfigure (Object config, Boolean stealthy)

Changes specified configuration options for the MapLayers.XSLTObjectLayer. The MapLayers.XSLTObjectLayer.config.src and MapLayers.XSLTObjectLayer.config.xml options have no effect here -- to change the layer's XML, call MapLayers.XSLTObjectLayer.loadXML or MapLayers.XSLTObjectLayer.loadXMLFromFile instead.

Arguments
  • config (Object) - The new configuration to apply to the MapLayers.XSLTObjectLayer. Options not specified here will retain their previous settings.

  • stealthy (Boolean) - If true, prevents the layer from being updated after its reconfiguration.

removeObjects (String targetXML, Function matchFunc)

Removes all the objects contained in a specified XML document from the MapLayers.XSLTObjectLayer.

Arguments
  • targetXML (String or Object or XMLDoc) - An XML string, document or wrapper object identifying the objects to remove from the layer.

  • (Optional) matchFunc (Function) - A function describing how to evaluate whether a node in the layer's internal XML document matches one in the supplied XML. Defaults to function (node) {return "@id='" + node.getAttribute ("id") + "'";}.

    Arguments
    • node (XMLDoc) - The XML node from the layer's main document to describe a match for.

    Returns

    String - An XPath expression (for which the context node is the currently selected marker in the supplied XML) that should evaluate to true if the node passed as a parameter refers to the same marker as the context node, and false otherwise. It is important that any string literals in this expression be quoted in the correct XPath manner, i.e. using single-quotes.

removeObjectsFromFile (String src, Function matchFunc)

Removes the specified objects from the MapLayers.XSLTObjectLayer in the same manner as MapLayers.XSLTObjectLayer.removeObjects, except using an XML document fetched from a supplied URL.

Arguments
  • src (String) - The URL to request an XML document describing the objects to remove.

  • (Optional) matchFunc (Function) - A function describing how to evaluate whether a node in the layer's internal XML document matches one in the supplied XML. Defaults to function (node) {return "@id='" + node.getAttribute ("id") + "'";}.

    Arguments
    • node (XMLDoc) - The XML node from the layer's main document to describe a match for.

    Returns

    String - An XPath expression (for which the context node is the currently selected marker in the supplied XML) that should evaluate to true if the node passed as a parameter refers to the same marker as the context node, and false otherwise. It is important that any string literals in this expression be quoted in the correct XPath manner, i.e. using single-quotes.

updateXML (String partialXML, Function matchFunc)

Parses an XML document describing only some of the markers to be displayed on the MapLayers.XSLTObjectLayer, and for each marker described in this partial document, replaces its matching marker in the main layer's main XML by it if such a marker exists, or appends it to the root node of the main XML otherwise. Note that since the marker elements are managed by ID, and ID defaults to a combination of latitude and longitude, it may be necessary to specify an 'id' property of the MapLayers.XSLTObjectLayer.config.extraData so that nodes are recognized as the same even if their location is adjusted.

Arguments
  • partialXML (String or Object or XMLDoc) - An XML string, document, or wrapper object describing (only) the markers to be updated.

  • (Optional) matchFunc (Function) - A function describing how to evaluate whether a node in the layer's internal XML document matches one in the supplied XML. Defaults to function (node) {return "@id='" + node.getAttribute ("id") + "'";}.

    Arguments
    • node (XMLDoc) - The XML node from the layer's main document to describe a match for.

    Returns

    String - An XPath expression (for which the context node is the currently selected marker in the supplied XML) that should evaluate to true if the node passed as a parameter refers to the same marker as the context node, and false otherwise. It is important that any string literals in this expression be quoted in the correct XPath manner, i.e. using single-quotes.

updateXMLFromFile (String src, Function matchFunc)

Performs a partial update of the MapLayers.XSLTObjectLayer's markers, in the same manner as MapLayers.XSLTObjectLayer.updateXML, except with a partial XML document fetched from a supplied URL.

Arguments
  • src (String) - The URL to request an XML document describing a partial update from. Some browsers may cache the contents of the XML document, if it is a static page (i.e. a non-changing URL) and refuse to re-request the file from the server until its expiry time. Which means that if the file is changed, another call to this function may not result in the new file being loaded. This problem may arise if you call this function every second or so to update the positions of objects on the map from a static url to a file which you may modify occasionally, because the old file from the cache is used instead. In order to avoid this, apply a query string to the end of the URL like this: http://.../something.xml?t=1 or a timestamp of sorts, to force the browser to re-request the file from the server.

  • (Optional) matchFunc (Function) - A function describing how to evaluate whether a node in the layer's internal XML document matches one in the supplied XML. Defaults to function (node) {return "@id='" + node.getAttribute ("id") + "'";}.

    Arguments
    • node (XMLDoc) - The XML node from the layer's main document to describe a match for.

    Returns

    String - An XPath expression (for which the context node is the currently selected marker in the supplied XML) that should evaluate to true if the node passed as a parameter refers to the same marker as the context node, and false otherwise. It is important that any string literals in this expression be quoted in the correct XPath manner, i.e. using single-quotes.

Properties
NameTypeDescription
DEFAULT_SIZESize

The default width and height, in pixels, to use for markers on MapLayers.XSLTObjectLayers.

LoadEventHandler

An event handler triggered when all of the objects in the current viewport have been displayed on the map.