【问题标题】:How add title on polygon in osmbonuspack如何在 osmbonuspack 中的多边形上添加标题
【发布时间】:2015-07-17 18:16:38
【问题描述】:

如何在 osmbonuspack 的 Polygon 上添加 Marker.title(不在 InfoWindow 中)之类的标题?

private void showGeoJsonObjects(String str){
    KmlDocument kmlDocument = new KmlDocument();
    kmlDocument.parseGeoJSON(str);
    KmlFeature.Styler styler = new MyKmlStyler();
    FolderOverlay kmlOverlay = (FolderOverlay) kmlDocument.mKmlRoot.buildOverlay(mMapView, null, styler, kmlDocument);

    mMapView.getOverlays().add(kmlOverlay);
    mMapView.invalidate();
}


class MyKmlStyler implements KmlFeature.Styler {
    @Override
    public void onFeature(Overlay overlay, KmlFeature kmlFeature) {}

    @Override
    public void onPoint(Marker marker, KmlPlacemark kmlPlacemark, KmlPoint kmlPoint) {}

    @Override
    public void onLineString(Polyline polyline, KmlPlacemark kmlPlacemark, KmlLineString kmlLineString) {}

    @Override
    public void onPolygon(Polygon polygon, KmlPlacemark kmlPlacemark, KmlPolygon kmlPolygon) {
        try {
            String styleString = kmlPlacemark.getExtendedData("style");
            JSONObject o = new JSONObject(styleString);
            if(o.getBoolean("stroke")) {
                String colorHash = "#"+Integer.toHexString((int)(o.getDouble("opacity")*255))+o.getString("color").replace("#","");
                polygon.setStrokeColor(Color.parseColor(colorHash));
                polygon.setStrokeWidth((float) o.getDouble("weight"));
            }
            if(o.getBoolean("fill")){
                String colorHash = "#"+Integer.toHexString((int)(o.getDouble("fillOpacity")*255))+o.getString("color").replace("#","");
                polygon.setFillColor(Color.parseColor(colorHash));
            }
            //Would be great if this method helped me add title
            polygon.setTitle("Tadadada!!!");
        }catch (Exception e){}

    }
}

//Probably I should override Polygon, something like this 
class TitledPolygon extends Polygon {
    public TitledPolygon(Context ctx) {
        super(ctx);
    }

    public TitledPolygon(ResourceProxy resourceProxy) {
        super(resourceProxy);
    }

    @Override
    protected void draw(Canvas canvas, MapView mapView, boolean shadow) {
        super.draw(canvas, mapView, shadow);
        if(mTitle!=null && mTitle.length()>0){
            Paint textPaint = new Paint();
            textPaint.setColor( Color.RED);
            textPaint.setTextSize(40f);
            textPaint.setAntiAlias(true);
            textPaint.setTextAlign(Paint.Align.LEFT);
            Point p = new Point(100,100);
            canvas.drawText(mTitle, p.x, p.y + 20, textPaint);
        }
    }
}

我需要做很多额外的工作。覆盖另一个使用 Polygon 的类,以调用 TitledPolygon。 可能会找到多边形的最大高度,以在多边形上方添加标题。 也许这是更简单的解决方案?

【问题讨论】:

  • 至少向我们展示您的试验......

标签: openstreetmap osmdroid


【解决方案1】:

我找到了更简单的方法。我添加了额外的 Overlay,并在 onPolygon 中将 OverlayItems 添加到 Overlay。

【讨论】:

  • 你能举个例子吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 2018-06-17
相关资源
最近更新 更多