Is it possible to give each property in Mapbox a different color based on data that we have on the property? - mapbox-gl-js

Is it possible in the Mapbox GL JS to set a property color for each property? For each address we know if the property is an existing customer or not, so we would like to give properties of our customers a different color then the properties that are not our customers. Is something possible?
I already know how to set a color for all properties (followed this example: https://docs.mapbox.com/mapbox-gl-js/example/change-building-color-based-on-zoom-level/), but we like to have different colors based on the data that we have on the address/property.
Also wonder how we can map our data (address X is a customer) to a property in Mapbox GL JS.
Regards,
Nick

Related

Is there a way to set multiple layer filters in the Mapbox Static Images API?

I am using the mapbox static images API. I have two layers in my style that I'm trying to filter on the request. The documentation seems to only provide a single "setfilter" and a single "layer_id" property, indicating I can only filter one of the layers.
Is it possible to filter two (or three, four) layers in the static images API? I'd love to be able to comma separate the layer_id and/or setfilter parameters in the request to handle this case.
An example request they provide in the docs for setting the filters is:
https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/-91,60,2/800x600?access_token=YOUR_MAPBOX_ACCESS_TOKEN&setfilter=["==","name_en","Canada"]&layer_id=country-label
I am looking for something like:
https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/-91,60,2/800x600?access_token=YOUR_MAPBOX_ACCESS_TOKEN&setfilters=["==","name_en","Canada"],["==","name","New York"]&layer_ids=country-label,state-label
FWIW, my current workaround is to use an overlay for one of the layers to form the geojson objects that I needed filtering, but its hacky and has an upperbound on how many I can add to the request, and I had to simplify the geojson for brevity in the request.
Unfortunately there is not a direct way to reference multiple layers in a request to the Static Images API.
As a workaround you may be able to create a new style layer in Mapbox Studio that combines all of the layers you want to apply a filter to. You could then use setfilter on that layer to achieve filtering across these multiple layers, see the documentation here.

MapBox GL - Render GeoJson Thematically Based on Data in Client

I have a geoJson layer showing U.S. states, with only an ID, and no other properties.
I also have a local array of data in memory with lots of properties about those states: things like population, acres of farmland, sales tax rate etc. One of the properties is the ID that's in the geoJson layer. So I should be able to join the local array with features in the geoJson layer.
I would like to be able to thematically style the states based on any of those properties, allowing the user the ability to choose the property. All the examples I have seen for thematic styling of GeoJson layers in MapBox require (1) that the properties exist in the geoJson itself, and (2) that you define the property and styling rules in advance (I'm not sure if there's a way to change this at a later point).
In other map libraries, I think including Leaflet, you can define a paint function, and pass in the feature. Is there anything like this in MapBox GL?
Thanks.
You can make your life easier by joining the geojson data with your "properties" data into a single geojson feature collection.
Once you got that going, you can use map.setPaintProperty(layerId, ...) to update the layer style based on user interaction: https://docs.mapbox.com/mapbox-gl-js/api/#map#setpaintproperty
As of the documentation:
value(any) The value of the paint property to set. Must be of a type appropriate for the property, as defined in the Mapbox Style Specification .
You can set anything the style spec supports, even interpolated data-driven properties, wich means you can set & update any property of the layer you would be able to configure when newly adding that layer. Sure, you can not set multiple paint/layout properties with a single call, but that is something you can easily abstract away yourself.
This might be a bit far fetched, but assuming what you call a "theme" is just a collection of paint properties and values which you derived from an user interaction. You can just encode your "theme" as a valid mapbox style and use map.setStyle(...) to efficiently change multiple properties with a single call. Remeber setStyle() can receive a a style url but also a complete style object.

Binding Text Blocks in a Master to Shape Data on the Master

I'm returning to Visio after being a power user in the 2000's. A lot of what I'd do back in the day was create custom masters and associate data with the shape with individual labels etc. on those masters. Sort of a multi-part shape bound to the shape data on a given master, with fine-tuned arrangement.
The shapesheet seems entirely gone in 2016 Pro and now we have the data graphic features, which are nice and interesting, but they don't give you the same degree of fine-tuning and baked-in support that my old approach of building custom masters did.
How would I go about taking a text block on a master and binding it inside that master to the master's shape data for a given property? I'm betting it's a custom expression, but I'm not sure what the syntax would be.
Oh, my overall use case here: I want to have a shape with fine-tuned fields that are always visible, but appear in different compartments on the shape. I want to link external data into the shape and have the text blocks pull the value out of the shape data and render it for the area in question. I may use Data Graphics for ancillary things on a case by case basis, but at a core, I know I want certain features to always be present in a master and styled in certain ways.
to display the property of another shape you need to reference it in the form:
sheet!N.prop.X
N being the ID of the other shape, in your case the parent.
Store this value in a intermediate field, the use insert/field.
Here's a tool to do this automatically: http://visguy.com/vgforum/index.php?topic=6318.0
To handle input options to custom properties I recommend the following
1) set up a custom property of the page as semi-colon separated list for holding the desired values. eg: prop.myOption = "A;B;C"
2) in the shape needing this option, set up am according field as fixed list. In the format cell write: thePage!prop.options.
That's it. This way you can edit the list in one central place and have all the shapes updated.

Range field for alpaca

I'm trying to get a handle on alpacajs and wanted to see if it would be a good fit for a project i am working one.
I have a few sliders (..) that I need to get on the forms.
Is that possible with Alpaca JS or do I need to customize the data somehow?
How would the range be represented in the schema?
Thanks

Correct way to share view models MVVM?

I have ContractView. This is to be displayed from 2 separate tiles on my dashboard. One for baseload and one for peak load.
When showing baseload clips the title will be Baseload Clip Definition and when from the Peak Load tile on my dashboard, it will be Peak Load Clip definition
Likewise the ViewModel will need to get Baseload or Peak load clips depending on which tile the user has clicked on
I know one way I could do this is to make 2 separate copies but this seems totally wrong as it would duplicate the views.
On the view model size I am considering creating 2 seperate view models and inheriting them from a ClipDefinitionViewModel. The 2 new view model classes would then know the clip type to obtain from the data service
Is there a better way?
I am using Simple MVVM Toolkit
Paul
One class, two objects with different properties.
Have a Title property that you set when the VM is constructed (either pass into the constructor or set explicitly).
Likewise a LoadSource property can define where the VM should look for its definitions.