当前位置: 首页>>代码示例>>Java>>正文


Java FeatureCollection类代码示例

本文整理汇总了Java中com.mapbox.services.commons.geojson.FeatureCollection的典型用法代码示例。如果您正苦于以下问题:Java FeatureCollection类的具体用法?Java FeatureCollection怎么用?Java FeatureCollection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FeatureCollection类属于com.mapbox.services.commons.geojson包,在下文中一共展示了FeatureCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateMapSourceFromFeatureCollection

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
/**
 * Takes a {@link FeatureCollection} and creates a map GeoJson source using the sourceId also
 * provided.
 *
 * @param mapboxMap  that the current mapView is using
 * @param collection the feature collection to be added to the map style
 * @param sourceId   the source's id for identifying it when adding layers
 * @since 0.8.0
 */
public static void updateMapSourceFromFeatureCollection(@NonNull MapboxMap mapboxMap,
                                                        @Nullable FeatureCollection collection,
                                                        @NonNull String sourceId) {
  if (collection == null) {
    collection = FeatureCollection.fromFeatures(new Feature[] {});
  }

  GeoJsonSource source = mapboxMap.getSourceAs(sourceId);
  if (source == null) {
    GeoJsonOptions routeGeoJsonOptions = new GeoJsonOptions().withMaxZoom(16);
    GeoJsonSource routeSource = new GeoJsonSource(sourceId, collection, routeGeoJsonOptions);
    mapboxMap.addSource(routeSource);
  } else {
    source.setGeoJson(collection);
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:26,代码来源:MapUtils.java

示例2: doInBackground

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
protected List<Position> doInBackground(Void... voids) {

  List<Position> points = new ArrayList<>();

  try {
    // Load GeoJSON file
    InputStream inputStream = getAssets().open("trace.geojson");
    BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
    StringBuilder sb = new StringBuilder();
    int cp;
    while ((cp = rd.read()) != -1) {
      sb.append((char) cp);
    }

    inputStream.close();
    FeatureCollection featureCollection = FeatureCollection.fromJson(sb.toString());
    LineString lineString = (LineString) featureCollection.getFeatures().get(0).getGeometry();
    points = lineString.getCoordinates();
  } catch (Exception exception) {
    Log.e(TAG, "Exception Loading GeoJSON: " + exception.toString());
  }

  return points;
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:26,代码来源:MapMatchingActivity.java

示例3: waypointFeatureCollection

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
/**
 * The routes also display an icon for each waypoint in the route, we use symbol layers for this.
 */
private static FeatureCollection waypointFeatureCollection(DirectionsRoute route) {
  final List<Feature> waypointFeatures = new ArrayList<>();
  for (RouteLeg leg : route.legs()) {
    waypointFeatures.add(getPointFromLineString(leg, 0));
    waypointFeatures.add(getPointFromLineString(leg, leg.steps().size() - 1));
  }
  return FeatureCollection.fromFeatures(waypointFeatures);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:12,代码来源:NavigationMapRoute.java

示例4: onMapClick

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
public void onMapClick(@NonNull LatLng point) {
  if (directionsRoutes == null || directionsRoutes.isEmpty() || !alternativesVisible) {
    return;
  }
  // determine which feature collections are alternative routes
  for (FeatureCollection featureCollection : featureCollections) {
    if (!(featureCollection.getFeatures().get(0).getGeometry() instanceof Point)) {
      List<com.mapbox.geojson.Point> linePoints = calculateLinePoints(featureCollection);

      com.mapbox.geojson.Feature feature = TurfMisc.pointOnLine(
        com.mapbox.geojson.Point.fromLngLat(point.getLongitude(), point.getLatitude()),
        linePoints);
      com.mapbox.geojson.Point pointAlong = (com.mapbox.geojson.Point) feature.geometry();
      // No linestring to get point on line, thus we just return.
      if (pointAlong == null) {
        return;
      }
      double dis = TurfMeasurement.distance(com.mapbox.geojson
        .Point.fromLngLat(point.getLongitude(),
        point.getLatitude()), pointAlong, TurfConstants.UNIT_METERS);
      if (dis <= ROUTE_CLICK_PADDING) {
        primaryRouteIndex = featureCollection.getFeatures()
          .get(0).getNumberProperty(INDEX_KEY).intValue();
      }
    }
  }
  updateRoute();
  if (onRouteSelectionChangeListener != null) {
    onRouteSelectionChangeListener.onNewPrimaryRouteSelected(
      directionsRoutes.get(primaryRouteIndex));
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:34,代码来源:NavigationMapRoute.java

示例5: calculateLinePoints

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static List<com.mapbox.geojson.Point> calculateLinePoints(
  FeatureCollection featureCollection) {
  List<com.mapbox.geojson.Point> linePoints = new ArrayList<>();
  for (Feature feature : featureCollection.getFeatures()) {
    List<Position> positions = (List<Position>) feature.getGeometry().getCoordinates();
    for (Position pos : positions) {
      linePoints.add(com.mapbox.geojson
        .Point.fromLngLat(pos.getLongitude(), pos.getLatitude()));
    }
  }
  return linePoints;
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:14,代码来源:NavigationMapRoute.java

示例6: updateRoute

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
private void updateRoute() {
  // Update all route geometries to reflect their appropriate colors depending on if they are
  // alternative or primary.
  for (FeatureCollection featureCollection : featureCollections) {
    if (!(featureCollection.getFeatures().get(0).getGeometry() instanceof Point)) {
      int index = featureCollection.getFeatures().get(0).getNumberProperty(INDEX_KEY).intValue();
      updatePrimaryShieldRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_SHIELD_LAYER_ID,
        index), index);
      updatePrimaryRoute(String.format(Locale.US, ID_FORMAT, GENERIC_ROUTE_LAYER_ID, index),
        index);
    }
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:14,代码来源:NavigationMapRoute.java

示例7: addSource

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
private void addSource(String sourceId) {
  FeatureCollection emptyFeature = FeatureCollection.fromFeatures(new Feature[] {});
  GeoJsonSource locationSource = new GeoJsonSource(
    sourceId,
    emptyFeature,
    new GeoJsonOptions().withMaxZoom(16));
  mapboxMap.addSource(locationSource);
  sourceMap.put(sourceId, locationSource);
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:10,代码来源:LocationLayer.java

示例8: onMapClick

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
public void onMapClick(@NonNull LatLng point) {

  final SymbolLayer marker = (SymbolLayer) mapboxMap.getLayer("selected-marker-layer");

  final PointF pixel = mapboxMap.getProjection().toScreenLocation(point);
  List<Feature> features = mapboxMap.queryRenderedFeatures(pixel, "marker-layer");
  List<Feature> selectedFeature = mapboxMap.queryRenderedFeatures(pixel, "selected-marker-layer");

  if (selectedFeature.size() > 0 && markerSelected) {
    return;
  }

  if (features.isEmpty()) {
    if (markerSelected) {
      deselectMarker(marker);
    }
    return;
  }

  FeatureCollection featureCollection = FeatureCollection.fromFeatures(
    new Feature[]{Feature.fromGeometry(features.get(0).getGeometry())});
  GeoJsonSource source = mapboxMap.getSourceAs("selected-marker");
  if (source != null) {
    source.setGeoJson(featureCollection);
  }

  if (markerSelected) {
    deselectMarker(marker);
  }
  if (features.size() > 0) {
    selectMarker(marker);
  }
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:35,代码来源:BasicSymbolLayerActivity.java

示例9: initPositionListFromGeoJsonFile

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
private void initPositionListFromGeoJsonFile() {

    // Get GeoJSON features from GeoJSON file in the assets folder
    featureCollection = FeatureCollection.fromJson(loadGeoJsonFromAsset("boston_charge_stations.geojson"));

    // Initialize List<Position> for eventual use in the Matrix API call
    positionList = new ArrayList<>();

    // Get the position of each GeoJSON feature and build the list of Position
    // objects for eventual use in the Matrix API call
    for (Feature singleLocation : featureCollection.getFeatures()) {
      Position singleLocationPosition = (Position) singleLocation.getGeometry().getCoordinates();
      positionList.add(singleLocationPosition);
    }
  }
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:16,代码来源:DirectionsMatrixApiActivity.java

示例10: setupData

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
public void setupData(final FeatureCollection collection) {
  if (mapboxMap == null) {
    return;
  }

  featureCollection = collection;
  setupSource();
  setupMakiLayer();
  setupLoadingLayer();
  setupCalloutLayer();
  setupRecyclerView();
  hideLabelLayers();
  setupMapillaryTiles();
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:15,代码来源:SymbolLayerMapillaryActivity.java

示例11: doInBackground

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
protected FeatureCollection doInBackground(Void... params) {
  SymbolLayerMapillaryActivity activity = activityRef.get();

  if (activity == null) {
    return null;
  }

  String geoJson = loadGeoJsonFromAsset(activity, "sf_poi.geojson");
  return new GsonBuilder()
    .registerTypeAdapter(Geometry.class, new GeometryDeserializer())
    .registerTypeAdapter(Position.class, new PositionDeserializer())
    .create().fromJson(geoJson, FeatureCollection.class);
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:15,代码来源:SymbolLayerMapillaryActivity.java

示例12: onPostExecute

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
protected void onPostExecute(FeatureCollection featureCollection) {
  super.onPostExecute(featureCollection);
  SymbolLayerMapillaryActivity activity = activityRef.get();
  if (featureCollection == null || activity == null) {
    return;
  }
  activity.setupData(featureCollection);
  new GenerateViewIconTask(activity).execute(featureCollection);
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:11,代码来源:SymbolLayerMapillaryActivity.java

示例13: onMapReady

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
public void onMapReady(MapboxMap mapboxMap) {

  this.mapboxMap = mapboxMap;

  List<Feature> markerCoordinates = new ArrayList<>();
  markerCoordinates.add(Feature.fromGeometry(
    Point.fromCoordinates(Position.fromCoordinates(-71.065634, 42.354950))) // Boston Common Park
  );
  markerCoordinates.add(Feature.fromGeometry(
    Point.fromCoordinates(Position.fromCoordinates(-71.097293, 42.346645))) // Fenway Park
  );
  markerCoordinates.add(Feature.fromGeometry(
    Point.fromCoordinates(Position.fromCoordinates(-71.053694, 42.363725))) // The Paul Revere House
  );
  FeatureCollection featureCollection = FeatureCollection.fromFeatures(markerCoordinates);

  Source geoJsonSource = new GeoJsonSource("marker-source", featureCollection);
  mapboxMap.addSource(geoJsonSource);

  Bitmap icon = BitmapFactory.decodeResource(
    BasicSymbolLayerActivity.this.getResources(), R.drawable.blue_marker_view);

  // Add the marker image to map
  mapboxMap.addImage("my-marker-image", icon);

  SymbolLayer markers = new SymbolLayer("marker-layer", "marker-source")
    .withProperties(PropertyFactory.iconImage("my-marker-image"));
  mapboxMap.addLayer(markers);

  // Add the selected marker source and layer
  FeatureCollection emptySource = FeatureCollection.fromFeatures(new Feature[]{});
  Source selectedMarkerSource = new GeoJsonSource("selected-marker", emptySource);
  mapboxMap.addSource(selectedMarkerSource);

  SymbolLayer selectedMarker = new SymbolLayer("selected-marker-layer", "selected-marker")
    .withProperties(PropertyFactory.iconImage("my-marker-image"));
  mapboxMap.addLayer(selectedMarker);

  mapboxMap.addOnMapClickListener(this);
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:42,代码来源:BasicSymbolLayerActivity.java

示例14: onCreate

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // Mapbox access token is configured here. This needs to be called either in your application
  // object or in the same activity which contains the mapview.
  Mapbox.getInstance(this, getString(R.string.access_token));

  // This contains the MapView in XML and needs to be called after the access token is configured.
  setContentView(R.layout.activity_query_feature_count);

  // Define our views, ones the center box and the others our view container used for the
  // snackbar.
  final View selectionBox = findViewById(R.id.selection_box);
  final View viewContainer = findViewById(R.id.query_feature_count_map_container);

  mapView = (MapView) findViewById(R.id.mapView);
  mapView.onCreate(savedInstanceState);
  mapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(final MapboxMap mapboxMap) {

      mapboxMap.addSource(
        new GeoJsonSource("highlighted-shapes-source"));

      // add a layer to the map that highlights the maps buildings inside the bounding box.
      mapboxMap.addLayer(
        new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
          .withProperties(fillColor(Color.parseColor("#50667F"))));

      // Toast instructing user to tap on the box
      Toast.makeText(
        FeatureCountActivity.this,
        getString(R.string.tap_on_feature_box_instruction),
        Toast.LENGTH_LONG
      ).show();

      selectionBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
          // Perform feature query within the selectionBox. The bounding box is
          // calculated using the view but you can also use a map bounding box made up
          // of latitudes and longitudes.
          int top = selectionBox.getTop() - mapView.getTop();
          int left = selectionBox.getLeft() - mapView.getLeft();
          RectF box = new RectF(left, top, left + selectionBox.getWidth(), top + selectionBox.getHeight());
          List<Feature> features = mapboxMap.queryRenderedFeatures(box, "building");

          // Show the features count
          Snackbar.make(
            viewContainer,
            String.format(getString(R.string.feature_count_snackbar_feature_size), features.size()),
            Snackbar.LENGTH_LONG).show();

          GeoJsonSource source = mapboxMap.getSourceAs("highlighted-shapes-source");
          if (source != null) {
            source.setGeoJson(FeatureCollection.fromFeatures(features));
          }
        }
      });
    }
  });
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:64,代码来源:FeatureCountActivity.java

示例15: MapillaryDataLoadResult

import com.mapbox.services.commons.geojson.FeatureCollection; //导入依赖的package包/类
MapillaryDataLoadResult(FeatureCollection mapillaryFeatureCollection) {
  this.mapillaryFeatureCollection = mapillaryFeatureCollection;
}
 
开发者ID:mapbox,项目名称:mapbox-android-demo,代码行数:4,代码来源:SymbolLayerMapillaryActivity.java


注:本文中的com.mapbox.services.commons.geojson.FeatureCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。