简体   繁体   English

如何在Delphi 10 for Android中更改Marker(TMapMarkerDescriptor)的图标?

[英]How to change icon for a Marker (TMapMarkerDescriptor) in Delphi 10 for Android?

Please can anyone explain me how to Change the Marker Icon in Delphi for a android App? 请任何人解释我如何更改Delphi中的标记图标为Android应用程序?

My try don't work 我的尝试不起作用

s.Create(16, 16); //Image size
position.Latitude := mapview1.Location.Latitude;
position.Longitude := mapview1.Location.Longitude;
MyMarker := TMapMarkerDescriptor.Create(Position, 'MyMarker');
MyMarker.Draggable := True;
Mymarker.Icon := imagelist1.Bitmap(s,0);
MyMarker.Visible :=True;
Fmarkers.Add(MapView1.AddMarker(MyMarker));

Imagelist is a Timagelist on the form. Imagelist是表单上的Timagelist。 added with a 16x16 image. 添加了16x16图像。

If i run my app, no marker is shown. 如果我运行我的应用程序,则不会显示任何标记。 do i comment // the line with the icon then all works fine but i have no custom marker icon. 我评论//带有图标的行然后一切正常,但我没有自定义标记图标。

i want a set of 4 different marker icons. 我想要一套4个不同的标记图标。

TSizeF.Create returns an instance of the record, which you must save into your variable s . TSizeF.Create返回记录的实例,您必须将其保存到变量s This should work (presuming you have a 16x16 bitmap at index 0 in your ImageList): 这应该工作(假设你在ImageList中的索引0处有一个16x16位图):

s := TSizeF.Create(16, 16);            //Image size
position.Latitude := mapview1.Location.Latitude;
position.Longitude := mapview1.Location.Longitude;
MyMarker := TMapMarkerDescriptor.Create(Position, 'MyMarker');
MyMarker.Draggable := True;
Mymarker.Icon := imagelist1.Bitmap(s, 0);
MyMarker.Visible :=True;
Fmarkers.Add(MapView1.AddMarker(MyMarker));

You should also be able to just skip the creation into a different variable and use it directly from the constructor [untested] - TSizeF is a record, and therefore doesn't need to be destroyed: 您还应该能够将创建跳过另一个变量并直接从构造函数[未测试]使用它 - TSizeF是一个记录,因此不需要销毁:

MyMarker.Icon := ImageList1.Bitmap(TSizeF.Create(16, 16), 0);

Well i have been looking answer for the same thing now for long time and the only way i could change it was loading my png image to TImage component on Designer and then assign Bitmap from that. 好吧,我一直在寻找同样的事情,现在很长一段时间,我可以改变它的唯一方法是将我的png图像加载到Designer上的TImage组件,然后从中分配Bitmap Like this: 像这样:

MyMarker.Icon := Image1.Bitmap;

Also the size of the picture doesn't matter 此外,图片的大小无关紧要

Update: 更新:
I found a way to put custom icon from imagelist 我找到了一种从图像列表中放置自定义图标的方法

s.Create(16, 16); //Image size
position.Latitude := mapview1.Location.Latitude;
position.Longitude := mapview1.Location.Longitude;
MyMarker := TMapMarkerDescriptor.Create(Position, 'MyMarker');
MyMarker.Draggable := True;
MyMarker.Icon := ImageList1.Source.Items[0].MultiResBitmap.Items[0].Bitmap;
MyMarker.Visible :=True;
Fmarkers.Add(MapView1.AddMarker(MyMarker));   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM