mapbox 样式

styles

Source子类Source描述Layer子类Layer描述
GeoJsonSource常用,存放点线面数据的jsonSymbolLayer标志图层,结合点数据使用
VectorSource常用,存放矢量瓦片的数据
(例如路况拥堵效果)
LineLayer线图层,结合线数据使用
RasterSource常用,存放栅格瓦片的数据FillLayer面图层,结合面数据使用
ImageSource不常用,将一张图片贴在地图某片四边形区域CircleLayer圆图层,结合点数据使用,点为圆心,可以设置半径
RasterDemSource不常用,带山坡效果的栅格瓦片数据RasterLayer栅格图层,结合栅格瓦片数据使用
CustomGeometrySource不用HeatmapLayer热力图层,结合大量点数据使用效果好
UnknownSource不用HillshadeLayer山坡图层,结合山坡瓦片数据使用
BackgroundLayer背景图层,不需要结合Source即可使用
FillExtrusionLayer面图层,带3D效果,像建筑物凸起这种
LocationIndicatorLayer结合定位点使用的图层
CustomLayer没有实际效果

1. 矢量瓦片加载(VectorSource)

VectorSourceActivity

          style.addSource(
            new VectorSource("terrain-data", "mapbox://mapbox.mapbox-terrain-v2")
          );

          LineLayer terrainData = new LineLayer("terrain-data", "terrain-data");
          terrainData.setSourceLayer("contour");
          terrainData.setProperties(
            lineJoin(Property.LINE_JOIN_ROUND),
            lineCap(Property.LINE_CAP_ROUND),
            lineColor(Color.parseColor("#ff69b4")),
            lineWidth(1.9f)
          );

          style.addLayer(terrainData);

2. 栅格瓦片加载(RasterSource)

AddWmsSourceActivity|AdjustLayerOpacityActivity

          style.addSource(new RasterSource(
            "web-map-source",
            new TileSet("tileset", "https://img.nj.gov/imagerywms/Natural2015?bbox={"
              + "bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:"
              + "3857&transparent=true&width=256&height=256&layers=Natural2015"), 256));

          // Create a RasterLayer with the source created above and then add the layer to the map
          if (style.getLayer("tunnel-street-minor-low") != null) {
            style.addLayerBelow(
              new RasterLayer("web-map-layer", "web-map-source"), "tunnel-street-minor-low");
          } else {
            style.addLayer(new RasterLayer("web-map-layer", "web-map-source"));
          }

3. 改变地图语种(Language)

LanguageSwitchActivity

  SymbolLayer countryLabelTextSymbolLayer = style.getLayerAs("country-label");
  countryLabelTextSymbolLayer.setProperties(textField("{name_zh-Hans}"));

4. 隐藏显示图层(Visibility)

ShowHideLayersActivity

  if (VISIBLE.equals(layer.getVisibility().getValue())) {
    layer.setProperties(visibility(NONE));
  } else {
    layer.setProperties(visibility(VISIBLE));
  }

5. 地图上加载图片(ImageSource)

ImageSourceActivity

  // Set the latitude and longitude values for the image's four corners
  LatLngQuad quad = new LatLngQuad(
    new LatLng(25.7836, -80.11725),
    new LatLng(25.783548, -80.1397431334),
    new LatLng(25.7680, -80.13964),
    new LatLng(25.76795, -80.11725)
  );

  // Add an ImageSource to the map
  style.addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.miami_beach));

  // Create a raster layer and use the imageSource's ID as the layer's data. Then add a RasterLayer to the map.
  style.addLayer(new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE));

6. 时间推移效果

ImageSourceTimeLapseActivity

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值