📄 ezflashfilergis.pas
字号:
{ TEzFlashFilerLayer - class implementation }
{------------------------------------------------------------------------------}
constructor TEzFlashFilerLayer.Create(Layers: TEzBaseLayers; const AFileName: string);
begin
inherited Create(Layers, AFileName);
// Don't connect to a database table here because spatial data is contained in
// the entity table (Use of '' as FileName)
FDBTable := TEzFlashFilerDataset.Create(Layers.Gis, '', True, True);
TEzFlashFilerDataset(FDBTable).FLayer := Self;
FLayerInfo := TEzFlashFilerLayerInfo.Create(Self);
// In this case FileName = Name because it is a table on the FlashFiler Server
FileName := AFileName;
Name := AFileName;
CoordMultiplier := 1;
FMWSparseList:= TMWSparseList.Create(512);
FModifiedList:= TMWSparseList.Create(512);
end;
destructor TEzFlashFilerLayer.Destroy;
begin
Close;
if FFlashFilerHeader <> nil then FreeAndNil(FFlashFilerHeader);
if FFlashFilerEntities <> nil then FreeAndNil(FFlashFilerEntities);
if FOl <> nil then FreeAndNil(FOl);
if FCachedRT <> nil then FreeAndNil(FCachedRT);
FDBTable.Free;
FMWSparseList.Free;
FModifiedList.Free;
inherited Destroy;
end;
procedure TEzFlashFilerLayer.InvalidateRecord(Index: Integer);
begin
If Not IsClientBuffered Then Exit;
{ invalidating a record will cause the entity to re-read from the server }
If FMWSparseList.HasData(Index-1) Then
begin
FMWSparseList.LocalRecno[Index-1]:= 0;
//FMWSparseList.DataExists[Index-1]:= False;
end;
end;
{Function TEzFlashFilerLayer.GetLocalDataExists( ServerRecno: Integer ): Boolean;
begin
Result:= False;
If Not TEzFlashFilerGIS(Layers.GIS).FClientBuffered Then Exit;
Result:= FMWSparseList.DataExists[ServerRecno-1];
end;
Procedure TEzFlashFilerLayer.SetLocalDataExists( ServerRecno: Integer; Value: Boolean );
begin
If Not TEzFlashFilerGIS(Layers.GIS).FClientBuffered Then Exit;
FMWSparseList.DataExists[ServerRecno-1]:= Value;
end; }
Function TEzFlashFilerLayer.GetLocalRecno( ServerRecno: Integer ): Integer;
begin
Result:= 0;
If Not IsClientBuffered Then Exit;
Result:= FMWSparseList.LocalRecno[ServerRecno-1];
end;
Procedure TEzFlashFilerLayer.SetLocalRecno( ServerRecno, Value: Integer );
begin
If Not IsClientBuffered Then Exit;
FMWSparseList.LocalRecno[ServerRecno-1]:= Value;
end;
Function TEzFlashFilerLayer.LocalLayer: TEzBaseLayer;
Begin
Result:= Nil;
If Not IsClientBuffered Then Exit;
Result:= TEzFlashFilerGIS(Layers.GIS).FBufferGIS.Layers.LayerByName( Self.Name );
End;
Procedure TEzFlashFilerLayer.TransportImage(AEntity: TEzEntity);
{$IFDEF FALSE}
var
Stream, FileStream: TStream;
FullName,FileName: string;
{$ENDIF}
Begin
{$IFDEF FALSE}
If (AEntity=Nil) Or Not (AEntity.EntityID in [idPictureRef, idBandsBitmap]) Or
(TEzFlayerFilerGIS(Layers.GIS).FTransportImages = tiNone) Then Exit;
case AEntity.EntityID of
idPictureRef:
FileName:= TEzPictureRef(AEntity).FileName;
idBandsBitmap:
FileName:= TEzBandsBitmap(AEntity).FileName;
end;
FullName:= AddSlash(Ez_Preferences.CommonSubdir) + Filename;
If (TEzFlayerFilerGIS(Layers.GIS).FTransportImages = tiNonExistingOnly) And
FileExists(FullName) Then Exit;
with GetTCPClient do
Begin
WriteLn('GLB_GETIMAGE');
WriteLn(FileName);
{ read the image }
Stream:= TMemoryStream.Create;
try
ReadStream(Stream,-1,False);
{$IFDEF TRANSPORT_COMPRESSED}
Stream.Position:= 0;
DeCompressmemStream(TMemoryStream(Stream));
{$ENDIF}
Stream.Position:= 0;
FileStream:= TFileStream.Create(FullName, fmCreate);
try
FileStream.CopyFrom( Stream, Stream.Size );
finally
FileStream.Free;
end;
Finally
Stream.Free;
end;
end;
{$ENDIF}
End;
procedure TEzFlashFilerLayer.InitializeOnCreate(const FileName: string;
AttachedDB, IsAnimation: Boolean;
CoordSystem: TEzCoordSystem;
CoordsUnits: TEzCoordsUnits;
FieldList: TStrings);
begin
// Nothing to do here
Modified := True; // Does no harm
end;
function TEzFlashFilerLayer.IsClientServer: Boolean;
begin
Result := True;
end;
procedure TEzFlashFilerLayer.StartBatchInsert;
begin
if FBatchUpdate = True then Exit;
FBatchUpdate := True;
// Start a transaction!?
end;
procedure TEzFlashFilerLayer.CancelBatchInsert;
begin
if FBatchUpdate = False then Exit;
FBatchUpdate := False;
RebuildTree;
UpdateMapExtension(QuickUpdateExtension);
// Rollback Transaction!?
end;
procedure TEzFlashFilerLayer.FinishBatchInsert;
begin
if FBatchUpdate = False then Exit;
FBatchUpdate := False;
// Commit transaction!?
RebuildTree;
UpdateMapExtension(QuickUpdateExtension);
end;
function TEzFlashFilerLayer.DefineScope(const Scope: string): Boolean;
var
Solver: TEzMainExpr;
begin
If Not FClientHasAllData Then
Begin
Result := False;
CancelFilter;
Solver := TEzMainExpr.Create(Layers.Gis, Self);
try
// Ol must be created after this because a call to one of the
// queryxxx expression could cause Ol to be set to nil
Solver.ParseExpression(Scope);
if Solver.Expression.ExprType <> ttBoolean then
raise EExpression.Create(SExprFail);
FOl := TIntegerList.Create;
First;
while not Eof do
begin
try
if RecIsDeleted then Continue;
if not Solver.Expression.AsBoolean then Continue;
FOl.Add(RecNo);
finally
Next;
end;
end;
FFiltered := True;
if FOl.Count > 0 then
begin
FFilterRecNo := -1;
// Is a sorting defined ?
if Solver.OrderByCount > 0 then
begin
FFiltered := False;
SortOrderList(Self, Solver, FOl);
FFiltered := True;
end;
end
else
begin
FFiltered := False;
FreeAndNil(FOl);
end;
Result := (FOl <> nil) and (FOl.Count > 0);
finally
Solver.Free;
end;
end else
Result:=LocalLayer.DefineScope( Scope );
end;
function TEzFlashFilerLayer.GetBookmark: Pointer;
var
I: Integer;
Bm: TFlashFilerBookmark;
begin
If Not FClientHasAllData Then
Begin
Bm := TFlashFilerBookmark.Create;
Bm.FRecno := GetRecNo;
Bm.FFiltered := FFiltered;
Bm.FFilterRecNo := FFilterRecNo;
if (FOl <> nil) and (FOl.Count > 0) then
begin
Bm.FOl.Capacity := FOl.Count;
for I := 0 to FOl.Count-1 do
Bm.FOl.Add(FOl[I]);
end;
Result := Bm;
end else
Result:= LocalLayer.GetBookmark;
end;
procedure TEzFlashFilerLayer.GotoBookmark(Bookmark: Pointer);
var
I: Integer;
Bm: TFlashFilerBookmark;
begin
If Not FClientHasAllData Then
Begin
Bm := TFlashFilerBookmark(Bookmark);
SetRecNo(Bm.FRecno);
FFiltered := Bm.FFiltered;
FFilterRecNo := Bm.FFilterRecNo;
if Bm.FOl.Count > 0 then
begin
if FOl = nil then FOl := TIntegerList.Create;
FOl.Clear;
FOl.Capacity := Bm.FOl.Count;
for I := 0 to Bm.FOl.Count-1 do
FOl.Add(Bm.FOl[I]);
end else if FOl <> nil then
FOl.Clear;
end else
LocalLayer.GotoBookmark( Bookmark );
end;
procedure TEzFlashFilerLayer.FreeBookmark(Bookmark: Pointer);
begin
If Not FClientHasAllData Then
TFlashFilerBookmark(Bookmark).Free
Else
LocalLayer.FreeBookmark( Bookmark );
end;
function TEzFlashFilerLayer.DefinePolygonScope(Polygon: TEzEntity;
const Scope: string; Operator: TEzGraphicOperator): Boolean;
var
Solver: TEzMainExpr;
Entity: TEzEntity;
Pass: Boolean;
SearchType: TSearchType;
Temp_Ol: TIntegerList;
begin
If Not FClientHasAllData Then
Begin
Result := False;
CancelFilter;
Temp_Ol := TIntegerList.Create;
Solver := nil;
if Length(Scope) > 0 then
begin
Solver := TEzMainExpr.Create(Layers.Gis, Self);
end;
try
if Solver <> nil then
begin
Solver.ParseExpression(Scope);
if Solver.Expression.ExprType <> ttBoolean then
raise EExpression.Create(SExprFail);
end;
case Operator of
goWithin, goContains, goIntersects:
SearchType := stOverlap;
goEntirelyWithin, goContainsEntire:
SearchType := stEnclosure;
else
SearchType := stOverlap;
end;
SetGraphicFilter(SearchType, Polygon.FBox);
First;
while not Eof do
begin
try
if RecIsDeleted then Continue;
Entity := RecLoadEntity;
if Entity = nil then Continue;
try
Pass := Entity.CompareAgainst(Polygon, Operator);
finally
Entity.Free;
end;
if Pass then
begin
if Solver <> nil then
begin
if not Solver.Expression.AsBoolean then Continue;
end;
Temp_Ol.Add(RecNo);
end;
finally
Next;
end;
end;
CancelFilter;
FFiltered := True;
if Temp_Ol.Count > 0 then
begin
FFilterRecNo := -1;
FOl := Temp_Ol;
Result := True;
// Is a sorting defined ?
if (Solver <> nil) and (Solver.OrderByCount > 0) then
begin
FFiltered := False;
SortOrderList(Self, Solver, FOl);
FFiltered := True;
end;
end
else
begin
FFiltered := False;
FreeAndNil(Temp_Ol);
end;
finally
if Solver <> nil then
Solver.Free;
end;
End Else
Result:= LocalLayer.DefinePolygonScope(Polygon, Scope, Operator);
end;
procedure TEzFlashFilerLayer.Zap;
begin
// Nothing to do here for the server
If FClientHasAllData Then
Begin
LocalLayer.Zap;
FMWSparseList.Clear;
End;
end;
procedure TEzFlashFilerLayer.GetFieldList(Strings: TStrings);
var
I: Integer;
begin
If Not FClientHasAllData Then
Begin
with GetDBTable do
for I := 1 to FieldCount do
Strings.Add(Format('%S;%S;%d;%d', [Field(I), FieldType(I),
FieldLen(I), FieldDec(I)]));
End Else
LocalLayer.GetFieldList( Strings );
end;
function TEzFlashFilerLayer.GetDBTable: TEzBaseTable;
begin
If Not FClientHasAllData Then
Result := FDBTable
else
Result := LocalLayer.DBTable;
end;
function TEzFlashFilerLayer.GetRecNo: Integer;
begin
If Not FClientHasAllData Then
begin
Result := FFlashFilerEntities.FieldByName('UID').AsInteger;
End Else
Result:= LocalLayer.Recno;
end;
procedure TEzFlashFilerLayer.SetRecNo(Value: Integer);
begin
If Not FClientHasAllData Then
begin
//if GetRecNo = Value then Exit;
If AnsiCompareText(FFlashFilerEntities.IndexName, 'ixPrimary') <> 0 then
FFlashFilerEntities.IndexName := 'ixPrimary'; // primary Index
if not FFlashFilerEntities.FindKey([Value]) then
EzGisError('Record not found!');
End Else
LocalLayer.Recno:= Value;
end;
function TEzFlashFilerLayer.IsCachedSpatialIndex: Boolean;
begin
Result:= (Layers.GIS is TEzFlashFilerGis) And TEzFlashFilerGis(Layers.Gis).FCachedSpatialIndex;
end;
procedure TEzFlashFilerLayer.SetGraphicFilter(S: TSearchType; const VisualWindow: TEzRect);
var
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -