Click or drag to resize

Telogis.GeoBase.Canvas.Util

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

Contains useful functions for manipulating the array of pixel points prior to rendering.

Functions
NameDescription
clipPath (Array poly, Point ul, Point lr, Boolean closed)

Clips a polygon to a rectangular viewport by the Sutherland-Hodgeman algorithm, edge-by-edge. If the Canvas.Util.clipPath.closed is set to false (i.e. the path being clipped is a polyline), the resulting path may contain some line segments along the edges of the viewport. To remove these and produce a set of properly clipped polylines, a call to Canvas.Util.splitPath should be made. Note that since this clipping operation is performed in-place, the result is saved in the array passed as a parameter.

Arguments
  • poly (Array) - The array of Points defining the polygon to clip to the viewport. This is modified by the call to give the result.

  • ul (Point) - The upper-left corner of the viewport to clip to.

  • lr (Point) - The lower-right corner of the viewport to clip to.

  • (Optional) closed (Boolean) - Whether the polygon to clip is closed (i.e. not a polyline). Defaults to true.

pathsEqual (Array path1, Array path2, Number tolerance)

Determines whether two lists of points have per-element equivalence and hence represent equivalent paths. Note that repeated points qualify a path as being distinct.

Arguments
  • path1 (Array) - The first array of Points to compare.

  • path2 (Array) - The second array of Points to compare.

  • (Optional) tolerance (Number) - The maximum error pixel distance in the x- and y- directions to allow between each corresponding point in the paths while still deeming them equivalent. Defaults to 0.

Returns

Boolean - True if Canvas.Util.pathsEqual.path1 and Canvas.Util.pathsEqual.path2 are equivalent within Canvas.Util.pathsEqual.tolerance pixels; false otherwise.

polysEqual (Array poly1, Array poly2, Number tolerance)

Determines whether the two polygons described by a pair of arrays are equivalent. This is essentially the same as Canvas.Util.pathsEqual, except that one of the arguments may be a cyclic shift of the other. Note that repeated points qualify a polygon as being distinct.

Arguments
  • poly1 (Array) - The first array of Points to compare.

  • poly2 (Array) - The second array of Points to compare.

  • (Optional) tolerance (Number) - The maximum error pixel distance in the x- and y- directions to allow between each corresponding point in the polygons while still deeming them equivalent. Defaults to 0.

Returns

Boolean - True if Canvas.Util.polysEqual.poly1 and Canvas.Util.polysEqual.poly2 are equivalent within Canvas.Util.polysEqual.tolerance pixels; false otherwise.

reducePath (Array points, Number factor, Number threshold)

A dynamic simplification method that produces accurate simplifications for a reduce factor above a certain threshold, or fast simplifications first and accurate simplifications next for a reduce factor below this threshold. The simplification is performed in-place, so the result will be saved in the array passed as a parameter (although a reference to it is returned for convenience).

Arguments
  • points (Array) - A Point array of pixel coordinates to reduce. This will be modified by the function call to contain the reduced points.

  • factor (Number) - The degree to which the polyline should be simplified. This will be the approximate proportion of points to preserve.

  • (Optional) threshold (Number) - If factor is below this threshold, a fast simplification step will be enabled before the accurate simplification step. Defaults to 0.5.

Returns

Array - A reference to the reduced array of polyline points.

removeRepeatedPoints (Array path, Boolean closed, Number tolerance)

Removes repeated points from a sequence of Points, for minor drawing-time optimization. This operation is performed in-place, so that the result will be saved in the array passed as a parameter (although a reference to it is returned, for convenience).

Arguments
  • path (Array) - The array of Points to remove repeated entries from. This is modified in the function call.

  • (Optional) closed (Boolean) - If this is set to true, the path will be treated cyclically and repeated points across the start/end will be removed. Defaults to false.

  • (Optional) tolerance (Number) - The pixel difference in the x- and y- directions to allow between two points considered equivalent. Defaults to 0.

Returns

Array - A reference to the modified Canvas.Util.removeRepeatedPoints.path, with repeated entries removed appropriately.

split (Array path, Point ul, Point lr)

Given a long polyline with segments that may lie on the edges of the viewport, this function removes these segments to give an array of smaller polylines. This is useful for discarding redundant sections of a polyline clipped with Canvas.Util.clipPath.

Arguments
  • path (Array) - The list of Points from which to remove trivial segments on the edges of the viewport.

  • ul (Point) - The pixel coordinates of the upper-left corner of the viewport to split polylines in, relative to the same origin as the points in Canvas.Util.splitPath.path.

  • lr (Point) - The pixel coordinates of the lower-right corner of the viewport to split polylines in, relative to the same origin as the points in Canvas.Util.splitPath.path.

Returns

Array - An array of lists of Points, each describing a distinct polyline inside the viewport area.