Android MapBox使用之自定义Marker(三)

前面两篇讲的是自定义MarkerView,而MarkerView已经被MapBox废弃了,本篇给出一个Marker的例子。

自定义CustomMarker:

public class CustomMarker extends Marker{
    Icon iconBig;
    /**
     * Creates a instance of {@link Marker} using the builder of Marker.
     *
     * @param baseMarkerOptions The builder used to construct the Marker.
     */
    public CustomMarker(BaseMarkerOptions baseMarkerOptions) {
        super(baseMarkerOptions);
    }

    public Icon getIconBig() {
        return iconBig;
    }

    public void setIconBig(Icon iconBig) {
        this.iconBig = iconBig;
    }
}

 自定义CustomMarkerOptions:

public class CustomMarkerOptions extends BaseMarkerOptions<CustomMarker,CustomMarkerOptions> implements Parcelable {

    public static final Creator<CustomMarkerOptions> CREATOR = new Creator<CustomMarkerOptions>() {
        public CustomMarkerOptions createFromParcel(Parcel in) {
            return new CustomMarkerOptions(in);
        }

        public CustomMarkerOptions[] newArray(int size) {
            return new CustomMarkerOptions[size];
        }
    };

    public CustomMarkerOptions() {
    }

    protected CustomMarkerOptions(Parcel in) {
        this.position((LatLng)in.readParcelable(LatLng.class.getClassLoader()));
        this.snippet(in.readString());
        this.title(in.readString());
        if(in.readByte() != 0) {
            String iconId = in.readString();
            Bitmap iconBitmap = (Bitmap)in.readParcelable(Bitmap.class.getClassLoader());
            Icon icon = IconFactory.recreate(iconId, iconBitmap);
            this.icon(icon);
        }

    }

    public CustomMarkerOptions getThis() {
        return this;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel out, int flags) {
        out.writeParcelable(this.getPosition(), flags);
        out.writeString(this.getSnippet());
        out.writeString(this.getTitle());
        Icon icon = this.getIcon();
        out.writeByte((byte)(icon != null?1:0));
        if(icon != null) {
            out.writeString(this.getIcon().getId());
            out.writeParcelable(this.getIcon().getBitmap(), flags);
        }

    }

    public CustomMarker getMarker() {
        if(this.position == null) {
            throw new InvalidMarkerPositionException();
        } else {
            return new CustomMarker(this);
        }
    }

    public LatLng getPosition() {
        return this.position;
    }

    public String getSnippet() {
        return this.snippet;
    }

    public String getTitle() {
        return this.title;
    }

    public Icon getIcon() {
        return this.icon;
    }

    public boolean equals(Object o) {
        if(this == o) {
            return true;
        } else if(o != null && this.getClass() == o.getClass()) {
            CustomMarkerOptions marker;
            label59: {
                marker = (CustomMarkerOptions)o;
                if(this.getPosition() != null) {
                    if(this.getPosition().equals(marker.getPosition())) {
                        break label59;
                    }
                } else if(marker.getPosition() == null) {
                    break label59;
                }

                return false;
            }

            label52: {
                if(this.getSnippet() != null) {
                    if(this.getSnippet().equals(marker.getSnippet())) {
                        break label52;
                    }
                } else if(marker.getSnippet() == null) {
                    break label52;
                }

                return false;
            }

            if(this.getIcon() != null) {
                if(!this.getIcon().equals(marker.getIcon())) {
                    return false;
                }
            } else if(marker.getIcon() != null) {
                return false;
            }

            boolean var10000;
            label77: {
                if(this.getTitle() != null) {
                    if(this.getTitle().equals(marker.getTitle())) {
                        break label77;
                    }
                } else if(marker.getTitle() == null) {
                    break label77;
                }

                var10000 = false;
                return var10000;
            }

            var10000 = true;
            return var10000;
        } else {
            return false;
        }
    }

    public int hashCode() {
        int result = 1;
        result = 31 * result + (this.getPosition() != null?this.getPosition().hashCode():0);
        result = 31 * result + (this.getSnippet() != null?this.getSnippet().hashCode():0);
        result = 31 * result + (this.getIcon() != null?this.getIcon().hashCode():0);
        result = 31 * result + (this.getTitle() != null?this.getTitle().hashCode():0);
        return result;
    }
}

自定义CustomMarker使用:

CustomMarkerOptions markerOptions = new CustomMarkerOptions();
markerOptions
      .icon(icon)
      .position(latlng);
CustomMarker customMarker = (CustomMarker) mAMap.addMarker(markerOptions);

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值