做调查报告的网站,广东省建设安全卡查询网站,wordpress 加密功能,优质校建设网站MapBox Android版开发 6 关于Logo Logo的显示查看源码及思路#xff08;Logo#xff09;第一步第二步 隐藏Logo示例查看源码及思路#xff08;Info#xff09;第一步第二步 隐藏Logo和Info示例 看到有网友留言问如何移除Logo#xff0c;今天看了下V9源码#xff0c;发现M… MapBox Android版开发 6 关于Logo Logo的显示查看源码及思路Logo第一步第二步 隐藏Logo示例查看源码及思路Info第一步第二步 隐藏Logo和Info示例 看到有网友留言问如何移除Logo今天看了下V9源码发现MapBox 提供了禁用Logo的功能。 
先简单说下思路部分源码最后是示例。 
Logo的显示 
MapBox通过MapView展示地图和地图上的要素地图上的要素也是MapView的一部分。要隐藏其中一个元素最先要考虑要素渲染的方式。 
通过Android控件叠在地图上。借助覆盖物接口渲染。在底层与地图一起渲染。 
三种可能的显示方式对应隐藏的难易程度也不通隐藏方式也不同。 
查看源码及思路Logo 
第一步 
接下来要确认MapBox是如何显示Logo的。先看MapView的源码。 
步骤1在MapView中可以很快找到方法MapView.initialiseLogoViewLogo是通过ImageView显示在地图上的。 
protected ImageView initialiseLogoView() {ImageView logoView  new ImageView(this.getContext());addView(logoView);logoView.setTag(logoView);logoView.getLayoutParams().width  LayoutParams.WRAP_CONTENT;logoView.getLayoutParams().height  LayoutParams.WRAP_CONTENT;logoView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_logo_icon));return logoView;
}步骤2查看MapView.initialiseLogoView 调用在UiSettings.initialiseLogo方法中创建了Logo视图。 
private void initialiseLogo(MapboxMapOptions options, NonNull Resources resources) {isLogoInitialized  true;logoView  mapView.initialiseLogoView();setLogoEnabled(options.getLogoEnabled());setLogoGravity(options.getLogoGravity());setLogoMargins(resources, options.getLogoMargins());
}步骤3UiSettings与Logo相关的属性和接口这其中就包含隐藏Logo的方法UiSettings.setLogoEnabled。 
ImageView logoView;
boolean isLogoInitialized  false;private void initialiseLogo(MapboxMapOptions options, NonNull Resources resources);
private void setLogoMargins(NonNull Resources resources, Nullable int[] logoMargins);
private void saveLogo(Bundle outState);
private void restoreLogo(Bundle savedInstanceState);
// Enables or disables the Mapbox logo.
public void setLogoEnabled(boolean enabled);
public boolean isLogoEnabled();
public void setLogoGravity(int gravity);
public int getLogoGravity();
public void setLogoMargins(Px int left, Px int top, Px int right, Px int bottom);
public int getLogoMarginLeft();
public int getLogoMarginTop();
public int getLogoMarginRight();
public int getLogoMarginBottom();第二步 
接下来的问题是如何获取UiSettings对象MapboxMap提供了方法。 
UiSettings与MapboxMap部分类图 #mermaid-svg-fuluYI3MiquOe26z {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-fuluYI3MiquOe26z .error-icon{fill:#552222;}#mermaid-svg-fuluYI3MiquOe26z .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-fuluYI3MiquOe26z .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-fuluYI3MiquOe26z .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-fuluYI3MiquOe26z .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-fuluYI3MiquOe26z .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-fuluYI3MiquOe26z .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-fuluYI3MiquOe26z .marker{fill:#333333;stroke:#333333;}#mermaid-svg-fuluYI3MiquOe26z .marker.cross{stroke:#333333;}#mermaid-svg-fuluYI3MiquOe26z svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-fuluYI3MiquOe26z g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-fuluYI3MiquOe26z g.classGroup text .title{font-weight:bolder;}#mermaid-svg-fuluYI3MiquOe26z .nodeLabel,#mermaid-svg-fuluYI3MiquOe26z .edgeLabel{color:#131300;}#mermaid-svg-fuluYI3MiquOe26z .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-fuluYI3MiquOe26z .label text{fill:#131300;}#mermaid-svg-fuluYI3MiquOe26z .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-fuluYI3MiquOe26z .classTitle{font-weight:bolder;}#mermaid-svg-fuluYI3MiquOe26z .node rect,#mermaid-svg-fuluYI3MiquOe26z .node circle,#mermaid-svg-fuluYI3MiquOe26z .node ellipse,#mermaid-svg-fuluYI3MiquOe26z .node polygon,#mermaid-svg-fuluYI3MiquOe26z .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-fuluYI3MiquOe26z .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-fuluYI3MiquOe26z g.clickable{cursor:pointer;}#mermaid-svg-fuluYI3MiquOe26z g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-fuluYI3MiquOe26z g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-fuluYI3MiquOe26z .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-fuluYI3MiquOe26z .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-fuluYI3MiquOe26z .dashed-line{stroke-dasharray:3;}#mermaid-svg-fuluYI3MiquOe26z #compositionStart,#mermaid-svg-fuluYI3MiquOe26z .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #compositionEnd,#mermaid-svg-fuluYI3MiquOe26z .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #dependencyStart,#mermaid-svg-fuluYI3MiquOe26z .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #dependencyStart,#mermaid-svg-fuluYI3MiquOe26z .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #extensionStart,#mermaid-svg-fuluYI3MiquOe26z .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #extensionEnd,#mermaid-svg-fuluYI3MiquOe26z .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #aggregationStart,#mermaid-svg-fuluYI3MiquOe26z .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z #aggregationEnd,#mermaid-svg-fuluYI3MiquOe26z .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-fuluYI3MiquOe26z .edgeTerminals{font-size:11px;}#mermaid-svg-fuluYI3MiquOe26z :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}                                                                       UiSettings     void setLogoEnabled(boolean enabled)                 MapboxMap     -UiSettings uiSettings     UiSettings getUiSettings()         隐藏Logo示例 
在地图初始化成功后通过MapboxMap的UiSettings对象隐藏Logo。 
mapView.getMapAsync(new OnMapReadyCallback() {Overridepublic void onMapReady(NonNull MapboxMap mapboxMap) {// 隐藏Logo mapboxMap.getUiSettings().setLogoEnabled(false);mapStyle  new MapStyle(mapboxMap);mapStyle.changeStyle(Style.MAPBOX_STREETS);}
});运行效果图如下。 
运行后发现在原本Logo的右侧还有一个 ⓘ参考隐藏Logo的思路接下来通过源码找隐藏 Info 的方法。 查看源码及思路Info 
第一步 
步骤1在MapView初始化Logo代码中Logo资源为R.drawable.mapbox_logo_icon接下来找info对应的资源。 
protected ImageView initialiseLogoView() {ImageView logoView  new ImageView(this.getContext());addView(logoView);logoView.setTag(logoView);logoView.getLayoutParams().width  LayoutParams.WRAP_CONTENT;logoView.getLayoutParams().height  LayoutParams.WRAP_CONTENT;logoView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_logo_icon));return logoView;
}步骤2MapBox中drawable不多能很快找到logo和info的资源。 
mapbox_logo_icon.png
mapbox_info_icon_default.png
mapbox_info_icon_selected.png
mapbox_info_bg_selector步骤3MapView.initialiseAttributionView使用了info资源。 
protected ImageView initialiseAttributionView() {ImageView attrView  new ImageView(this.getContext());addView(attrView);attrView.setTag(attrView);attrView.getLayoutParams().width  LayoutParams.WRAP_CONTENT;attrView.getLayoutParams().height  LayoutParams.WRAP_CONTENT;attrView.setAdjustViewBounds(true);attrView.setClickable(true);attrView.setFocusable(true);attrView.setContentDescription(getResources().getString(R.string.mapbox_attributionsIconContentDescription));attrView.setImageDrawable(BitmapUtils.getDrawableFromRes(getContext(), R.drawable.mapbox_info_bg_selector));// inject widgets with MapboxMapattrView.setOnClickListener(attributionClickListener  new AttributionClickListener(getContext(), mapboxMap));return attrView;
}步骤4查看MapView.initialiseAttributionView 调用在UiSettings.initialiseAttribution方法中创建了Info视图。 
private void initialiseAttribution(NonNull Context context, MapboxMapOptions options) {isAttributionInitialized  true;attributionsView  mapView.initialiseAttributionView();setAttributionEnabled(options.getAttributionEnabled());setAttributionGravity(options.getAttributionGravity());setAttributionMargins(context, options.getAttributionMargins());int attributionTintColor  options.getAttributionTintColor();setAttributionTintColor(attributionTintColor ! -1? attributionTintColor : ColorUtils.getPrimaryColor(context));
}步骤3UiSettings与Attribution相关的属性和接口这其中就包含隐藏Info的方法UiSettings.setAttributionEnabled。 
ImageView attributionsView;
private final int[] attributionsMargins  new int[4];
private AttributionDialogManager attributionDialogManager;
boolean isAttributionInitialized  false;private void initialiseAttribution(NonNull Context context, MapboxMapOptions options);
private void setAttributionMargins(NonNull Context context, Nullable int[] attributionMargins);
private void saveAttribution(Bundle outState);
private void restoreAttribution(Bundle savedInstanceState);
// Enables or disables the attribution.
public void setAttributionEnabled(boolean enabled);
public boolean isAttributionEnabled();
public void setAttributionDialogManager(NonNull AttributionDialogManager attributionDialogManager);
public AttributionDialogManager getAttributionDialogManager();
public void setAttributionGravity(int gravity);
public int getAttributionGravity();
public void setAttributionMargins(Px int left, Px int top, Px int right, Px int bottom);
public void setAttributionTintColor(ColorInt int tintColor);
public int getAttributionMarginLeft();
public int getAttributionMarginTop();
public int getAttributionMarginBottom();第二步 
UiSettings与MapboxMap部分类图 #mermaid-svg-vyykc7na8u8fYadB {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-vyykc7na8u8fYadB .error-icon{fill:#552222;}#mermaid-svg-vyykc7na8u8fYadB .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-vyykc7na8u8fYadB .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-vyykc7na8u8fYadB .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-vyykc7na8u8fYadB .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-vyykc7na8u8fYadB .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-vyykc7na8u8fYadB .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-vyykc7na8u8fYadB .marker{fill:#333333;stroke:#333333;}#mermaid-svg-vyykc7na8u8fYadB .marker.cross{stroke:#333333;}#mermaid-svg-vyykc7na8u8fYadB svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-vyykc7na8u8fYadB g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-vyykc7na8u8fYadB g.classGroup text .title{font-weight:bolder;}#mermaid-svg-vyykc7na8u8fYadB .nodeLabel,#mermaid-svg-vyykc7na8u8fYadB .edgeLabel{color:#131300;}#mermaid-svg-vyykc7na8u8fYadB .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-vyykc7na8u8fYadB .label text{fill:#131300;}#mermaid-svg-vyykc7na8u8fYadB .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-vyykc7na8u8fYadB .classTitle{font-weight:bolder;}#mermaid-svg-vyykc7na8u8fYadB .node rect,#mermaid-svg-vyykc7na8u8fYadB .node circle,#mermaid-svg-vyykc7na8u8fYadB .node ellipse,#mermaid-svg-vyykc7na8u8fYadB .node polygon,#mermaid-svg-vyykc7na8u8fYadB .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-vyykc7na8u8fYadB .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-vyykc7na8u8fYadB g.clickable{cursor:pointer;}#mermaid-svg-vyykc7na8u8fYadB g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-vyykc7na8u8fYadB g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-vyykc7na8u8fYadB .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-vyykc7na8u8fYadB .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-vyykc7na8u8fYadB .dashed-line{stroke-dasharray:3;}#mermaid-svg-vyykc7na8u8fYadB #compositionStart,#mermaid-svg-vyykc7na8u8fYadB .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #compositionEnd,#mermaid-svg-vyykc7na8u8fYadB .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #dependencyStart,#mermaid-svg-vyykc7na8u8fYadB .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #dependencyStart,#mermaid-svg-vyykc7na8u8fYadB .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #extensionStart,#mermaid-svg-vyykc7na8u8fYadB .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #extensionEnd,#mermaid-svg-vyykc7na8u8fYadB .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #aggregationStart,#mermaid-svg-vyykc7na8u8fYadB .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB #aggregationEnd,#mermaid-svg-vyykc7na8u8fYadB .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-vyykc7na8u8fYadB .edgeTerminals{font-size:11px;}#mermaid-svg-vyykc7na8u8fYadB :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}                                                                       UiSettings     void setLogoEnabled(boolean enabled)     void setAttributionEnabled(boolean enabled)                 MapboxMap     -UiSettings uiSettings     UiSettings getUiSettings()         隐藏Logo和Info示例 
在地图初始化成功后通过MapboxMap的UiSettings对象隐藏Logo和Info。 
mapView.getMapAsync(new OnMapReadyCallback() {Overridepublic void onMapReady(NonNull MapboxMap mapboxMap) {// 隐藏Logo和InfomapboxMap.getUiSettings().setLogoEnabled(false);mapboxMap.getUiSettings().setAttributionEnabled(false);mapStyle  new MapStyle(mapboxMap);mapStyle.changeStyle(Style.MAPBOX_STREETS);}
});运行效果图