简体   繁体   English

如何使用 OSMDROID/OSMBonusPack 更改标记气泡

[英]How to change the marker bubble using OSMDROID/OSMBonusPack

teI'm trying to replace google map in my application by OSM map.我正在尝试用 OSM 地图替换我的应用程序中的谷歌地图。 I've been trying to use this by following their how to install and imported the project using Jitpack.我一直在尝试使用这种按照自己如何安装和使用进口的Jitpack项目。 It works fine.它工作正常。 On tap of marker default info bubbles(some light gray colored ones) are shown.点击标记默认信息气泡(一些浅灰色的)显示。 What should I do if I want to modify the background of the marker bubble?I'm not using any kind of onClick method in my code如果我想修改标记气泡的背景,我该怎么做? 我的代码中没有使用任何类型的 onClick 方法

 import android.app.Fragment;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import org.osmdroid.api.IMapController;
import org.osmdroid.tileprovider.tilesource.TileSourceFactory;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.ScaleBarOverlay;
import java.util.ArrayList;
import java.util.List;
import demo.exe.exe.R;
import demo.exe.exe.model.Education.EducationServiceProviderItem;
import demo.exe.exe.utils.AppConstants;


public class MapFragmentOSM extends Fragment implements View.OnClickListener {

    private ArrayList<EducationServiceProviderItem> educationServiceProvider=null;
MapView mapView;
    int subcategotyId;
    View rootView;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        double latDouble,longDouble;
        int i=0;
        super.onCreate(savedInstanceState);
        rootView = inflater.inflate(R.layout.fragment_map, container,
                false);

        mapView = (MapView) rootView.findViewById(R.id.mapview);
        mapView.setClickable(true);
        mapView.setBuiltInZoomControls(true);
        mapView.setMultiTouchControls(true);
        mapView.setUseDataConnection(true);

;
        mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);

        IMapController mapViewController = mapView.getController();



        if(locationNameId==1) {

            mapViewController.setZoom(18);
            mapViewController.setCenter(AppConstants.BAUNIA1);
        }
        else if(locationNameId==2)
        {
            mapViewController.setZoom(17);
            mapViewController.setCenter(AppConstants.PARIS1);
        }
        switch (categoryId)
        {
            case AppConstants.EDUCATION:
                if(educationServiceProvider!=null) {
                    for (EducationServiceProviderItem et : educationServiceProvider) {
                    //    LatLng location = new LatLng(Double.parseDouble(et.getLatitude()), Double.parseDouble(et.getLongitude()));
                        subcategotyId = et.getEduSubCategoryId();
                        latDouble=Double.parseDouble(et.getLatitude());
                        longDouble=Double.parseDouble(et.getLongitude());
                      GeoPoint point=  new GeoPoint(latDouble,longDouble);
                        drawMarkerEdu(point, et.getEduNameEng(),et.getAddress(), et.getEduSubCategoryId());
                    }
                }
                break;


            default:
                break;

        }

        //Add Scale Bar
        ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(mapView);
        mapView.getOverlays().add(myScaleBarOverlay);


        return rootView;
    }
    private void drawMarkerEdu(GeoPoint point,String title,String address,int subcategotyId) {
        Marker marker = new Marker(mapView);
        marker.setPosition(point);
        marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);


        if (subcategotyId >= 1 && subcategotyId <= 12)
            marker.setIcon(this.getResources().getDrawable(R.drawable.pin_feroza));
        else if (subcategotyId >= 13 && subcategotyId <= 17)
            marker.setIcon(this.getResources().getDrawable(R.drawable.pin_blue));
        else if (subcategotyId >= 18 && subcategotyId <= 19)
            marker.setIcon(this.getResources().getDrawable(R.drawable.pin_pink));
        else if (subcategotyId >= 20 && subcategotyId <= 21)
            marker.setIcon(this.getResources().getDrawable(R.drawable.pin_green));
        else if (subcategotyId >= 22 && subcategotyId <= 26)
            marker.setIcon(this.getResources().getDrawable(R.drawable.pin_yellow));
        marker.setSnippet(title);
        marker.setSubDescription(address);
        mapView.getOverlays().add(marker);


    }
    @Override
    public void onClick(View v) {

    }
}

Any suggestion will be highly appreciated!任何建议将不胜感激!

This tutorial shows exactly what you want. 本教程准确显示了您想要的内容。 Basically you override the InfoWindow class and give it your own layout.基本上,您可以覆盖 InfoWindow 类并为其提供您自己的布局。

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

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