com.mapbox.mapboxsdk.style.sources.Source Java Examples

The following examples show how to use com.mapbox.mapboxsdk.style.sources.Source. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrafficPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Toggles the visibility of the traffic layers.
 *
 * @param visible true for visible, false for none
 */
public void setVisibility(boolean visible) {
  this.visible = visible;

  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  Source source = style.getSource(TrafficData.SOURCE_ID);
  if (source == null) {
    initialise();
  }

  List<Layer> layers = style.getLayers();
  for (Layer layer : layers) {
    if (layerIds.contains(layer.getId())) {
      layer.setProperties(visibility(visible ? Property.VISIBLE : Property.NONE));
    }
  }
}
 
Example #2
Source File: PolygonContainer.java    From AirMapSDK-Android with Apache License 2.0 6 votes vote down vote up
public boolean checkForIntersections() {
    List<LatLng> points = PointMath.findIntersections(path);
    if (points.isEmpty()) {
        return false;
    }

    List<Point> intersections = latLngsToPositions(points);
    if (map.getStyle().getLayer(INTERSECTION_LAYER) == null) {
        Source intersectionSource = new GeoJsonSource(INTERSECTION_SOURCE, Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
        map.getStyle().addSource(intersectionSource);
        Layer intersectionLayer = new SymbolLayer(INTERSECTION_LAYER, INTERSECTION_SOURCE)
                .withProperties(PropertyFactory.iconImage(INTERSECTION_IMAGE));
        map.getStyle().addLayer(intersectionLayer);
    } else {
        GeoJsonSource intersectionsSource = map.getStyle().getSourceAs(INTERSECTION_SOURCE);
        intersectionsSource.setGeoJson(Feature.fromGeometry(MultiPoint.fromLngLats(intersections)));
    }

    return true;
}
 
Example #3
Source File: GHAttributionDialogManager.java    From graphhopper-navigation-example with Apache License 2.0 5 votes vote down vote up
private Set<Attribution> build() {
    List<String> attributions = new ArrayList<>();
    attributions.add("<a href=\"https://www.graphhopper.com/\" target=\"_blank\">&copy; GraphHopper API</a>");
    for (Source source : mapboxMap.getSources()) {
        attributions.add(source.getAttribution());
    }

    return new AttributionParser.Options()
            .withCopyrightSign(true)
            // TODO when using Mapbox as Tilesource we should keep this, should we automatically remove it otherwise?
            .withImproveMap(true)
            .withAttributionData(attributions.toArray(new String[attributions.size()]))
            .build().getAttributions();
}
 
Example #4
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * You can pass in a {@link MapLocale} directly into this method which uses the language defined
 * in it to represent the language found on the map.
 *
 * @param mapLocale the {@link MapLocale} object which contains the desired map language
 * @since 0.1.0
 */
public void setMapLanguage(@NonNull MapLocale mapLocale) {
  this.mapLocale = mapLocale;
  if (!style.isFullyLoaded()) {
    // We are in progress of loading a new style
    return;
  }

  List<Layer> layers = style.getLayers();
  for (Source source : style.getSources()) {
    if (sourceIsFromMapbox(source)) {
      boolean isStreetsV8 = sourceIsStreetsV8(source);
      for (Layer layer : layers) {
        if (layer instanceof SymbolLayer) {
          PropertyValue<?> textFieldProperty = ((SymbolLayer) layer).getTextField();
          if (textFieldProperty.isExpression()) {
            if (isStreetsV8) {
              convertExpressionV8(mapLocale, layer, textFieldProperty);
            } else {
              boolean isStreetsV7 = sourceIsStreetsV7(source);
              convertExpression(mapLocale, layer, textFieldProperty, isStreetsV7);
            }
          }
        }
      }
    } else {
      String url = null;
      if (source instanceof VectorSource) {
        url = ((VectorSource) source).getUrl();
      }
      if (url == null) {
        url = "not found";
      }
      Timber.d("The %s (%s) source is not based on Mapbox Vector Tiles. Supported sources:\n %s",
        source.getId(), url, SUPPORTED_SOURCES);
    }
  }
}
 
Example #5
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Checks whether the map's source is a source provided by Mapbox, rather than a custom source.
 *
 * @param singleSource an individual source object from the map
 * @return true if the source is from the Mapbox Streets vector source, false if it's not.
 */
private boolean sourceIsFromMapbox(Source singleSource) {
  if (singleSource instanceof VectorSource) {
    String url = ((VectorSource) singleSource).getUrl();
    if (url != null) {
      for (String supportedSource : SUPPORTED_SOURCES) {
        if (url.contains(supportedSource)) {
          return true;
        }
      }
    }
  }
  return false;
}
 
Example #6
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean sourceIsStreetsV7(Source source) {
  if (source instanceof VectorSource) {
    String url = ((VectorSource) source).getUrl();
    return url != null && url.contains("mapbox.mapbox-streets-v7");
  }
  return false;
}
 
Example #7
Source File: LocalizationPlugin.java    From mapbox-plugins-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private boolean sourceIsStreetsV8(Source source) {
  if (source instanceof VectorSource) {
    String url = ((VectorSource) source).getUrl();
    return url != null && url.contains("mapbox.mapbox-streets-v8");
  }
  return false;
}
 
Example #8
Source File: MapStyleController.java    From AirMapSDK-Android with Apache License 2.0 5 votes vote down vote up
private void setupJurisdictionsForEnterprise() {
    // Reload the style after setup is complete
    if (map == null || map.getMap() == null || map.getMap().getStyle() == null) {
        return;
    }

    OfflineManager.getInstance(map.getContext()).clearAmbientCache(null);

    Style style = map.getMap().getStyle();
    String jurisdictionsId = "jurisdictions";

    if (style.getLayer(jurisdictionsId) != null) {
        style.removeLayer(jurisdictionsId);
    }

    if (style.getSource(jurisdictionsId) != null) {
        style.removeSource(jurisdictionsId);
    }

    TileSet tileSet = new TileSet(tileJsonSpecVersion, AirMap.getBaseJurisdictionsUrlTemplate());
    tileSet.setMaxZoom(12f);
    tileSet.setMinZoom(8f);
    Source source = new VectorSource(jurisdictionsId, tileSet);
    style.addSource(source);
    Layer layer = new FillLayer(jurisdictionsId, jurisdictionsId)
            .withSourceLayer(jurisdictionsId)
            .withProperties(fillColor(TRANSPARENT), fillOpacity(1f));
    style.addLayerAt(layer, 0);
}