Click or drag to resize

Telogis.GeoBase.MapLayers.CircleFence

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

MapLayers.CircleFence inherits from MapLayers.GeoFence.

A circular form of geofence, as described by a coordinate-pair center point and a distance radius in some fixed units.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});
Constructor
NameDescription
MapLayers.CircleFence(config)

Arguments

  • config (Object) - Configuration options for the circular GeoFence.

    Properties
    NameTypeDescription
    centerLatLon

    The latitude-longitude coordinates of the center of the GeoFence region.

    Defaults to null. This property may also be referenced by the name: centre.
    radiusNumber

    The radius of the geofence region about MapLayers.CircleFence.config.center. This is given in the units specified by the MapLayers.CircleFence.config.units configuration option, which defaults to miles.

    Defaults to 0.
    unitsString

    The string abbreviation of the unit to take radius measurements of the GeoFence in. This should be a DistanceUnit code.

    Defaults to DistanceUnit.MILES.
Functions
NameDescription
contains (LatLon loc)

Determines whether a given point lies within the fence boundaries.

JavaScript
// Set the location we will use for the center of the fence
var fenceCenter = new Telogis.GeoBase.LatLon(33.575131,-117.778007)
map.setCenter(fenceCenter);
var balloonText;

// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: fenceCenter,
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

// Create test locations
var inside = new Telogis.GeoBase.LatLon(33.573818,-117.775948);
var outside = new Telogis.GeoBase.LatLon(33.579922,-117.785417);

// Test the 'outside' location against the circle fence
if (myCircleFence.contains(outside)) {
    balloonText = 'I am within the fence';
} else {
    balloonText = 'I am outside the fence';
}

// Put a pin on the map to make visualization easier
var pinBob = new Telogis.GeoBase.MapLayers.ImageObject({
    map: map,
    balloonConfig: {content: balloonText},
    location: outside,
    src: 'images/pin-red.png'
});
Arguments
  • loc (LatLon) - The latitude-longitude coordinates of the point to test for.

Returns

Boolean - True if MapLayers.CircleFence.contains.loc lies within the fence; false otherwise.

getCenter ()

Finds the coordinates of the center of the fence.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

alert('Center of the CircleFence is '+myCircleFence.getCenter());
// Center of the CircleFence is (33.575131, -117.778007)
Returns

LatLon - The location of the MapLayers.CircleFence's center.

getDistance ()

Finds the distance from the center of the circular fence to its edge.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

alert('Radius of this CircleFence is '+
    myCircleFence.getDistance() +' '+myCircleFence.getUnits());
    // Radius of this CircleFence is 0.5 mi
Returns

Number - The radius of the MapLayers.CircleFence. The units of this can be found with a call to MapLayers.CircleFence.getUnits.

getUnits ()

Finds the string abbreviation of the units that the circular fence is being measured in, which will be a DistanceUnit code.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a kilometer
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.KILOMETERS,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

alert('Units used for this CircleFence is '+myCircleFence.getUnits());
// Units used for this CircleFence is km
Returns

String - The appropriate DistanceUnit.

setCenter (LatLon loc)

Sets the center of the MapLayers.CircleFence to a certain latitude-longitude location.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

document.onclick = myTestFunction;
function myTestFunction() {
    myCircleFence.setCenter(new Telogis.GeoBase.LatLon(33.566795,-117.769035));
};
Arguments
  • loc (LatLon) - The location to center the fence at.

setRadius (Number distance, String units)

Sets the radius of the MapLayers.CircleFence in given units.

JavaScript
// Create a CircleFence in Los Angeles with a radius of half a mile
myCircleFence = new Telogis.GeoBase.MapLayers.CircleFence({
    id: 'circle_fence',
    parent: map,
    center: new Telogis.GeoBase.LatLon(33.575131,-117.778007),
    radius: 0.5,
    units: Telogis.GeoBase.DistanceUnit.MILES,
    fillColor: new Telogis.GeoBase.Color(0,18,255,0.2),
    lineColor: new Telogis.GeoBase.Color(0,18,255,0.9),
    lineWidth: 1,
    show: true
});

document.onclick = myTestFunction;
function myTestFunction() {
    // Change radius of the circle fence from 0.5 miles to 5 kilometers
    myCircleFence.setRadius(5,Telogis.GeoBase.DistanceUnit.KILOMETERS);
};
Arguments
  • distance (Number) - The distance, in the given units, from the center of the MapLayers.CircleFence to its edge.

  • (Optional) units (String) - The string abbreviation of the units to take MapLayers.CircleFence.setRadius.distance in, which should be a DistanceUnit code. Defaults to DistanceUnit.MILES.