【Android】ImageMap,图片地图
16lz
2021-01-23
https://github.com/CFutureTeam/android-image-map
package com.*.imagemap;import *.imagemap.ImageMap;import *.imagemap.core.Bubble;import *.imagemap.core.CircleShape;import *.imagemap.core.Shape;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.Color;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.TextView;public class MainActivity extends Activity { private ImageMap map; // lib库里面自定义试图对象 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); map = (ImageMap) findViewById(R.id.imagemap); // 用资源文件创建一个bitmap,地图 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.imm_01, new BitmapFactory.Options()); // 把图加载到ImageMap上面去 map.setMapBitmap(bitmap); // 加载一个用来标注位置的视图view,这个view自己可以定义的 View bubble = getLayoutInflater().inflate(R.layout.popup, null); // 把试图加进ImageMap map.setBubbleView(bubble, new Bubble.RenderDelegate() { @Override public void onDisplay(Shape shape, View bubbleView) { ImageView logo = (ImageView) bubbleView.findViewById(R.id.logo); // // 通过bubbleView得到相应的控件 TextView name = (TextView) bubbleView.findViewById(R.id.name); name.setText("我的位置"); // 标注上面显示一个文本 logo.setImageResource(R.drawable.kfc_logo); // 图片 } }); // 该方法可以实现一个圆点,用于和bubble进行绑定,并且最终显示在地图上 CircleShape black = new CircleShape("NO", Color.RED); // Color.BLUE,圆点的颜色 double x = Math.random() * 100 + 100; // 随机x坐标,实际中,可以从服务器获取 double y = Math.random() * 100 + 100; // 随机y坐标 black.setValues(String.format("%.5f,%.5f,15", x, y)); // 设置圆点的位置和大小 map.addShapeAndRefToBubble(black); // 加到地图上 // 该方法可以实现一个圆点,用于和bubble进行绑定,并且最终显示在地图上 CircleShape black2 = new CircleShape("NO2", Color.BLUE); // Color.BLUE,圆点的颜色 double x1 = Math.random() * 300 + 100; // 随机x坐标,实际中,可以从服务器获取 double y1 = Math.random() * 300 + 100; // 随机y坐标 black2.setValues(String.format("%.5f,%.5f,15", x1, y1)); // 设置圆点的位置和大小 map.addShape(black2); // 加到地图上 // 该方法可以实现一个圆点,用于和bubble进行绑定,并且最终显示在地图上 CircleShape black3 = new CircleShape("NO3", Color.YELLOW); // Color.BLUE,圆点的颜色 double x2 = Math.random() * 500 + 100; // 随机x坐标,实际中,可以从服务器获取 double y2 = Math.random() * 500 + 100; // 随机y坐标 black3.setValues(String.format("%.5f,%.5f,15", x2, y2)); // 设置圆点的位置和大小 map.addShape(black3); // 加到地图上 }}
更多相关文章
- Android Canvas类介绍和Android Draw Rect 坐标图示
- Android Service总结04 之被绑定的服务 -- Bound Service
- android将线程绑定在指定CPU
- Android--取得控件在手机屏幕上的位置
- 基于Android DataBinding的InverseBindingMethod改进SeekBar双向
- Android LBS系列04 位置和地图服务简介