I have a dataset of polylines, markers and polygons stored as lat/lon data in a CSV file that need plotting in Android MapBox. I'm able to do this easily using mapboxmap.addPolyline, addMarker and addpolygons, but after adding hundreds of points scrolling the map and viewing the data on an Android phone becomes very slow.
Am I going about this wrongly? Is there a more efficient way to plot many data points that i'm supposed to be using?
What version of the Maps SDK are you using? Your use of addPolyline/addMarker/etc. makes me think that you're using a very outdated version. Please try using 8.5.0 and using sources/layers: https://docs.mapbox.com/android/maps/overview/data-driven-styling/
In general, you should use the lat/lon data in the CSV file to create Feature objects. Use them to create a FeatureCollection and then add/style layers.
Setting up a LineLayer
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
#Override
public void onStyleLoaded(#NonNull Style style) {
Feature polygonFeature = Feature.fromGeometry(Polygon.fromLngLats());
Feature lineStringFeature = Feature.fromGeometry(LineString.fromLngLats());
Feature pointFeature = Feature.fromGeometry(Point.fromLngLat());
FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[]{
pointPolygon, pointLineString, pointFeature
});
GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
style.addSource(geoJsonSource);
LineLayer lineLayer = new LineLayer("line-layer-id", "source-id");
lineLayer.setProperties(
PropertyFactory.lineColor(Color.BLUE)
);
style.addLayer(lineLayer);
}
});
Related
I am currently developing android map using mapbox sdk, and I want to add multiple markers when user click on one button. and I type below in my onStyleLoaded but it's not showing anything
List<Feature> symbolLayerIconFeatureList = new ArrayList<>();
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995560, 34.767070)));
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995979, 34.744110)));
symbolLayerIconFeatureList.add(Feature.fromGeometry(
Point.fromLngLat(31.995010, 34.767380)));
style.addImage("charge-icon-id", BitmapFactory.decodeResource(
MapboxNavigationActivity.this.getResources(), R.drawable.map_marker_dark));
style.addSource(new GeoJsonSource("charge-source-id",
FeatureCollection.fromFeatures(symbolLayerIconFeatureList)));
SymbolLayer destinationSymbolLayer = new SymbolLayer("charge-layer-id", "charge-source-id");
destinationSymbolLayer.withProperties(iconImage("charge-icon-id"),
iconAllowOverlap(true),
iconIgnorePlacement(true)
);
style.addLayer(destinationSymbolLayer);
May I ask what are the problem?
It's a bit tough to say without some more context/information, but I'm guessing that the issue is related to the order in which you're adding the source, layer, and image. Take a look at this example: https://docs.mapbox.com/android/maps/examples/marker-symbol-layer/
You'll want to add the image, source, and layer before the style is loaded. You can then make additional adjustments/add data when the style is loaded using the onStyleLoaded listener.
Disclaimer: I work at Mapbox.
Currently I am working on the adding a WMS source on the map in native android platform. I am using mapbox to show map in the application. I am trying to add a WMS source layer from Geo-server But the WMS source layer getting added multiple times over the map as shown in the picture :
Here is the code snippet which I have used to add WMS source :
#Override
public void onMapReady(MapboxMap mapboxMap) {
RasterSource webMapSource = new RasterSource(
"web-map-source",
new TileSet("tileset", "http://geo.skymetweather.com:8081/geoserver/cite/wms/cite:india_district_web?" +
"&bbox=68.036003112793,6.60812377929688,97.5504302978516," +
"37.2502937316895&format=image/png&service=WMS&version=1.1.1&" +
"request=GetMap&srs=EPSG:4326&width=493&height=512&layers=cite:india_district_web"), 256);
mapboxMap.addSource(webMapSource);
// Add the web map source to the map.
RasterLayer webMapLayer = new RasterLayer("web-map-layer", "web-map-source");
mapboxMap.addLayerBelow(webMapLayer, "aeroway-taxiway");
}
Please suggest if any thing wrong with the code or does anyone know how to add Raster Source on Map?
Thanks in advance !
Mapbox only supports 'EPSG:3857' for rendering WMS tiles and you should project your source to this SRS. Also, there is no need to set its bounding box statically as you did in second line of TileSet. Use this template to load WMS in your application:
RasterSource webMapSource = new RasterSource(
"web-map-source",
new TileSet("tileset",
'http://a.example.com/wms?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&width=256&height=256&layers=example')
,256);
I'm trying show all my map makers on Here maps, but I don't want cluster them to a number, like image. I used Here maps app, markers not clustered Here Maps.
What should I do ?.
You can find information about it here.
You can use the ClusterLayer class.
ClusterLayer cl = new ClusterLayer();
If you want to customize the image use their ImageClusterStyle & ClusterTheme.
ImageClusterStyle imageCluster = new ImageClusterStyle(img);
ClusterTheme theme = new ClusterTheme();
theme.setStyleForDensityRange(2, 9, imageCluster);
cl.setTheme(theme);
I have my own offline map data in my app but only for a small region. Now I'd like to overlay this data onto my Google Map V2. This also already works. The only thing missing now is that GoogleMaps still overlays it's road names / city names above my tiles.
Is it possible to display a google map V2 in Android with MAP_TYPE_NORMAL and overlay custom tiles above roads?
TileOverlay overlay = map.addTileOverlay(new
TileOverlayOptions().tileProvider(provider).zIndex(2000));
The zIndex does't seem to help me here.
I think there is no way to display your tile-layer over the road names/city names.
How about display your offline map as Marker?
It should be displayed on the top.
try this link for https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/TileOverlay &
EXAMPLE :
GoogleMap map; // ... get a map.
TileProvider tileProvider; // ... create a tile provider.
TileOverlay tileOverlay = map.addTileOverlay(
new TileOverlayOptions().tileProvider(tileProvider));
Hope this helps.
As far as I know, you cannot place TileOverlays or GroundOverlays on top of labels. Your best option might be to use a different map type. This can be changed after the map has been created (i.e. in the onMapReady method by using the mMap.setMapType(...) method). Here are some possibilities:
MAP_TYPE_NORMAL + Custom Map Style
You can easily create your own map styles by using the Styling Wizard. It allows you to create a style that excludes labels entirely (among other things). Once you've created a style you like, you can copy the JSON code generated by that website and add it to the project file res/raw/style_json.json. The style can then be applied like this:
mMap.setMapType( GoogleMap.MAP_TYPE_NORMAL );
try
{
boolean success = mMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
getContext(), R.raw.style_json ) );
if( !success )
{
Log.e( TAG, "Style parsing failed." );
}
}
catch( Resources.NotFoundException e )
{
Log.e( TAG, "Can't find style. Error: ", e );
}
MAP_TYPE_NONE + Custom Map Tiles
If you need to have labels outside of your TileOverlay, you could add a second TileOverlay of non-Google map tiles (like those provided by OpenStreetMap). These typically include the labels within the map tiles themselves. So if your TileOverlay is added with a higher z-index, it will appear on top of these other map tiles!
Map Types Without Labels
MAP_TYPE_SATELLITE and MAP_TYPE_NONE don't include labels. If you don't need any map data outside of your TileOverlay, using MAP_TYPE_NONE will save on mobile data.
I am trying to develop an offline android map that makes use of OSM map tiles of a particular zoom level, For this purpose I used an open source library : Osmdroid
Now, I am looking into the possibility of creating an offline geocoding/ reverse geocoding for a single city that can be integrated with my application,
can I use Osm xml data for that purpose? if so , then can anyone suggest/explain how to use it to create SQlite db.. to be used with my app
I read here and also here about Spatialite
But cannot quite understand its working and implementation
Thanks
With the Skobbler SDK you have offline maps and (reverse) geocoding.
This has an answer in here
https://stackoverflow.com/a/64811929/13794189
and goes as follows:
To use Open Street Maps (OSM) in offline mode you need to first implement a download manager like the one shown here on the post liked bellow. It has resume capabilities which is good for very large files :
https://stackoverflow.com/a/64811752/13794189
next you can load the downloaded OSM maps file in to a mapView like this:
org.osmdroid.config.IConfigurationProvider osmConf = org.osmdroid.config.Configuration.getInstance();
File basePath = new File(SessionData.offlineMapsDirectoryPath, "osmdroid");
osmConf.setOsmdroidBasePath(basePath);
File tileCache = new File(SessionData.offlineMapsDirectoryPath, "tile");
osmConf.setOsmdroidTileCache(tileCache);
map = (MapView) getActivity().findViewById(R.id.map); // create basic map
//map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
map.setTilesScaledToDpi(true);
map.setMultiTouchControls(true);
map.setUseDataConnection(false);
// add compass to map
//CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
//compassOverlay.enableCompass();
//map.getOverlays().add(compassOverlay);
//attach listeners
MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this);
map.getOverlays().add(0, mapEventsOverlay);
In the code above, SessionData.offlineMapsDirectoryPath is the path where the downloaded file is saved.
Don't forget to add in your gradle file the following implementations:
implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.github.MKergall:osmbonuspack:6.6.0'