如何在 osmdroid 中扩展 ResourceProxy 接口?

How to extends ResourceProxy interface in osmdroid?

是的,我知道,另一个关于在 osmdroid 中更改图标的线程。 但是没有任何好的解释可用!

我做了很多研究,这是一个frequently asked topic。为什么不在这一点上对所有需要指定自己资源的用户做出明确的回答?

所有可用的东西都是“Have a look at ResourceProxy.java”或"Pass the bitmap to constructor"。没办法,它对我不起作用,我什至不知道一个简单的界面如何在我的 res 文件夹中找到我的可绘制对象!我尝试传递一些与 osmdroid 同名的 .PNG 文件(例如 "person.png"),但是当我 运行 应用程序时,我仍然拥有默认资源。

有人可以清楚地解释如何逐步编写“our own ResourceProxy”吗? Not brievely like that because I followed the steps and didn't manage to success.

我知道 osmdroid was fixed recently 在 github 中,但 .aar 比修复程序旧。在这里您可以找到 Resource Proxy class.

当您在 MapView 实例中创建时,您需要传入对 "ResourceProxy" 实现的引用。默认情况下,它加载 "DefaultResourceProxyImpl"。要覆盖,请创建一个扩展 DefaultResourceProxyImpl 的新 class,然后您可以覆盖 getBitmap 和 getDrawable。实际上这里有一个覆盖 DefaultResourceProxyImpl 的示例:

https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/ResourceProxyImpl.java

为了您,我正在努力将这样的示例包含在 osmdroid 示例应用程序中。它看起来像这样

 public class CustomResourceProxy extends DefaultResourceProxyImpl {

      private final Context mContext;
      public CustomResourceProxy(Context pContext) {
           super(pContext);
        mContext = pContext;
      }

      @Override
    public Bitmap getBitmap(final bitmap pResId) {
        switch (pResId){
                case person:
                     //your image goes here!!!
                     return BitmapFactory.decodeResource(mContext.getResources(),org.osmdroid.example.R.drawable.sfgpuci);

           }
           return super.getBitmap(pResId);
    }

    @Override
    public Drawable getDrawable(final bitmap pResId) {
        switch (pResId){
                case person:
                     //your image goes here!!!
                     return mContext.getResources().getDrawable(org.osmdroid.example.R.drawable.sfgpuci);
           }
           return super.getDrawable(pResId);
    }

 }

编辑:完成 参见 https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/CustomResourceProxy.java

编辑:编辑: Wiki 已更新,请参阅 https://github.com/osmdroid/osmdroid/wiki/How-to-use-the-osmdroid-library