Q&A - Question

How to show only selected shape area on TGIS_ViewerWnd?

Question
Bahodir asked on December 10, 2019, keyword: Developer Kernel
I need to show the area of specific shape, outside of this shape should be blank including other layers. It is like cutting, but cutting specific area of TGIS_ViewerWnd component (that is what client is demanding and hopefully, it will optimize the viewing time).
Answers
LukK replied November 07, 2019
I don't know if there is any ready solution but You can hide unwanted shapes and then zoom to the selected area.
I'm using code like this:
  GIS.Lock;
  ext := TGIS_Utils.GisNoWorld;
  try
    for i := 0 to GIS.Items.Count - 1 do
    begin
      if not (GIS.Items.Items[i] is TGIS_LayerVector) then
        Continue;
      ll := TGIS_LayerVector(GIS.Items.Items[i]);
      if Assigned(ll) then
      begin
        shp := ll.FindFirst;
        while Assigned(shp) do
        begin
          shp := shp.MakeEditable;
          if shp.IsSelected = True then
          begin
            shp.IsHidden := False;
            ext := TGIS_Utils.GisMaxExtent(ext, shp.Extent);
          end 
          else
            shp.IsHidden := True;
          shp := ll.FindNext;
        end;
      end;
    end;
    GIS.VisibleExtent := ext;
  finally
    GIS.Unlock;
    GIS.InvalidateWholeMap;
  end;
Tomasz Kosinski (TatukGIS) replied November 07, 2019
Nothing ourt of the box. But you can try this:
  1. create a new temporary TGIS_LayerVector layer
  2. attach PainlLayerEvent and draw rectanles around your area like this:
procedure TfrmMain.doPaint(_sender: TObject;
  _layer: TGIS_Layer);
var
  rndr    : TGIS_RendererAbstract
  shprect : TRect ;
begin
  _layer.Draw ;

  if not Assigned( myShape  ) then exit ;

  shprect := GIS.MapToScreenRect(
              GisCommonExtent(
                GIS.VisibleExtent,
                myShape.ProjectedExtent
              )
            ) ;

  rndr := TGIS_RendererAbstract( _layer.Renderer )

  rndr.CanvasPen.Style := TGIS_PenStyle.Clear ;

  // even a transparent mask!
  rdr.CanvasBrush.Color
    := TGIS_Color.FromARGB( 200, 255, 255, 255 );

  // 1000 to make a wide margin
  rndr.CanvasDrawRectangle(
     Rect( -1000, -1000, shprect.Left, GIS.Height + 1000 )
  ) ;

  // and so on
end;
Bahodir replied December 10, 2019
I forgot to mention I work on C++ builder. Pascal language is a bit complicated for me. Can anyone show it for C++ builder?
Tomasz Kosinski (TatukGIS) replied December 10, 2019
You can try this: https://github.com/aababilov/pas2cpp

Generally conversion is quite simple:

Delphi:
rdr.CanvasBrush.Color := TGIS_Color.FromARGB( 200, 255, 255, 255 );
C++:
rdr->CanvasBrush->Color = TGIS_Color::FromARGB( 200, 255, 255, 255 );
If you would like to answer the question please Sign In.
*
*
Please review our recent Privacy Policy.
If you have any questions or requests, please contact us.
Rules
The Questions and Answers (Q & A) is intended to provide a means of communication between TatukGIS customers.
 
  1. Licensed users (with active maintenance play) of TatukGIS products may contribute to the Q & A content. Read-only access is available to anyone.
  2. Keep the content positive and professional.
  3. Be courteous to others by posting information when a question or issue asked on the Q & A is answered or resolved by other means (such as with help from TatukGIS technical support). Offer others at least a hint how the posted question was answered or the issue was resolved.
  4. The Q & A is not a replacement for TatukGIS technical support. TatukGIS team may or may not regularly follow or contribute content.