ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Slippy map opaque layer
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

bmesser

United Kingdom
221 Posts

Posted - Aug 13 2019 :  11:50:03  Show Profile  Reply
Hi

Does anyone know if it's possible to create an opaque over layer when using TIESlippyMaps?

I would like to create a multi-point coloured polygon area for a county or region and still partially see the map beneath.

I may well have asked this question before but can't be sure what the answer was!

Bruce.

xequte

38128 Posts

Posted - Aug 13 2019 :  16:42:03  Show Profile  Reply
Hi Bruce

You can use layers:

ImageEnView1.LayersAdd( iesPinLeft, 100, 100, 120, 120 );
ImageEnView1.CurrentLayer.Opacity := 0.4;

But because slippy maps are virtually drawn, you need to concern yourself with moving them when the user scrolls.

So I think you are better to draw it yourself, as the pins are drawn in the OnDrawBackBuffer event of the \InputOutput\GeoMaps\ demo.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

bmesser

United Kingdom
221 Posts

Posted - Aug 13 2019 :  17:24:38  Show Profile  Reply
Thanks for your speedy reply Nigel I'll try it out tomorrow and let you know.
Go to Top of Page

bmesser

United Kingdom
221 Posts

Posted - Aug 15 2019 :  14:58:54  Show Profile  Reply
Hi Nigel

I tried as you suggested drawing a filled polygon on a transparent layer using this code:

Image.LayersAdd;
Image.Layers[1].Opacity:=0.5;

procedure TfmMain.ImageDrawBackBuffer(Sender: TObject);
var
  pts : TPointArray;
  i   : integer;
begin
  SetLength(pts,length(Warnings[0].Coordinates));

  for i:=0 to length(Warnings[0].Coordinates)-1 do
  begin
    pts[i].X:=map.LongitudeToBmpX(Warnings[0].Coordinates[i].Lon);
    pts[i].Y:=map.LatitudeToBmpY(Warnings[0].Coordinates[i].Lat);
  end;
  
  with Image.Layers[1].Bitmap.Canvas do
  begin
    Pen.Color:=clBlack;
    Brush.Style:=bsSolid;
    Brush.Color:=clYellow;
    Polygon(pts);
  end;
end;  

That worked but as I drag the map with the mouse the polygon gets repeatedly redrawn:



Somewhere I need to clear the bitmap but how?

Bruce
Go to Top of Page

xequte

38128 Posts

Posted - Aug 15 2019 :  21:55:32  Show Profile  Reply
Hi Bruce

Sorry, i should have steered you more directly to the drawing option.

Please take a look at: \InputOutput\GeoMaps\

It uses RenderToTBitmapEx, which has Transparency as a parameter. You can set it to 128 to draw at 50% transparency.

I would do something like:

1. Generate your pts list using LongitudeToBmpX/LatitudeToBmpY
2. find the min and max x and y in your array
3. Create bitmap of size maxX - minX, maxY - minY
4. Make offsetX := minX and offsetY := minY
5. Subtract offsetX and offsetY from all points
6. Draw a polygon to the TIEBitmap.IECanvas
7. Render the polygon at offsetX, offsetY using RenderToTBitmapEx

Of course, you could skip steps 2-5 and just use an image of the size of the client (and decide whether the performance is acceptable).

You might also consider caching the bitmaps too for performance.

For tips on using a TIECanvas, see the polygon example at:

https://www.imageen.com/help/TIECanvas.html



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

bmesser

United Kingdom
221 Posts

Posted - Aug 16 2019 :  05:25:05  Show Profile  Reply
Hi Nigel

For a moment I thought that I would have to email you back saying I still couldn't clear the canvas when I dragged the map.

Then I found the ImageDrawLayers method and the penny dropped. It's perfectly fast enough for what I do but opens up a new way of doing things to me!

procedure ImageDrawLayer(Sender: TObject; Dest: TIEBitmap; LayerIndex: Integer);
var
  pts : TPointArray;
  i   : integer;
begin
  if LayerIndex=1 then
  begin
    SetLength(pts,length(Warnings[0].Coordinates));

    for i:=0 to length(Warnings[0].Coordinates)-1 do
    begin
      pts[i].X:=map.LongitudeToBmpX(Warnings[0].Coordinates[i].Lon);
      pts[i].Y:=map.LatitudeToBmpY(Warnings[0].Coordinates[i].Lat);
    end;

    with Dest.IECanvas do
    begin
      Pen.Mode := pmCopy;
      Pen.Width :=2;
      Pen.Style := psSolid;
      Pen.Color := clBlack;
      Pen.Transparency := 192;

      Brush.Color := clYellow;
      Brush.Style := bsSolid;
      Brush.Transparency := 128;
      Polygon(pts);
    end;
  end;
end;




Thanks again - the mapping that comes as an extra with the ImageEn component library is an absolute godsend to me.

Bruce.
Go to Top of Page

xequte

38128 Posts

Posted - Aug 16 2019 :  16:52:09  Show Profile  Reply
Nice work

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: