Is there an option to remove duplicate point labels within a distance in Mapbox Studio? - mapbox

I'm using Mapbox Studio to label some point features (from a GeoJSON layer I uploaded) in a style, and there are some duplicate points located nearby each other:
Are there any options in Mapbox Studio to remove the duplicate labels automatically? For example, some other mapping programs have the option to remove duplicate labels within a specified distance (pixels or map units). Is this available in Mapbox Studio (or failing that, in Mapbox-GL-JS)?

Mapbox Studio does not provide a way to remove the duplicate labels automatically. You could work with a filter to manually filter out duplicates by writing a relatively complex expression, although this is not really the intended use case of expressions. You could also add a duplicate: true property to duplicated point features in your source data, but since this would require manipulating your source data, you might as well remove the duplicates from the source data instead of taking this approach.
That being said, you could consider clustering your data and styling the clusters so that a cluster looks the same as any individual point. This example shows how to create and style clusters using Mapbox GL JS. Here is a JSFiddle that heavily modifies this example to cluster closely-located points, and style the clusters in the same way that individual points are styled: https://jsfiddle.net/uo216fxz/ (you will need to add your own Mapbox access token in order to view the result). Text labels are added with the point count for each cluster containing more than one point, so that you can easily see that clusters and single points are identical aside from the labeling.
You will likely need to customize several properties (such as clusterRadius, clusterMaxZoom, etc) beyond what is provided in the linked JSFiddle, to be more specific to your source data.

Related

Labelling multi polygons with the same geometry

In my dataset i have some polygons overlapped each other and I want to display their value in the label. In qgis we can do this as follows.
first step
Second step
multi labeling results in qgis
I am looking for a solution in mapbox studio to be able to do this.
There are some options like Expressions in Mapbox studio style but all are for working with labelling using multiple columns. But i need to have labelling based on multi features that have overlapping.

How can I convert a tileset to an Albers projection? Or add a feature to an albers projection that lines up correctly?

Mapbox studio has a style with an Albers projection (https://www.mapbox.com/elections/albers-usa-projection-style):
I need to use another style with waterbodies like this:
but in the Albers projection. When I start with the Albers style, and then add water, they of course don't line up:
How can I get the tile I used in my waterbody example to be in the Albers project? I ultimately am wanting to use it in a leaflet map and add markers to it (using R).
The example you cited above is actually showing a workaround to make data appear as if it is projected in Albers but it's really just altered polygons being displayed in webmercator. This was a workaround/hack to get the desired visual using the tools available at the time. If you want to do the same workaround for your water bodies data so it will appear this way in leaflet, follow the steps of the tutorial which uses third party tools (QGIS, Dirty Reprojectors, Tippecanoe)
Mapbox has since added support for non-webmercator projections, which means you don't need to modify your source data to reproject them for use in a mapboxgl-js map: https://docs.mapbox.com/mapbox-gl-js/example/projections/
Disregard the earlier example, and just change the projection to Albers in Mapbox Studio.
Bear in mind that changing the projection in Mapbox Studio does not actually modify your data, it just renders it differently on the screen.

Is there a function to select and show certain features only in print composer?

I have a feature layer with points. I have three pages in my print composer. On one of my pages, I only want to show points that fall within a certain value range. First, I tried locking the style on the pages where I want to display all my points.
Then, I went to the Query Builder of the layer I want to select points from, and I created an expression to display only points from a range:
The problem is that this selection modifies the points shown on all my pages in print composer, even the ones where I locked the layers and style for layers. The only alternative solution I can think of is to select the points I want to show, create a new feature layer with those selected points, and then show that feature layer on my page in print composer. However I'd like to know if there's another way to do this without creating a new feature layer each time I want to filter the points I show in print composer.
There's another way. The points change because when you define a query, basically you define what features will be loaded to the project. So if you use categorized symbology you can define that some feature will be not displayed, but they will stay loaded in the project.
Here you can find how to use this type of symbology: Classifying Nominal Data

MapBox. A highlight effect by hover event on table. SetData takes 2s for updating source with 6000 features

I'm trying to implement a highlight effect by hover effect on the table's row. I've got the data table related to Mapbox's point features. I update the map point's styles by my rxjs state (every change in the state calls styles updating on my map). For small features count, it works well, but it takes 2 seconds for updating styles on the map with 6000 points. Directly setData execution takes 150-200 ms, but rendering takes 1-3 seconds. How can I improve the performance of the Mapbox for my task? As I wrote, I have 6000 points on the map, and when I hover the cursor over a row in the table I want to change the style for2 points. Change of style implemented by changing the feature's layer (might that be the matter?).
Thanks for any ideas.
the github issue.
setFeatureState is the most efficient way to update the styling of a small number of features on a map with many features.
It does have certain limitations: it only works on layers with feature IDs, and not all styling can be controlled through feature state (notably, layout properties such as icon-image cannot).
Documentation here: https://docs.mapbox.com/mapbox-gl-js/api/#map#setfeaturestate
I found more productive way to highlight any resource. I just use another data-source for selected / highlighted resources and one or few style layers. You only need to put selected resources to another data-source and draw them according selected style. That don't affective to common data sources, and don't need to recompute resources states, just draw selected resource above based resources.

Is it possible to give different icons to a cluster group when it starts unclustering?

The red circles with numbers are clusters, but part of a bigger cluster when zoomed out.
Is it possible to change the marker/icon of the marker cluster in this present zoom depending on the markers that they have inside them? This without clicking them or anything, just change depending on the values of the markers that are hidden?
I have tried accessing the layer that is clustering all of them but I haven't been able to find the markers themselves, much less know how it would be possible to change the appearance of one without changing the other.
It looks like you already know how to customize your clusters appearance.
In the case your question refers only to the number of contained markers, you would just need to use a slightly modified version of the default iconCreateFunction to adjust the threshold values. When markers are removed/added from the MarkerClusterGroups and a cluster is de-/populated in consequence, its icon is re-drawn automatically. Customising the Clustered Markers
Now if you want this appearance to depend on some data from the contained markers, you would simply need to use cluster.getAllChildMarkers(); within your iconCreateFunction to get the array of markers contained within the cluster being styled. Then iterate through that array of markers, look for your data and create an icon accordingly.
Then, I understand that some data attached to your markers is changing, without any user action, and you want your clusters to update their appearance in consequence? In that case, please refer to this related question to upgrade your markercluster plugin with the new refreshClusters() method.
If your iconCreateFunction is properly designed, you do not have to worry about which clusters are changed. In fact, ALL clusters can be re-drawned, but if their markers data has not changed, they will get the same icon.