com.mapbox.mapboxsdk.style.sources.VectorSource Java Examples
The following examples show how to use
com.mapbox.mapboxsdk.style.sources.VectorSource.
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: NavigationMapboxMap.java From graphhopper-navigation-android with MIT License | 5 votes |
private void initializeStreetsSource(MapboxMap mapboxMap) { VectorSource streetSource = new VectorSource(STREETS_SOURCE_ID, MAPBOX_STREETS_V7); mapboxMap.addSource(streetSource); LineLayer streetsLayer = new LineLayer(STREETS_LAYER_ID, STREETS_SOURCE_ID) .withProperties( lineWidth(DEFAULT_WIDTH), lineColor(Color.WHITE) ) .withSourceLayer(ROAD_LABEL); mapboxMap.addLayerAt(streetsLayer, LAST_INDEX); }
Example #2
Source File: LocalizationPlugin.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 #3
Source File: LocalizationPlugin.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 #4
Source File: LocalizationPlugin.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
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 #5
Source File: LocalizationPlugin.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
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 #6
Source File: RegionSelectionFragment.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 5 votes |
public String getOfflineRegionName() { List<Feature> featureList = mapboxMap.queryRenderedFeatures(boundingBox, LAYER_IDS); if (featureList.isEmpty() && style != null) { Timber.v("Rendered features empty, attempting to query vector source."); VectorSource source = style.getSourceAs("composite"); if (source != null) { featureList = source.querySourceFeatures(SOURCE_LAYER_IDS, null); } } if (!featureList.isEmpty() && featureList.get(0).properties().has("name")) { return featureList.get(0).getStringProperty("name"); } return getString(R.string.mapbox_offline_default_region_name); }
Example #7
Source File: MapStyleController.java From AirMapSDK-Android with Apache License 2.0 | 5 votes |
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); }
Example #8
Source File: TrafficPlugin.java From mapbox-plugins-android with BSD 2-Clause "Simplified" License | 4 votes |
/** * Adds traffic source to the map. */ private void addTrafficSource() { VectorSource trafficSource = new VectorSource(TrafficData.SOURCE_ID, TrafficData.SOURCE_URL); style.addSource(trafficSource); }
Example #9
Source File: MapStyleController.java From AirMapSDK-Android with Apache License 2.0 | 4 votes |
public void addMapLayers(AirMapRuleset ruleset, boolean useSIMeasurements) { String sourceId = ruleset.getId(); List<String> layers = ruleset.getLayers(); // check if source is already added to map Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); if(temporalFilter != null){ switch (temporalFilter.getType()){ case NOW: switch (temporalFilter.getRange()){ case ONE_HOUR: cal2.roll(Calendar.HOUR_OF_DAY, 1); break; case FOUR_HOUR: cal2.roll(Calendar.HOUR_OF_DAY, 4); break; case EIGHT_HOUR: cal2.roll(Calendar.HOUR_OF_DAY, 8); break; case TWELVE_HOUR: cal2.roll(Calendar.HOUR_OF_DAY, 12); break; } break; case CUSTOM: cal1.setTime(temporalFilter.getFutureDate()); cal2.setTime(temporalFilter.getFutureDate()); cal1.set(Calendar.HOUR_OF_DAY, temporalFilter.getStartHour()); cal1.set(Calendar.MINUTE, temporalFilter.getStartMinute()); cal2.set(Calendar.HOUR_OF_DAY, temporalFilter.getEndHour()); cal2.set(Calendar.MINUTE, temporalFilter.getEndMinute()); break; } } if (map.getMap().getStyle().getSource(sourceId) != null) { Timber.e("Source already added for: %s", sourceId); } else { String urlTemplates; if(temporalFilter == null){ urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements); } else { urlTemplates = AirMap.getRulesetTileUrlTemplate(sourceId, layers, useSIMeasurements, cal1.getTime(), cal2.getTime()); } TileSet tileSet = new TileSet(tileJsonSpecVersion, urlTemplates); tileSet.setMaxZoom(12f); tileSet.setMinZoom(8f); VectorSource tileSource = new VectorSource(sourceId, tileSet); map.getMap().getStyle().addSource(tileSource); } for (String sourceLayer : layers) { for (AirMapLayerStyle layerStyle : mapStyle.getLayerStyles(sourceLayer)) { // check if layer is already added to map if (map.getMap().getStyle().getLayer(layerStyle.id + "|" + sourceId + "|new") != null) { continue; } // use layer from styles as a template Layer layerToClone = map.getMap().getStyle().getLayer(layerStyle.id); Layer layer = layerStyle.toMapboxLayer(layerToClone, sourceId); // add temporal filter if applicable if (layer.getId().contains("airmap|tfr") || layer.getId().contains("notam")) { addTemporalFilter(layer); } if (airspaceTypeListener != null) { String typeKey = layerStyle.id.split("\\|")[1]; AirMapAirspaceType airspaceType = MappingService.AirMapAirspaceType.fromString(typeKey); airspaceTypeListener.onAirspaceTypeAdded(ruleset, airspaceType, layer); } map.getMap().getStyle().addLayerAbove(layer, layerStyle.id); } } // add highlight layer if (map.getMap().getStyle().getLayer("airmap|highlight|line|" + sourceId) == null) { LineLayer highlightLayer = new LineLayer("airmap|highlight|line|" + sourceId, sourceId); highlightLayer.setProperties(PropertyFactory.lineColor("#f9e547")); highlightLayer.setProperties(PropertyFactory.lineWidth(4f)); highlightLayer.setProperties(PropertyFactory.lineOpacity(0.9f)); Expression filter = Expression.eq(Expression.get("id"), "x"); try { highlightLayer.setFilter(filter); map.getMap().getStyle().addLayer(highlightLayer); } catch (Throwable t) { // https://github.com/mapbox/mapbox-gl-native/issues/10947 // https://github.com/mapbox/mapbox-gl-native/issues/11264 // A layer is associated with a style, not the mapView/mapbox Analytics.report(new Exception(t)); t.printStackTrace(); } } }