Dela via


TestDataGenerator Class

Note

Bing Maps Web Control SDK retirement

Bing Maps Web Control SDK is deprecated and will be retired. Free (Basic) account customers can continue to use Bing Maps Web Control SDK until June 30th, 2025. Enterprise account customers can continue to use Bing Maps Web Control SDK until June 30th, 2028. To avoid service disruptions, all implementations using Bing Maps Web Control SDK will need to be updated to use Azure Maps Web SDK by the retirement date that applies to your Bing Maps for Enterprise account type. For detailed migration guidance, see Migrate from Bing Maps Web Control SDK and Migrate Bing Maps Enterprise applications to Azure Maps with GitHub Copilot.

Azure Maps is Microsoft's next-generation maps and geospatial services for developers. Azure Maps has many of the same features as Bing Maps for Enterprise, and more. To get started with Azure Maps, create a free Azure subscription and an Azure Maps account. For more information about azure Maps, see Azure Maps Documentation. For migration guidance, see Bing Maps Migration Overview.

Often when creating a demo or trying to test a new application you need to create some test/mock data. Generating a random Location object isn’t particularly difficult, but what if you want to create a random Polygon that actually looks like a polygon, and maybe has a hole as well?

This can be difficult to achieve and require a fair amount of code. In some cases, the code needed to generate random shape data can end up being longer than the code you are trying to test. To help with testing scenarios, the Bing Maps V8 control features a test data generator. This test data generator consists of a set of static methods which are exposed through the Microsoft.Maps.TestDataGenerator namespace.

Static Methods

Definition Return Value Description
getColor(withAlpha?: boolean) string Generates a random hex color string. If the withAlpha value is to true, a RGBA value will be returned with an alpha value of 0.5.
getLocations(num?: number, bounds?: LocationRect) Location or Location[] Generates random Location objects.
num: The number of locations to generate. If set to one a single Location will be returned. If greater than one and array will be returned.
bounds: The bounding box in which all the locations should fall within.
getPushpins(num?: number, bounds?: LocationRect, options?: IPushpinOptions) Pushpin or Pushpin[] Generates random pushpins.
num: The number of pushpins to generate. If set to one a single Pushpin will be returned. If greater than one and array will be returned.
bounds: The bounding box in which all the pushpins should fall within.
options: The options to use for rendering the pushpins. Default is random.
getPolylines(num?: number, bounds?: LocationRect, size?: number, scaleFactor?: number, options?: IPolylineOptions) Polyline or Polyline[] Generates random polylines.
num: The number of polylines to generate. If set to one a single Polyline will be returned. If greater than one and array will be returned.
bounds: The bounding box in which all the locations of the polylines should fall within.
size: The number of locations each polylines should have. Default: random between 3 and 10.
scaleFactor: A number that scales the size of the polylines based on size of the bounding box. A value of 0.1 would generate polylines that are no larger than 10% of the width/height of the map. Default: 0.1
options: The options to use for rendering the polylines. Default is random.
getPolygons(num?: number, bounds?: LocationRect, size?: number, scaleFactor?: number, options?: IPolygonOptions, addHole?:boolean) Polygon or Polygon[] Generates random simple polygons.
num: The number of polygons to generate. If set to one a single Polygon will be returned. If greater than one and array will be returned.
bounds: The bounding box in which all the locations of the polygon should fall within.
size: The number of locations each polygon should have. Default: random between 3 and 10.
scaleFactor: A number that scales the size of the polygons based on the size of the bounding box. A value of 0.1 would generate polygons that are no larger than 10% of the width/height of the map. Default: 0.1
options: The options to use for rendering the polygons. Default is random.
addHole: A boolean indicating if the generated polygon should have a hole or not. Note that this will double the number of Location objects that are in the Polygon. Default: false

See Also