FormatLoadFromFile(SourceFormat: TopobaseFormat, FileName: String);
SourceFormat. Topobase format.
FileName. Path and name of topobase file.
The FormatLoadFromFile method loads the topobase from a file.
Executing the example requires that the repository contains:
A map with the MAP identifier containing the Regions layer.
Four topobase files on the C disk: Topobase.tbs, Topobase.svg, Topobase.google, Topobase.triangulate.
A form containing:
The Button component named Button1.
The UiMap component named UiMap1 that is a data source for MapBox1.
The MapBox component named MapBox1. Select the UiMap1 data source for the component in the Source property.
The IntegerEdit component named IntegerEdit1. Set value of the format, from which a topobase wil be loaded, in the Value property for the component. Use the value of the TopobaseFormat enumeration as a topobase format value.
Add links to the Drawing, Map, MathFin, Metabase, and Topobase system assemblies.
Var
Count: Integer;
// Get information about dynamic indicators
// in different temporary points on map layer
Class VisualDataAdapter: Object, IMapTimeDynamicDataAdapter
Function Get_PartCount(Attribute: Variant; TimePoint: Integer): Integer;
Begin
Return Count;
End Function Get_PartCount;
Function Get_TimePointName(TimePoint: Integer): String;
Begin
Return "TimePoint " + TimePoint.ToString;
End Function Get_TimePointName;
Function Get_TimePointsCount: Integer;
Begin
Return 4;
End Function Get_TimePointsCount;
Function Get_Data(Attribute: Variant; PartvIndex: Integer; TimePoint: Integer): Variant;
Var
t: Integer;
i: Integer;
Begin
t := 1;
For i := 0 To TimePoint Do
t := t + 10;
End For;
Return Math.Rand * 10 * t;
End Function Get_Data;
Function Get_CustomFormat: String;
Begin
Return "#0,000";
End Function Get_CustomFormat;
End Class VisualDataAdapter;
Class ITOPOBASE_FORMATLOADFROMFILEForm: Form
Button1: Button;
UiMap1: UiMap;
MapBox1: MapBox;
IntegerEdit1: IntegerEdit;
mb: IMetabase;
Map: IMap;
Top: IMapTopobase;
Itop: ITopobase;
Sub CreateLayer(CurrentMap: IMap);
Var
StartC, EndC: IGxColor;
Color: IMapVisualColorProperty;
Scale: IMapColorScale;
AreaVisual: IMapAreaVisual;
Layer: IMapLayer;
Begin
// Get map layer named Regions
Layer := CurrentMap.Layers.FindByName("Regions");
// Set map background color
CurrentMap.Color := New GxColor.CreateARGB(100, 100, 100, 100);
// Refresh map
CurrentMap.Refresh;
// Get map indicator
AreaVisual := Layer.Visuals.AddAreaVisual;
// Create a data source for indicator
AreaVisual.DataAdapter := New VisualDataAdapter.Create As IMapTimeDynamicDataAdapter;
Count := 5;
// Get indicator fill parameters
Color := AreaVisual.Color;
// Determine a data source for fill
Color.DataAdapter := AreaVisual.DataAdapter;
// Create a color scale
Scale := New DxMapColorScale.Create As IMapColorScale;
// Set start gradient color
StartC := GxColor.FromName("Red");
// Set end gradient color
EndC := GxColor.FromName("Blue");
// Set up color scale
Scale.AutoSetup(Layer, AreaVisual.DataAdapter, StartC, EndC);
// Set color scale for indicator fill
Color.Scale := Scale;
// Refresh map
CurrentMap.Refresh;
End Sub CreateLayer;
Sub ITOPOBASE_FORMATLOADFROMFILEFormOnCreate(Sender: Object; Args: IEventArgs);
Begin
// Get repository
mb := MetabaseClass.Active;
// Get map
Map := UiMap1.Map;
// Get map topobase
Top := mb.FetchItemById("OBJ14878_COPY2").Edit As IMapTopobase;
// Save topobase
Itop := Top As ITopobase;
// Set topobase
Map.Topobase := Itop As IMapTopobase;
// Display map
CreateLayer(Map);
End Sub ITOPOBASE_FORMATLOADFROMFILEFormOnCreate;
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
TopoName: String;
Begin
TopoName := "";
// Upload topobase from the file C:\Topobase.<file extension>
If IntegerEdit1.Value = TopobaseFormat.Tbs Then
TopoName := "tbs";
End If;
If IntegerEdit1.Value = TopobaseFormat.Svg Then
TopoName := "svg";
End If;
If IntegerEdit1.Value = TopobaseFormat.Google Then
TopoName := "google";
End If;
If IntegerEdit1.Value = TopobaseFormat.Triangulate Then
TopoName := "triangulate";
End If;
Itop.FormatLoadFromFile((IntegerEdit1.Value) As TopobaseFormat, "C:\Topobase." + TopoName);
// Save changes
(Itop As IMetabaseObject).Save;
// Set new topobase
Map.Topobase := Itop As IMapTopobase;
// Display map
CreateLayer(Map)
End Sub Button1OnClick;
End Class ITOPOBASE_FORMATLOADFROMFILEForm;
After executing the example the topobase with the specified format will be loaded from the file to the form on clicking the Button1 button.
See also: