Android WorldWind的使用与添加Geoserver影像(三)

在上一章中我们学习了怎么在Activity中加载Geoserver影像,接下来学习怎么在 Fragment中添加影像。
继续上一章的内容。
在MainActivity中创建Fragment方法,创建好后在OnCreate中调用。

/**
* 添加三维球并显示观测点的经纬度与观测高
*/
public void addGlobeFragment() {
    //添加一个FragmentTransaction的实例
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    //用add()方法加上Fragment的对象ObservationFragment
    worldWindowFragment = new WorldWindowFragment();
    transaction.add(R.id.globe, worldWindowFragment);
    //baseGlobeFragment=worldWindowFragment;
    transaction.commit();
}

之后新建一个WorldWindowFragment类继承Fragment类

public class WorldWindowFragment extends Fragment {

    private WorldWindow worldWindow;
    private WmsLayer wenanLayer;
    private RenderableLayer locateLayer;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container, @NonNull Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_worldwind, null);
        WorldWindow worldWindowView = createWorldWindow();
        worldWindowView.setWorldWindowController(new BasicWorldWindowController());
        FrameLayout globelayout=view.findViewById(R.id.globelayout);
        globelayout.addView(worldWindowView);
        return view;
    }

    public WorldWindow createWorldWindow() {
        worldWindow = new WorldWindow(getContext());
        worldWindow.getLayers().addLayer(new BackgroundLayer());
        worldWindow.getGlobe().getElevationModel().addCoverage(new BasicElevationCoverage());
        addWenanLayer();
        locateLayer = new RenderableLayer("VectorTest");
        worldWindow.getLayers().addLayer(locateLayer);
        return worldWindow;
    }

    /**
     * 添加基础底图数据
     */
    public void addWenanLayer(){
        WmsLayerConfig config = new WmsLayerConfig();
        config.serviceAddress = "http://192.168.0.1:7080/geoserver/ksh/wms";
        config.wmsVersion = "1.1.0";
        config.layerNames = "ksh:wax2018";
        wenanLayer = new WmsLayer(new Sector().setFullSphere(), 1, config);
        worldWindow.getLayers().addLayer(wenanLayer);
    }
}

fragment_worldwind布局为

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--三维球-->
    <FrameLayout
        android:id="@+id/globelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </FrameLayout>

</LinearLayout>

至此,开发完全结束。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nanjumufeng

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值