当前位置: 首页 > 知识库问答 >
问题:

android mapbox源geojson不工作

公孙涵育
2023-03-14

我举了一个例子:https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/

它起作用了。

然后,我尝试用源geojson替换这些点,但没有成功,如下所述:https://docs.mapbox.com/android/maps/guides/data-driven-styling/#geojson

除了在地图上添加新东西的部分,我没有改变任何东西。这一部分现在看起来像这样:

 @Override
    public void onMapReady(@NonNull final MapboxMap mapboxMap) {

        try {
            mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/mapbox/cjf4m44iw0uza2spb3q0a7s41")

                    // Add the SymbolLayer icon image to the map style
                    .withImage(ICON_ID, BitmapFactory.decodeResource(
                            MainActivity.this.getResources(), R.drawable.mapbox_marker_icon_default))

                    // Adding a GeoJson source for the SymbolLayer icons.
                    .withSource(new GeoJsonSource("ports",
                            new URI("https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson")))

                    // Adding the actual SymbolLayer to the map style. An offset is added that the bottom of the red
                    // marker icon gets fixed to the coordinate, rather than the middle of the icon being fixed to
                    // the coordinate point. This is offset is not always needed and is dependent on the image
                    // that you use for the SymbolLayer icon.
                    .withLayer(new SymbolLayer(LAYER_ID, SOURCE_ID)
                            .withProperties(
                                    iconImage(ICON_ID),
                                    iconAllowOverlap(true),
                                    iconIgnorePlacement(true)
                            )
                    ), new Style.OnStyleLoaded() {
                @Override
                public void onStyleLoaded(@NonNull Style style) {

                    // Map is set up and the style has loaded. Now you can add additional data or make other map adjustments.


                }
            });
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }

当我运行应用程序时,我会得到一个带有mapbox地图的地图画布,但没有点。我错过了什么?

共有1个答案

程鸿波
2023-03-14

解决方案是,我只是没有一个图像资源在我的绘图文件夹。

 类似资料:
  • GeoJSON 是一个编码各种地理数据结构的格式。一个GeoJSON对象可以代表一个几何,一个特性,或一组特性。GeoJSON 支持以下几何类型: 点,LineString,多边形,多点,MultiLineString,多个多边形,GeometryCollection。GeoJSON(包含一 个几何特征对象和额外的属性和特性集合代表一个列表的功能。

  • 我有一个java项目的Apache ant构建文件,其中包含一个javac命令来编译我的源代码。这个项目有一些特殊的约束,它是由小的子项目组成的。这些子项目中的大多数具有以下文件夹结构: src和service都是源文件夹。A.java导入/service文件夹中的一些类,例如B.java。在eclipse中,一切正常,A.java导入B.java时没有任何错误或问题,所以我假设classpath

  • 我试图使用SpringMVC制作一个简单的JavaWeb应用程序。我试图在我的资源文件夹中添加CSS和JS文件,该文件夹分别位于。因此,我需要在我的l并在该文件中包含spring webmvc。我的如下所示: 下面给出了我的POM. xml: 一旦我使用Maven构建项目,并尝试使用Eclipse IDE上添加的Tomcat在服务器上运行它,我就会得到以下错误: 配置问题:找不到元素[resour

  • 接口说明 为了让用户设置的单体化、标绘、压平数据(点线面要素信息等)在下一次访问数据的时候,能正常查看,Wish3DEarth团队新增了单体化、标绘、压平数据的保存接口,最终访问相对应的文件,来加载设置好的属性信息。 存储的文件名如下 1:单体化 attach.geojson 2:标绘 draw.geojson 3:压平 flatten.geojson 如需调用,请访问 开发者文档 来查看详细的接

  • 简介 GeoJSON是一种用于编码各种地理数据结构的格式官网。满足JSON语法格式,具体的说明有两处,一是:wiki-GeoJSON_draft_version_6说明-英文,还有一个是在github上,开源中国上有中英文对照 geojson-spec,GeoJson用的比较广泛,如果想进一步了解二者的不同,请查看下面的扩展阅读 补充 样式说明 topojson 的样式只能通过加载时以参数传入进行

  • 然而,使用getInputStream是可行的。 如果有人能分享这背后的原因,以及在spring Boot中加载xml文件是否有更好的/替代的方法,这将是非常有帮助的。如有任何帮助,我将不胜感激