mapbox / mapbox-gl-native

Interactive, thoroughly customizable maps in native Android, iOS, macOS, Node.js, and Qt applications, powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
4.38k stars 1.32k forks source link

Disappearing clusters when style from URL #13966

Closed piotr-chebdowski-intive closed 4 years ago

piotr-chebdowski-intive commented 5 years ago

Steps to reproduce

  1. Take any clustering example, like this one https://docs.mapbox.com/android/maps/examples/create-and-style-data-clusters/
  2. Observe that everything is ok
  3. Change style source from built in like Style.LIGHT to URL, example: Style.Builder().fromUrl("https://www.mapbox.com/android-docs/files/mapbox-raster-v8.json")

Expected behavior

Everything is ok like when using Style.LIGHT

Actual behavior

Clusters will disappear if there is attached layer with: textField(Expression.toString(get("point_count"))) For example: val count = SymbolLayer("count", "earthquakes") count.setProperties( textField(Expression.toString(get("point_count"))), textSize(12f), textColor(Color.WHITE), textIgnorePlacement(true), textAllowOverlap(true) ) loadedMapStyle.addLayer(count)

So in order to make it work you need to use build in style or comment out the line textField(Expression.toString(get("point_count"))), But then you would not have labels with feature count. Or don't use labels at all. Unclustered layer is working ok. If I will zoom in I can see unclustered features.

Android versions: all Device models: all Mapbox SDK versions: 7.1.2

tobrun commented 5 years ago

@piotr-chebdowski-intive are you replacing the style in the example in step 3 or calling it after the style has loaded?

In case of the latter, when setting a new style you will remove all the underlying layers and sources attached to the previous style.It's expected that the clustered layers and sources aren't visible anymore with the newly loaded style, you will have to recreate and add them again.

fwiw, we have a cluster test defined in https://github.com/mapbox/mapbox-gl-native/blob/master/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/GeoJsonClusteringActivity.java.

I don't have an issue showing clusters on either Style.Light or Style.Sattelite (which is raster based):

image

image

S-ido commented 5 years ago

@tobrun I don't have either :) As I wrote everything is ok when you use Style.LIGHT Style.SATTELITE and other constants. Like this: map.setStyle(Style.SATELLITE) { style -> addClusteredGeoJsonSource(style) }

The problem is when you try this: map.setStyle(Style.Builder().fromUrl("https://www.mapbox.com/android-docs/files/mapbox-raster-v8.json")) { style -> addClusteredGeoJsonSource(style) }

I'm not replacing style. It's done in initialization. And I can still see unclustered features. Or even clusters if I disable labels.

I've chacked the GeoJsonClusteringActivity you mentioned and it's the same. If you replace line 90 .fromUrl(Style.LIGHT) with this .fromUrl("https://www.mapbox.com/android-docs/files/mapbox-raster-v8.json") then you can see only unclustered features. But if you also comment out line 189 textField(Expression.toString(get("point_count"))), then clusters will be back, but without labels of course.

tobrun commented 5 years ago

@S-ido thank you for adding that additional information. Trying to load that URL I'm seeing:

E/Mbgl-HttpRequest: [HTTP] Unable to parse resourceUrl 

Debugging that step I'm seeing the resourceUrl is an empty string. There is an issue with that style definiton but haven't been able to track down what concretely.

Update: actually afterwards the resource urls are correctly filled up.

S-ido commented 5 years ago

I can confirm that when line textField(Expression.toString(get("point_count"))), is uncommented I have E/Mbgl-HttpRequest: [HTTP] Unable to parse resourceUrl error and clusters are not visible. The map is working ok. Unclustered layer is visible. I've tested on local json this time. .fromUrl("asset://OSMapStyleStandard.json")

{
    "version": 8,
    "name": "Standard Map",  
    "sources": {
        "mapbox-standard-source": {
            "type": "raster",
            "tiles":  [ "https://api.mapbox.com/v4/ordnancesurvey.a6f1854b/{z}/{x}/{y}@2x.png?access_token=token" ],
            "tileSize": 256
        }
    },
    "layers": [
        {
            "id": "mapbox-standard-layer",
            "type": "raster",
            "source": "mapbox-standard-source"
        }
    ]
}
AlexanderEggers commented 5 years ago

@tobrun This issue is similar to https://github.com/mapbox/mapbox-gl-native/issues/13945 (that I created a few days ago).

natalia-osa commented 5 years ago

I have the same issue but on iOS. When I'm using:

clusterLayer.text = [NSExpression expressionWithFormat:@"CAST(point_count, 'NSString')"];

with default MapBox layers (without any URL config) it's working fine and the digits are displayed properly. However when this code:

[mapView setStyleURL:@"anyUrlHere_AllNotWorking"];

with any custom link (including MapBox ones) is called, I can see the following warning in the console and the clusters on the map are missing:

[ERROR] {}[Style]: Failed to load glyph range 0-255 for font stack Open Sans Regular,Arial Unicode MS Regular: unsupported URL

Also, a moment before the warning is displayed the app stops on the Thread 1 (so main):

CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__:

(I have exception breakpoints enabled, but nothing else stops the execution).

After reading @Mordag thread, I can specify that on iOS it happens from the launch/installation, has no connection with neither cache nor internet reachability. However the issues on github are connected, probably it's the same reason for all 3 of them, with various aspects. Something is wrong with font configuration when using style URLs.

iOS versions: all Device models: all Mapbox SDK versions: 4.9.0

natalia-osa commented 5 years ago

It's worth to add, that setting:

clusterLayer.text = [NSExpression expressionForConstantValue:@"12345"];

works properly. So probably it is connected with casting point_count.

Anyway, this issue surely is not Android-only.

cabelloruizcarlos commented 5 years ago

Hi! I facing the same issue than @natalia-osa and @piotr-chebdowski-intive. The unclustered layer works but the clustered ones never appear. I m working on Android btw

I m not changing the style, I m just loading one from a URL. I used the sample and it works good if I set a default style(like LIGHT for example). I tried also replacing setStyle(Style.Builder().fromUrl by setStyle(Style.Builder().fromUri but it didn't work

I test it using the version 7.0.0 , 8.0.0 and 8.3.0 of the library with no luck :(

I also try to make it work following the @Mordag issue assigning a System font --> textFont(arrayOf("Open Sans Regular")) and without any assignment but its not working

@tobrun I saw you labeled it with needs info. I need to solve this asap so ask me whatever you may need.

Thanks in advance guys

P.D: I also tried writing a literal instead of the "point_count" but same same

stale[bot] commented 4 years ago

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

dshazly commented 4 years ago

how did you fix this issue?

felixkrautschuk commented 4 years ago

@piotr-chebdowski-intive @cabelloruizcarlos have you found a fix or a workaround for this issue on Android in the meantime?

felixkrautschuk commented 4 years ago

Just in case anyone else is stumbling over this: In my case this issue was caused by the fact, that I am using a local style json file instead of the default Mapbox Styles (or even a custom style from our Mapbox Studio account) and I could fix it by adding the following line to my style json file:

"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"

(as mentioned in other Github threads: https://github.com/mapbox/mapbox-gl-native-ios/issues/122 and https://github.com/react-native-mapbox-gl/maps/issues/481#issuecomment-570777698)

Now the cluster circles and numbers appear as expected on Android and iOS.

Chenshuai770 commented 1 year ago

@felixkrautschuk it not use ,can you write it anymore