karonl
V2EX  ›  Android

我是如何使用 Android SurfaceView 开发室内不规则区域图

  •  
  •   karonl · Apr 29, 2016 · 14247 views
    This topic created in 3688 days ago, the information mentioned may be changed or developed.

    最近因为产品需要引入室内区域地图,非产品主要功能,考虑引擎体积,考虑适用性,最后选择使用继承 SurfaceView 来进行开发,特点是轻量化,操作非常流畅。目前已经实现不规则区域块的绘制和点击监听。 PS :接下来将考虑室内导航的问题。

    演示视频 http://7lryk8.com1.z0.glb.clouddn.com/Screenrecord-2016-04-29-17-20-21.mp4

    项目地址 https://github.com/karonl/InDoorSurfaceView (thanks for your star)

    使用说明

    InDoorSurfaceView view = (InDoorSurfaceView)findViewById(R.id.surface);
    DataAdapter adapter =  new DataAdapter();
    view.setAdapter(adapter);//初始化
    adapter.setBmp(bmp);//设置图片(底图)
    adapter.setList(list);//设置数组(图上的可点区域)
    adapter.refreshData();
    

    接口说明

    view.setOnClickMapListener(new InDoorSurfaceView.onClickMapListener() {
        @Override
        public void onClick(PathUnit region) {
            //读取 pathunit
        }
    }            
    
    view.onFramesListener(new InDoorSurfaceView.FramesListener() {
        @Override
        public void onRefresh(float number) {
            //刷新率
        }
    }    
    

    绘制到图上的不规则可点图形例子

    //图案列表
    private void getUnitList(){
        PathUnit unit = new PathUnit(getList());
        unit.setName("你点击到我了");
        unitList.add(unit);
    }
    //每个图案的坐标组合
    private List<PointF> getList(){
        float density = getResources().getDisplayMetrics().density;
        List<PointF> pointList = new ArrayList<>();
        pointList.add(new PointF(99.1f * density,673.1f * density));
        pointList.add(new PointF(222.1f * density,670.1f * density));
        pointList.add(new PointF(227.1f * density,327.1f * density));
        pointList.add(new PointF(94.1f * density,321.1f * density));
        pointList.add(new PointF(100.1f * density,674.1f * density));
        return pointList;
    }
    

    注:从资源读取的图片对应的坐标要乘上 desity ,网络加载的图片则不用

    如何使用该库 1.通过设置导入 2.去除启动器 intent fliter

    2 replies    2016-04-30 14:26:03 +08:00
    wjh3936
        1
    wjh3936  
       Apr 29, 2016
    已 star
    puras
        2
    puras  
       Apr 30, 2016
    听着很牛 B 的样子,同 Star
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3274 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 12:02 · PVG 20:02 · LAX 05:02 · JFK 08:02
    ♥ Do have faith in what you're doing.