2023-02-10 ArcGIS三维加载天地图底图

2023-02-09  本文已影响0人  谦谦行者
// 去除logo 水印
val licenseCode = "runtimelite,1000,rud4449636536,none,NKMFA0PL4S0DRJE15166"
        ArcGISRuntimeEnvironment.setLicense(licenseCode)
        sceneView.isAttributionTextVisible = false

        val scene = ArcGISScene()
        // 设置加载天地图---影像
        val webTiledLayer =
            TianDiTuMethodsClass.CreateTianDiTuTiledLayer(TianDiTuMethodsClass.LayerType.TIANDITU_IMAGE_MERCATOR)
      // 矢量:TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_MERCATOR

        val webTiledLayer1 =
           TianDiTuMethodsClass.CreateTianDiTuTiledLayer(TianDiTuMethodsClass.LayerType.TIANDITU_IMAGE_ANNOTATION_CHINESE_MERCATOR)
      // 矢量:TianDiTuMethodsClass.LayerType.TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR
        val requestConfiguration = RequestConfiguration().apply {
            headers["referer"] = "http://www.arcgis.com"
        }
        webTiledLayer.requestConfiguration = requestConfiguration
        webTiledLayer1.requestConfiguration = requestConfiguration
        webTiledLayer.loadAsync()
        webTiledLayer1.loadAsync()
        val basemap = Basemap(webTiledLayer)
        basemap.baseLayers.add(webTiledLayer1)
        scene.basemap = basemap
    // 加载自己的地图
    val arcGISMapImageLayer =
            ArcGISMapImageLayer("http://......./MapServer")
        arcGISMapImageLayer.loadAsync()
    scene.operationalLayers.add(arcGISMapImageLayer)
        sceneView.scene = scene

    //  控制地图视角
    //  前两个是经纬度,后几个是角度
      val camera = Camera(36.53481, 115.47989, 2000.0, 345.0, 0.0, 0.0)
        sceneView.setViewpointCamera(camera) 
/**
*     设置底图点击事件
*/
    sceneView.setOnTouchListener(object : DefaultSceneViewOnTouchListener(sceneView){
            override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
                e ?:return false
                val mapPoint = android.graphics.Point(e.x.toInt(), e.y.toInt())
                val listListenableFuture = sceneView.identifyGraphicsOverlaysAsync(mapPoint,
                    12.0,false,5)
                listListenableFuture.addDoneListener{
                    try {
                        val results = listListenableFuture.get()
                        for (result in results) {
                            for (graphic in result.graphics) {
                                
                                val stationCode = graphic.attributes["name"].toString()

                                ToastUtils.showToast(this@TestActivity,"$stationCode")
                            }
                        }

                    } catch (e: Exception) {

                    }
                }
                return super.onSingleTapConfirmed(e)
            }
        })
上一篇下一篇

猜你喜欢

热点阅读