iMobile for Android如何对接iserver发布的数据服务

严稳
2023-12-01

作者:dongyx

使用iMobile for Android如何实现对接iserver发布数据服务呢?在支持过程中经常遇到客户会问我发了数据服务能不能直接在地图显示或者我能不能直接对iserver发布的数据服务进行查询呢?今天小编就为大家介绍一下使用iMobile产品如何对接iserver发布的数据服务和地图服务,本篇文章主要从数据服务的上传、下载和更新。
一、数据服务
1.如何下载数据服务
要想下载数据服务首先得准备一个数据源,可以直接使用代码在手机端创建一个文件型数据源或者在iDesktop中创建数据源(目前支持UDB类型)拷贝到手机端打开。具体实现代码如下:

final ProgressDialog progress = new ProgressDialog(MainActivity.this);
        String mUrl="http://172.16.14.191:8090/iserver";
        String mUrlDatasets ="http://172.16.14.191:8090/iserver/services/data-supermap/rest/data/datasources/orcl/datasets/";
        String datasetName = "New_Point";
        String urlServer  = mUrl;
        String urlDataset = mUrlDatasets + datasetName;
        //构造DataDownloadService对象
        DataDownloadService downloadService = new DataDownloadService(urlServer);
        downloadService.setResponseCallback(new ResponseCallback(){
            @Override
            //响应回调函数,向服务器请求失败时回调
            public void requestFailed(String errorMsg) {
                Log.e("Download", errorMsg);
                progress.dismiss();
                Toast toast = Toast.makeText(MainActivity.this, "下载失败", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
            }
            @Override
           //响应回调函数,向服务器请求成功时回调
            public void requestSuccess() {
                Log.i("Download", "requestSuccess");
            }
            @Override
            public void addFeatureSuccess(int i) {
            }
            @Override
            public void receiveResponse(FeatureSet featureSet) {
            }
            @Override
            //响应回调函数,数据服务结束时调用
            public void dataServiceFinished(String arg0) {
                Toast toast = Toast.makeText(MainActivity.this, "下载成功", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                progress.dismiss();
                m_MapControl.getMap().refresh();
            }
        });
        //显示下载服务执行的进度条,回调里面销毁
        progress.setMessage("下载中...");
        progress.show();
        //执行下载操作
        Datasource m_datasource = m_Workspace.getDatasources().get(0);
        downloadService.downloadDataset(urlDataset, m_datasource);

2.服务器更新数据后,iMobile如何更新下载的数据

当我们将iserver的数据下载到本地后,iserver端数据进行了更改,可以通过更新数据的方式将iserver的变动更新到本地数据集中,需要注意的是进行更新操作时iserver和本地都存在该名称的数据集以及其对应的同步属性数据集:

final ProgressDialog progress = new ProgressDialog(MainActivity.this);
        String mUrl="http://172.16.14.191:8090/iserver";
        String mUrlDatasets ="http://172.16.14.191:8090/iserver/services/data-supermap/rest/data/datasources/orcl/datasets/";
        String datasetName = "New_Point";
        String urlServer  = mUrl;
        String urlDataset = mUrlDatasets + datasetName;
        //构造DataDownloadService对象
        DataDownloadService downloadService = new DataDownloadService(urlServer);
        downloadService.setResponseCallback(new ResponseCallback(){
            @Override
        //响应回调函数,向服务器请求失败时回调
            public void requestFailed(String errorMsg) {
                Log.e("Update: ", errorMsg);
                progress.dismiss();
                Toast toast = Toast.makeText(MainActivity.this, "更新失败", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
            }
            @Override
        //响应回调函数,向服务器请求成功时回调
            public void requestSuccess() {
                System.out.println("更新完成");
            }

            @Override
            public void addFeatureSuccess(int i) {

            }

            @Override
            public void receiveResponse(FeatureSet featureSet) {

            }

            @Override
        //响应回调函数,数据服务结束时调用
            public void dataServiceFinished(String arg0) {
                Toast toast = Toast.makeText(MainActivity.this, "更新成功", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                progress.dismiss();
                m_MapControl.getMap().refresh();
            }
        });
        //显示更新服务执行的进度条,回调里面销毁
        progress.setMessage("更新中...");
        progress.show();
        //执行更新操作
        Datasource m_datasource = m_Workspace.getDatasources().get(0);
        downloadService.updateDataset(urlDataset, (DatasetVector)m_datasource.getDatasets().get(datasetName));

3.向iserver端提交数据
按照业务需要完成本地数据的修改后,即可将修改后的数据提交到服务端。提交数据时需注意两点:1)提交时要求服务器端和本地都存在该数据集及对应的同步属性数据集。2)提交时本地数据集的版本不得高于服务端版本(即本地的Max[SmUserID]不大于服务器上的Max[SMID])。

 final ProgressDialog progress = new ProgressDialog(MainActivity.this);
        //调用第三步中的方法,修改数据
        //modifiedDataset(2);
        Datasource m_datasource = m_Workspace.getDatasources().get(0);
        String datasetName = "New_Point";
        DatasetVector dataset = (DatasetVector)m_datasource.getDatasets().get(datasetName);
        String mUrl="http://172.16.14.191:8090/iserver";
        String mUrlDatasets ="http://172.16.14.191:8090/iserver/services/data-supermap/rest/data/datasources/orcl/datasets/";

        String urlServer  = mUrl;
        String urlDataset = mUrlDatasets + datasetName;
        //构造DataUploadService对象
        DataUploadService uploadService = new DataUploadService(urlServer);
        uploadService.setResponseCallback(new ResponseCallback(){
            @Override
        //响应回调函数,向服务器请求失败时回调
            public void requestFailed(String errorMsg) {
                Log.e("commit: ", errorMsg);
                progress.dismiss();
                Toast toast = Toast.makeText(MainActivity.this, "提交失败", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

            }
            @Override
            //响应回调函数,向服务器请求成功时回调
            public void requestSuccess() {
                Log.i("Commit", "requestSuccess");
            }
            @Override
            public void addFeatureSuccess(int i) {
            }
            @Override
            public void receiveResponse(FeatureSet featureSet) {
            }
            @Override
            //响应回调函数,数据服务结束时调用
            public void dataServiceFinished(String arg0) {
                Toast toast = Toast.makeText(MainActivity.this, "提交成功", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                progress.dismiss();
                m_MapControl.getMap().refresh();
            }
        });
        //显示提交服务执行的进度条,回调里面销毁
        progress.setMessage("提交中...");
        progress.show();
        //执行提交操作
        uploadService.commitDataset(urlDataset, dataset);

 类似资料: