Create bubbles from geojson with Kendo UI - kendo-ui

I have a geojson file with a collection of points:
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {
"name": "Point one",
},
"geometry": {
"type": "Point",
"coordinates": [13,52]
}
},...
By default those points are displayed as a standard location marker.
$("#map").kendoMap({
center: [52, 13],
zoom: 10,
layers: [{
type: "shape",
dataSource: {
type: "geojson",
transport: {
read: function(e) {
e.success(myPoints);
}
}
}
}]
});
});
But I want to display the points as bubbles. Searching for; how to display geojson data with kendo ui, then I only find tutorials of layer type: shape in combination with geojson polygons. If I read the kendo ui tutorials for type bubble, then there is a value field to define the radius, which is not defined in geojson data. How to edit the standard marker display of geojson points? Or how to setup the properties of a bubble layer with respect to a geojson data input?

Through the layerDefaults.marker.shape you can customize the marker and even set a custom icon for the marker, as shown here.
To show bubbles with different size add a bubble layer. Here is a dojo with a GeoJSON map and a bubble layer, with the bubble diameter being based on population value.
Edit:
The bubble layer expects data in the following format
[
{
"City":"City A",
"Country":"USA",
"MyValueField":123456789,
"MyLocationField":[
45.2,
24.33
]
},
{
"City":"City B",
"Country":"USA",
"MyValueField":123456789,
"MyLocationField":[
34.47,
95.28
]
}
]
If the endpoint returns the data in a different format you can use the schema.parse function to parse the response in the expected format:
{
type: "bubble",
dataSource: {
transport: {
read: {
url: "https://get/my/data",
dataType: "json"
}
},
schema: {
parse: function(response) {
// parse response to match expected format
return response;
}
}
},
locationField: "MyLocationField", //The Map accepts a [Latitude, Longitude] format for its locations field
valueField: "MyValueField"
}

Related

Is Weaviate compatible with fielded search?

I'm working with a dataset that contains multiple fields. I need to conduct searches on several fields simultaneously. Is Weaviate compatible with fielded search? If that is the case, I'd appreciate it if you could instruct me on how to combine many search queries.
This is a scheme:
schema = {
"classes": [{
"class": "Post",
"vectorizer": "none", # explicitly tell Weaviate not to vectorize anything, we are providing the vectors ourselves through our BERT model
"properties": [{
"name":"pmid",
"dataType": ["int"],
},
{
"name":"title",
"dataType": ["text"],
},
{
"name": "body",
"dataType": ["text"],
},
{
"name":"summary",
"dataType": ["text"],
}]
}]
}
I'd want to do a simultaneous search on the body and summary. For instance, it identifies publications that have the term "HIV" in their body and summary.
This is certainly possible. Check out the where-filter in the Weaviate docs :-)
Example based on your example schema.
{
Get {
Post(
nearVector: {
vector: [0, 0, 0] # <== your custom vector
}
where: { # <== searching for a pmid > 12
operator: GreaterThan
valueInt: 12
path: ["pmid"]
}
) {
pmid
title
}
}
}

vega-lite scatter plot with hyperlink on each data point is not clicking

I am following this documentation on making href channel inside the encoding of a vega-lite scatter plot.
The data I am using is from an elasticsearch index. This is my code for the plot:
{
$schema: https://vega.github.io/schema/vega-lite/v4.json
data: {
url: {
%context%: true
index: my_index
body: {
size: 10000
}
}
format: {
property: hits.hits
}
}
transform: [
{
calculate: datum._source.price
as: price
}
{
calculate: datum._source.size
as: size
}
{
calculate: "'https://www.example.com/'+datum._source.id"
as: url
}
]
layer: [
{
selection: {
grid: {
type: interval
bind: scales
}
}
mark: {
type: circle
tooltip: true
}
encoding: {
x: {
field: size
type: quantitative
}
y: {
field: price
type: quantitative
}
href: {
field: url
}
}
}
]
}
The code works and on hovering over the scatter points, the mouse changes to a recognised link however the click itself does not work. why is that? the only differences from the documented example is that the data is from elasticsearch and I have a second layer in the plot.
How can I make the hyperlinks work?
To enable the click selection, you need to provide a selection of type: single. Try click the points in the link of editor or try the sample below:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Using `labelExpr` to show only initial letters of month names.",
"data": {"url": "data/seattle-weather.csv"},
"mark": "circle",
"transform": [
{
"calculate": "'https://www.google.com'",
"as": "url"
}
],
"selection": {"select": {"type": "single"}},
"encoding": {
"href": {"field": "url"},
"x": {
"timeUnit": "month",
"field": "date",
"axis": {"labelAlign": "left", "labelExpr": "datum.label[0]"}
},
"y": {"aggregate": "mean", "field": "precipitation"}
}
}

