mapbox : fill-color expression depending of a value (not a color value) from the geojson - maps

how could I set the color of a shape depending of the value of one of its property in the geoJson ?
let's say I have this features collection :
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"district_type": "foo"
},
"geometry": {
"coordinates": [...],
"type": "Polygon"
}
},
{
"type": "Feature",
"properties": {
"district_type": "bar"
},
"geometry": {
"coordinates": [...],
"type": "Polygon"
}
}
]
}
And this array to match colors :
var colors = {
foo:'#111111',
bar:'#222222',
}
Now, I want to add a layer where the shapes have the color from my colors var, matching the distric_type property of the features.
map.addLayer({
'id': 'districts-fill',
'type': 'fill',
'source': 'geo-districts',
'paint': {
'fill-color': ..., //which expression here ?
'fill-opacity': 0.4
}
});
Thanks !

I found out... That's so nice !
map.addLayer({
'id': 'districts-fill',
'type': 'fill',
'source': 'geo-districts',
'paint': {
'fill-color': [
'match', ['get', 'district_type'],
'foo', '#111111',
'bar', '#222222',
'white'// otherwise
],
'fill-opacity': 0.4
},

Related

How to create array json schema for an array string which contains some fixed values and may have other additonal values

So I have this json schema:-
{
"type": "object",
"properties": {
"campaignType": {
"type": "string",
"enum": [
"export"
]
},
"clientid": {
"type": "integer",
"minimum": 1
},
"select": {
"type": "object",
"minProperties": 1,
"anyOf": [
{
"required": [
"list"
]
},
{
"required": [
"segment"
]
}
],
"properties": {
"list": {
"type": "array",
"items": {
"type": "integer"
}
},
"segment": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"attributes": {
"type": "array",
"minItems": 2,
"items": {
"type": "string",
"contains": ["fk", "uid"]
}
}
},
"required": [
"campaignType",
"clientid",
"select",
"attributes"
]
}
Here I want to have attributes field to have value "fk", "uid" fixed and must allow other field values with "fk" and "uid".
with this following code I am getting error while passing additonal values:-
{
"campaignType":"export",
"clientid":107311,
"select":{
"segment":[30]
},
"attributes":["uid","fk", "att1"]
}
error unmarshaling properties from json: error unmarshaling items from json: json: cannot unmarshal object into Go value of type []*jsonschema.Schema
how do I fix it?
The value of contains in your schema must be a schema:
According to your question, maybe change the "attributes" schema to:
"attributes": {
"type": "array",
"minItems": 2,
"items": [ { "const": "fk" }, { "const": "uid" } ],
"additionalItems": {
"type": "string"
}
}

Transform mongo arrarys

I have a collection, which contains documents like
{
"_id": ObjectId("60f561eb0d022a4c614966c1"),
"vehicleId": 288,
"startTime": [
ISODate("2021-06-19T13:00:19Z"),
ISODate("2021-06-19T13:00:40Z")
],
"odo": [0, 1116.0746443123298],
"location": [
{ "type": "Point", "coordinates": [75.759973, 26.977889] },
{ "type": "Point", "coordinates": [75.771209, 26.97858] }
]
}
I want to change the location array so that the document looks like
{
"_id": ObjectId("60f561eb0d022a4c614966c1"),
"vehicleId": 288,
"startTime": [
ISODate("2021-06-19T13:00:19Z"),
ISODate("2021-06-19T13:00:40Z")
],
"odo": [0, 1116.0746443123298],
"locations": [
{ loc: { "type": "Point", "coordinates": [75.759973, 26.977889] } },
{ loc: { "type": "Point", "coordinates": [75.771209, 26.97858] } }
]
}
that is, each entry becomes an object. I may want to do the same thing to odo and starttime.
I'm experimenting with aggregation pipelines, but I haven't found a way except using application code to read and transform the object.
I'd rather do it via a mongo-only way and not have use application and parse document by document, so any help with a mongo-only way would be much appreciated.
Would be this one:
db.collection.aggregate([
{
$set: {
location: "$$REMOVE",
locations: {
$map: {
input: "$location",
in: { loc: "$$this" }
}
}
}
}
])

How to add Single-field Exemptions in Firestore Index Config File

Please let me know how to add Index exemptions for Single-field, in the firebase-indexes.json file, in order to deploy through CLI.
Currently, below is my index config in the file firebase-indexes.json, able to deploy through CLI, but it is creating an index of type Composite, not as a Single-field Exemption.
{
"indexes": [
{
"collectionGroup": "comments",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "id",
"order": "ASCENDING"
},
{
"fieldPath": "id",
"order": "DESCENDING"
}
]
}
]
}
Thanks in advance.
Assuming that your collection is called "comments" and your exemption field is called "field", you will add a new property to your firestore.indexes.json called "fieldOverrides", like this:
{
"indexes": [
// your indexes here
],
"fieldOverrides": [
{
"collectionGroup": "comments",
"fieldPath": "field",
"indexes": [
{
"order": "ASCENDING",
"queryScope": "COLLECTION"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION"
},
{
"arrayConfig": "CONTAINS",
"queryScope": "COLLECTION"
},
{
"order": "ASCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"order": "DESCENDING",
"queryScope": "COLLECTION_GROUP"
},
{
"arrayConfig": "CONTAINS",
"queryScope": "COLLECTION_GROUP"
}
]
}
]
}

get dynamic data from the slot ? not added resolutionsPerAuthority's dynamic element in the list

I am trying to get dynamic data from the slot
As per documentation and my basic test I am sending directive from launch request as like :
{'version': '1.0', 'response': {'outputSpeech': {'type': 'SSML', 'ssml': '<speak> Hi, welcome to developement dynamic slot. <break time="800ms"/>Please tell me the product name you would be interested in</speak>'}, 'card': {'type': 'Simple', 'title': 'Choose a Medicine.', 'content': 'Pick a Medicine.'}, 'reprompt': {'outputSpeech': {'type': 'SSML', 'ssml': '<speak><break time="5s"/>I am HERE to help You, Please tell me the product and country names you would be interested in.</speak>'}}, 'shouldEndSession': False}, 'directives': [{'type': 'Dialog.UpdateDynamicEntities', 'updateBehavior': 'REPLACE', 'types': [{'name': 'products', 'values': [{'id': 'grnTea', 'name': {'value': 'green tea', 'synonyms': ['matcha']}}, {'id': 'oolTea', 'name': {'value': 'oolong', 'synonyms': ['chinese tea', 'black dragon tea']}}]}]}]}
and when I'm trying to get data which is not statically store in a slot but added in directive slot value.
returns following output :
{ "version": "1.0", "session": { "new": false, "sessionId": "amzn1.echo-api.session.671181ed-1e50-4e4c-b70e-4d854fe7cb78", "application": { "applicationId": "amzn1.ask.skill.c35cd12c-6845-473e-be58-9b1139ee0adb" }, "user": { "userId": "amzn1.ask.account.sadasdsa", "permissions": { "consentToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ..XyWgyUIjDzzlZ12CR0lbZid6GxwZZYBgarlV-9difbkFjOTxrcvS9lJYWo-Db3wo-fIdXb_jZkCAJBtYPggqnJhLyyC-EDa0_u9aARKthF1_nkbLh5zDOHDb8MyyOYro4BJlqm4XBNd1qyeQUV2M4fdca1YSEnbEun_6kWOKeFRS-14zcwMj5E-MHcBbeDX799A_kay82kS8VGeMhSUsXPTZFrwOKHcFweJTqXFNOkBxME8kAFfS1JB5MNbA3TujVIsIgTBSNQaJeHRksConKt0u06ATrjffzFkcmbxDT5HoJH4NqDgS0y_GdtaeXQM3LJ-MN0-_DMX2QVEaL6kUUw" } } }, "context": { "System": { "application": { "applicationId": "amzn1.ask.skill.c35cd12c-6845-473e-be58-9b1139ee0adb" }, "user": { "userId": "amzn1.ask.account.aasdasdasdasdas", "permissions": { "consentToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.asdjaskdhas.XyWgyUIjDzzlZ12CR0lbZid6GxwZZYBgarlV-9difbkFjOTxrcvS9lJYWo-Db3wo-fIdXb_jZkCAJBtYPggqnJhLyyC-EDa0_u9aARKthF1_nkbLh5zDOHDb8MyyOYro4BJlqm4XBNd1qyeQUV2M4fdca1YSEnbEun_6kWOKeFRS-14zcwMj5E-MHcBbeDX799A_kay82kS8VGeMhSUsXPTZFrwOKHcFweJTqXFNOkBxME8kAFfS1JB5MNbA3TujVIsIgTBSNQaJeHRksConKt0u06ATrjffzFkcmbxDT5HoJH4NqDgS0y_GdtaeXQM3LJ-MN0-_DMX2QVEaL6kUUw" } }, "device": { "deviceId": "amzn1.ask.device.ajshdjkhasjkhdkjsahkasdhjasd", "supportedInterfaces": {} }, "apiEndpoint": "https://api.eu.amazonalexa.com", "apiAccessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjEifQ.asdhjashjdhajsd.RQhzWmnhN9K_dCbsFXBPPoLVzuwe5BWjAruwJNF1pVr11PiygVgQ64W3CNng2sK1thT2tl6r3GuRtG-1133Aw1KPWtMuHElu7CTrFfgAqW8blpK37PJIvPMOUGBw1rbrgCTMdy8Ua7qSFV_Y_wlOJaV3-apDGBqhQKE_-dE-ntWYZuIySlY3l8hBs_66eELS-LiL5DEDJk1hfvC2C6ZFB7A7P8mx4Hb71km-lYaElJS0-FDP0C-LdSp6dCbzV23W4JehtTGL4kJ1JEQgWyuNAAkt_HmPcEYlPp8T5RFceDuVuz-ZZBFyiVKuAN8VmxyFsmnC3SXi4yb3RKm1SCcorg" }, "Viewport": { "experiences": [ { "arcMinuteWidth": 246, "arcMinuteHeight": 144, "canRotate": false, "canResize": false } ], "shape": "RECTANGLE", "pixelWidth": 1024, "pixelHeight": 600, "dpi": 160, "currentPixelWidth": 1024, "currentPixelHeight": 600, "touch": [ "SINGLE" ], "video": { "codecs": [ "H_264_42", "H_264_41" ] } }, "Viewports": [ { "type": "APL", "id": "main", "shape": "RECTANGLE", "dpi": 160, "presentationType": "STANDARD", "canRotate": false, "configuration": { "current": { "video": { "codecs": [ "H_264_42", "H_264_41" ] }, "size": { "type": "DISCRETE", "pixelWidth": 1024, "pixelHeight": 600 } } } } ] }, "request": { "type": "IntentRequest", "requestId": "amzn1.echo-api.request.0f3b51f1-880b-483f-8410-3210e81e5b59", "timestamp": "2020-01-01T11:48:09Z", "locale": "en-IN", "intent": { "name": "productcheck", "confirmationStatus": "NONE", "slots": { "products": { "name": "products", "value": "green tea", "resolutions": { "resolutionsPerAuthority": [ { "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.c35cd12c-6845-473e-be58-9b1139ee0adb.products", "status": { "code": "ER_SUCCESS_NO_MATCH" } } ] }, "confirmationStatus": "NONE", "source": "USER" } } } } }
It's not added resolutions resolutionsPerAuthority's second(dynamic) element in the list.
anybody can help me out from this problem?
I tested your added directive exactly as pasted and the dynamic entity resolved as expected:
"slots": {
"products": {
"name": "products",
"value": "matcha",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.****.products",
"status": {
"code": "ER_SUCCESS_NO_MATCH"
}
},
{
"authority": "amzn1.er-authority.echo-sdk.dynamic.amzn1.ask.skill.****.products",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "green tea",
"id": "grnTea"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
Could you share your skill's interaction model to investigate further?

How to I access many layers into a json array? Angularjs

After fighting with this for a couple of hours, I think I need to rephrase the question.
I have an object that contains and array of objects;
Playlist: [
{
"added_at": "2015-11-13T20:55:06Z",
"added_by": {
"external_urls": {
"spotify": "http://open.spotify.com/user/spotify_canada"
},
"href": "https://api.spotify.com/v1/users/spotify_canada",
"id": "spotify_canada",
"type": "user",
"uri": "spotify:user:spotify_canada"
},
"is_local": false,
"track": {
"album": {
"album_type": "album",
"available_markets": [
"CA",
"MX",
"US"
],
"external_urls": {
"spotify": "https://open.spotify.com/album/6Fr2rQkZ383FcMqFyT7yPr"
},
"href": "https://api.spotify.com/v1/albums/6Fr2rQkZ383FcMqFyT7yPr",
"id": "6Fr2rQkZ383FcMqFyT7yPr",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/8b47495ce0c4a341f7196f70bcf4361e6257c1a0",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/da1e8958b6260e832660d0c5f3c80e9569c388c8",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/478dbfd0e579dee7392707b9a6848faff0cdfefd",
"width": 64
}
],
"name": "Purpose (Deluxe)",
"type": "album",
"uri": "spotify:album:6Fr2rQkZ383FcMqFyT7yPr"
},
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/1uNFoZAHBGtllmzznpCI3s"
},
"href": "https://api.spotify.com/v1/artists/1uNFoZAHBGtllmzznpCI3s",
"id": "1uNFoZAHBGtllmzznpCI3s",
"name": "Justin Bieber",
"type": "artist",
"uri": "spotify:artist:1uNFoZAHBGtllmzznpCI3s"
}
],
"available_markets": [
"CA",
"MX",
"US"
],
"disc_number": 1,
"duration_ms": 205680,
"explicit": false,
"external_ids": {
"isrc": "USUM71511919"
},
"external_urls": {
"spotify": "https://open.spotify.com/track/4B0JvthVoAAuygILe3n4Bs"
},
"href": "https://api.spotify.com/v1/tracks/4B0JvthVoAAuygILe3n4Bs",
"id": "4B0JvthVoAAuygILe3n4Bs",
"name": "What Do You Mean?",
"popularity": 93,
"preview_url": "https://p.scdn.co/mp3-preview/13da79dc4803f65092d583f6e3bdf1fc4d8344e5",
"track_number": 3,
"type": "track",
"uri": "spotify:track:4B0JvthVoAAuygILe3n4Bs"
}
},
In side of each of these objects is another object I am trying to assign to scope.
So this - playlist {items [ {track {name: songname} } ] }
How do I go about assigning the track.name to scope?
Thanks!
I'm not sure if you just have a typo but why are you assigning your blank array to data.items instead of the other way around?
$scope.playListInfo = [];
$scope.getPlayList = function() {
Spotify.getPlaylistTracks('spotify_canada', '7ndCD5pklOTcrTcv4DErmI')
.then(function(data) {
var i = 0;
for(i; i < data.items.length; i++) {
var dataToKeep = {};
dataToKeep.name = data.items[i].track.name;
dataToKeep.artist = data.items[i].track.artist;
$scope.playListInfo[i] = dataToKeep;
}
});
};
Apparently, I don't have sufficient points to comment. So, I am creating this post.
The JSON data has items and not item. Also, I think you'd have to create a $scope.playlistTrack array outside the function.
$scope.playlistTrack = [];
$scope.getPlayList = function () {
Spotify.getPlaylistTracks('spotify_canada', '7ndCD5pklOTcrTcv4DErmI')
.then(function (datas) {
angular.forEach(datas, function(data){
data.items = $scope.playlistTrack;
});
});
};
Hope this answer helps.

Resources