Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

CustomLayer usage to add custom tiles as map layer #4210

Closed
pahakorolev opened this issue Mar 6, 2016 · 9 comments
Closed

CustomLayer usage to add custom tiles as map layer #4210

pahakorolev opened this issue Mar 6, 2016 · 9 comments
Labels
Android Mapbox Maps SDK for Android feature

Comments

@pahakorolev
Copy link

MapBox Android SDK has methods to work with CustomLayers:

com.mapbox.mapboxsdk.maps.MapboxMap.addCustomLayer(CustomLayer customLayer, String before)
com.mapbox.mapboxsdk.maps.MapboxMap.removeCustomLayer(String id)
com.mapbox.mapboxsdk.maps.MapboxMap.invalidateCustomLayers()

But using of those require native(cpp) implementation of CustomLayer like at your example.
It's so difficult, because we need to implement render and other parts of CustomLayer.
How about simple implementation for using raster tiles over rendered map like TileOverlay and UrlTileProvider from Google Maps SDK for example?
It is necessary first of all to support the rendering tiles from server side, which can contains a lot of data like polygons, polylines or paths, markers and images already rendered by server.
Here examples of tiles:

0539c9cef7e2e2b09c3145b03cdfc253 2

0539c9cef7e2e2b09c3145b03cdfc253 1

0539c9cef7e2e2b09c3145b03cdfc253

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Mar 6, 2016
@tobrun tobrun added this to the android-v4.1.0 milestone Mar 6, 2016
@tobrun tobrun added the feature label Mar 6, 2016
@1ec5
Copy link
Contributor

1ec5 commented Mar 6, 2016

CustomLayer isn’t intended for this use case. It sounds like you want something like this custom raster style example. If you want to overlay your raster tiles atop a GL style, such as Light, you can combine the existing Light stylesheet with the raster tile source in that example.

@pahakorolev
Copy link
Author

No, that's not what I meant. The custom tile layer can be added dynamically, e.g. user pressed some button. In your case I need to change style url and reload all data, which previously was added. And user can edit this layer by some request to a server, e.g. change period of history which he is seeing on the map. And so, I should be able to invalidate this layer, because server's tiles was changed.
If need be, I'm ready to show necessity of this feature at real cases and applications.

@1ec5
Copy link
Contributor

1ec5 commented Mar 6, 2016

Ah, thanks for the clarification. From the screenshots and explanation above, the raster tiles look simple enough that they could be represented more efficiently as GeoJSON rather than as raster images. (GeoJSON makes things like mapbox-gl-draw possible with the GL JS library.) The Android SDK has support for GeoJSON at the source level. #3630 tracks dynamically modifying GeoJSON layers at runtime, while #837 tracks dynamically adding and removing layers, paint properties, etc. As far as I know, the combination of those two features would enable the use case you’re describing.

@pahakorolev
Copy link
Author

Thank you for your answer. GeoJSON is a cool feature, but described by me functionality is not the same.
Firstly, which size of GeoJson we'll have, if it will contains about 1 million points? But it may contain more.
And secondly, I speak about existing solution. Our server side returning png tiles and change it's to GeoJSON will forces us to change a significant amount of our logic.
And a possibility of working with custom tiles is a basic functionality of any popular cartographical SDK.
For example:

and etc.

@1ec5
Copy link
Contributor

1ec5 commented Mar 6, 2016

In that case, I think #837 is the one you want to keep an eye on. Here’s what I mean: although this GL JS example uses a GeoJSON layer, there’s nothing that prevents you from calling addLayer() with a raster tile layer, and there are related methods like addSource() and removeLayer() as well.

@pahakorolev
Copy link
Author

Thanks for the explanation. If by this style I will be able to use raster tiles from any custom server - it will be a good solution.

val layer=map.addLayer({
"sources": {
            "raster-tiles": {
                "type": "raster",
                "url": "http://some.server",
                "tileSize": 512
            }
        }
"tiles": [
        "http://some.server/{z}/{x}/{y}/tile.png"
    ]
});
...//some code
map.invalidateLayer(layer); //or map.removeLayer(layer) and then map.addLayer({})
map.removeLayer(layer);

@bleege bleege modified the milestone: android-v4.1.0 Mar 18, 2016
@1ec5
Copy link
Contributor

1ec5 commented Mar 31, 2016

Image source support (#1350) may also be relevant to your use case.

@1ec5
Copy link
Contributor

1ec5 commented May 20, 2016

In your case I need to change style url and reload all data, which previously was added.

I missed this detail – you want to explicitly reload a raster tile source rather than adding and removing distinct raster tile sources at runtime. The iOS SDK does have a method for reloading the style, but it doesn’t bust the cache. (The only thing that currently busts the cache is the Cache-Control HTTP header: #4446 (comment)) Before we can introduce a cache-busting mechanism, we need to add support to our own servers for refreshing; we’re tracking that work internally.

@cammace
Copy link
Contributor

cammace commented Aug 4, 2016

@pahakorolev we've now added the runtime style API and closed #837, this exposes new ways to add a raster or GeoJSON layer to the map. For examples, I'd recommend taking a look at this ticket, there's a few examples showing how to add layers. To use in your application now, make sure you have the SNAPSHOT version of the SDK in your build.gradle.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android feature
Projects
None yet
Development

No branches or pull requests

5 participants