How to explicitly set schema field type to [SanityImage]

I want to set an images field in my document to an array of type [SanityImage].
I have tried setting it to type: 'image' but when I query the field I get that the type is [SanityCollectionItemsImages]
The images field is found inside an object (productVariant) which is then included in the main document (collection) where I have an array of productVariants in my items field.
Inside the fields array of my collection document:
...
{
title: "Items",
name: "items",
type: "array",
of: [
{
title: "Item",
type: "productVariant",
},
],
},
...
The productVariant type object:
export default {
title: "Product variant",
name: "productVariant",
type: "object",
fields: [
{
name: "images",
title: "Images",
type: "array",
of: [
{
type: "image",
options: {
hotspot: true,
},
},
],
},
...
My query using GraphQL:
allSanityCollection {
edges {
node {
_id
title
description
items {
_key
title
images {
asset {
_ref
_id
fluid(maxHeight: 600) {
base64
aspectRatio
src
srcSet
srcWebp
srcSetWebp
sizes
}
}
}
}
}
}
}
When I click on the the images field inside the GraphiQL web IDE:
Using Sanity.io HTTP API to get the whole document:
"images": [
{
"_key": "5605f5383975",
"_type": "image",
"asset": {
"_ref": "image-14f9b7688912499f187b7c20e57816b3cdf42c1e-4016x4688-jpg",
"_type": "reference"
}
},
...
My question is how to set the type of a field in my schema to be explicitly [SanityImage] instead of [SanityCollectionItemsImages] and why do I get that weird type?
The Sanity schema looks totally sane, and the API delivers the proper data structure as you say, so the problem seems to be related to the Gatsby and GraphQL layer of things.
I'll recommend making sure you are using the latest versions of the CLI, Studio and Sanity Gatsby plugin and see if that makes things better as development on the Gatsby source plugin is moving fast.

How do you convert TopoJSON linestring to polygon?

I have a TopoJSON file containing the boundaries of various districts in Uttar Pradesh, India. When you load the data on a map, you see only the outlines of the districts; the districts themselves are not filled.
I believe the problem is that each district is of type GeometryCollection that has its own geometries made up of a series of LineStrings.
Instead, I want each district to be of type Polygon that just has arcs.
For example, the first object is:
{
"type": "GeometryCollection",
"geometries": [{
"type": "GeometryCollection",
"properties": {
"district_number": 1,
"district_name": "Ghaziabad"
},
"geometries": [{
"type": "LineString",
"arcs": [0]
}, {
"type": "LineString",
"arcs": [1]
}, {
"type": "LineString",
"arcs": [2]
}, {
"type": "LineString",
"arcs": [3]
}, {
"type": "LineString",
"arcs": [4]
}, {
"type": "LineString",
"arcs": [5]
}]
}
I think I want to convert it, and every other object, to:
{
"type": "Polygon",
"properties": {
"district_number": 1,
"district_name": "Ghaziabad"
},
"arcs": [[0,1,2,3,4,5]]
}
I could fix it manually, but that seems insane. Is there a better way?
Update
So I figured out how to convert the object into the result I thought I wanted, but I got some very wacky polygons. Here is my (very clunky) code. Thanks to Saeed Adel Mehraban for some guidance with this.
d3.json('map.topojson',function(error,data){ // get my json that needs to be converted
var arr = data.objects.collection.geometries; // this is the relevant array
var newArr = []; // in order to map each object, i need to put each one into a new array as a single-item array
arr.forEach(function(d,i){
var curr = [d];
newArr.push(curr);
})
newArr.forEach(function(e,i){ // now that i have my new array, i want to convert each object that contains a LineString into a Polygon
var output = e.map(function(d){
var arcsArr = []; // an empty array to push each single value of the LineString arcs into
return {
"type": "Polygon", // change the type to polygon
"properties": d.properties, // keep the properties
"arcs": d.geometries.map(function(g) { // a single key-value pair for arcs, made up of the individual arcs from the LineString
arcsArr.push(g.arcs[0]);
return [arcsArr]; // the array of arcs must be in another array
})
};
});
var output = output[0]; // get only the first item in the output array, which is the object i have modified
output.arcs = output.arcs[0]; // and change the arcs so we're only taking the first array (as we've duplicated the arrays)
$('body').append(JSON.stringify(output)+','); // append the whole thing to the body so I can copy it and paste it into the appropriate part of the JSON
});
});
This "worked" in the sense that my LineStrings were indeed converted to Polygons, retaining the original border. But the polygons themselves are a nightmare, with straight lines crisscrossing the map at all kinds of angles.
Is there something like a command line tool that can convert boundaries made of LineStrings into Polygons?
I believe I ran into the same problem being described.
This is Zambia drawn as a svg polyline foreach arc (red being the first arc listed, and magenta being the last):
However when attempting to create a polygon by concatenating the arcs:
What happened was the arcs for every object were listed clockwise, but the points in every individual arc were listed counterclockwise. Without seeing the topojson that OP is using I cannot 100% confirm this, but I suspect that this was the case.
I solved this by reversing the points in an arc before pushing them to the array of points to draw the polygon and now all is well:
Maybe a map function like below? (I write that with simplistic assumption about data schema. I can't guarantee that it works for complex linestrings since I'm not familiar with topojson format. But it works with your provided data)
var foo = [
{
"type": "GeometryCollection",
"geometries": [{
"type": "GeometryCollection",
"properties": {
"district_number": 1,
"district_name": "Ghaziabad"
},
"geometries": [{
"type": "LineString",
"arcs": [0]
}, {
"type": "LineString",
"arcs": [1]
}, {
"type": "LineString",
"arcs": [2]
}, {
"type": "LineString",
"arcs": [3]
}, {
"type": "LineString",
"arcs": [4]
}, {
"type": "LineString",
"arcs": [5]
}]
}]
}
];
var bar = foo.map(function(d) {
return {
"type": "Polygon",
"properties": d.geometries[0].properties,
"arc": d.geometries.map(function(g1) {
return g1.geometries.map(function(g) {
return g.arcs[0];
});
})
};
});
console.log(bar);

How to perform case-insensitive sort in Kendo Tree view?

I am using the below code to sort the value of the tree, it seems like the sorting happens based on CASE.
I am trying to figure out a way to perform case insensitive sorting, can someone please help me?
if(sortValue == 'Ascending') {
$("#groupTree").data("kendoTreeView").dataSource.sort({ field: "text", dir: "asc" });
} else if(sortValue == 'Descending') {
$("#groupTree").data("kendoTreeView").dataSource.sort({ field: "text", dir: "desc" });
}
Even that your question says "sort in Kendo Tree View" it actually refers to Kendo DataSource.
Said so, it is not supported BUT in KendoUI forums there is solution that might work. Check it here
Just thought of listing a sample code to help others who are in search of a work around to perform case-insensitive sorting when using Kendo datasource.
var homogeneous = new kendo.data.HierarchicalDataSource({
data: [{
"id":"1237",
"text":"b",
"encoded":false,
"items":[{
"id":"234",
"text":"b1",
"encoded":false,
"items":[{
"id":"456",
"text":"se",
"encoded":false,
"items":[{
"id":"567",
"text":"BB",
"encoded":false
}]
}]
}]
}, {
id: 1,
// lowercase foo should be after 'text:b' in case-insensitive sort
text: "foo"
}],
schema: {
parse: function(data) {
for (var i = 0; i < data.length; i++) {
data[i].lowerText = data[i].text.toLowerCase();
}
return data;
},
model: {
id: "id",
children: "items"
}
},
sort: { field: "lowerText", dir: "asc" }
});
$("#tree").kendoTreeView({
dataSource: homogeneous
});

Resources