How can I bind groupby data to a amcharts map - json

I am facing problem while binding data to a map.
How I was binding data before. I had JSON data as records format
{
"latitude":39.7645187,
"longitude": -104.9951976,
"name": "ORCL",
"value":32,
"activeProducts":"127",
},
{
"latitude":49.619446,
"longitude": -128.695623,
"name": "RCXC",
"value":72,
"activeProducts":"789",
},
From above data, directly I was using lat, long to show circle on the map. name, value and activeProducts for tooltip.
Now I have grouped data based on name field which came after using reduce clause
CDFN: (26) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
HCDR: (33) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
HVBL: (87) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
PCMD: (16) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}
Each single group have same data like lat, long, name. value(shown in first JSON data) is the count of each group records(CDFN: (26)). Data looks like this after expanding
{
"latitude":39.7645187,
"longitude": -104.9951976,
"name": "CDFN",
"activeProducts":"127",
"totalproducts":"140"
},
{
"latitude":49.619446,
"longitude": -128.695623,
"name": "HCDR",
"activeProducts":"789",
"totalproducts":"810"
},
Now my question
from above groups CDFN, HCDR, HVBL etc how can I get let and long of one records only to bind to map.
This is code I am using currently
public productsLocMap()
{
this.mapChart = am4core.create("stationsMap", am4maps.MapChart);
this.mapChart .geodata = am4geodata_worldLow;
this.mapChart .projection = new am4maps.projections.Miller();
this.polygonSeries = this.mapChart .series.push(new am4maps.MapPolygonSeries());
this.polygonSeries.useGeodata = true;
this.polygonSeries.strokeWidth = 0.5;
let imageSeries = this.mapChart .series.push(new am4maps.MapImageSeries());
imageSeries.dataFields.value = "value";
var place = imageSeries.mapImages.template;
place.nonScaling = true;
place.propertyFields.latitude = "latitude";
place.propertyFields.longitude = "longitude";
imageSeries.data=Stations.Stations;
var circle = place.createChild(am4core.Circle);
circle.fillOpacity = 0.7;
circle.propertyFields.fill = "color";
circle.tooltipText = "[bold]{name}:[/]\nCompliance Devices: {activeDevices}\nTotal devices:{totalDevice}";
place.events.on("hit", (ev)=>{
console.log(ev.target.dataItem.dataContext.title)
})
imageSeries.heatRules.push({
"target": circle,
"property": "radius",
"max": 15,
"dataField": "value",
})
}
Below lines are important where I am binding data
imageSeries.data=Stations.Stations;
imageSeries.heatRules.push({
"target": circle,
"property": "radius",
"max": 15,
"dataField": "value",
})
I tried doing this but not showing anything on map
imageSeries.data=group;

AmCharts expects an array for the data property in a series or chart object, not an object/map that points to an array. You need to assign an array to it directly. You can create multiple image series and assign a group to each one, e.g.
series1.data = group.CDFN;
// ...
series2.data = group.HCDR;
// ...
// etc

Related

Get specific JSON object from multiple

I am working with the FedEx Rates API in PHP to get shipping estimates which, by default, returns multiple service types that I have converted into a JSON array.
{
transactionId: 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx', output: {…}}
output:
alerts: (2) [{…}, {…}]
encoded: false
quoteDate: "2022-12-07"
rateReplyDetails: Array(10)
0: {serviceType: 'FEDEX_EXPRESS_SAVER', serviceName: 'FedEx Express Saver®', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
1: {serviceType: 'FEDEX_2_DAY', serviceName: 'FedEx 2Day®', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
2: {serviceType: 'FEDEX_2_DAY_AM', serviceName: 'FedEx 2Day® AM', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
3: {serviceType: 'FEDEX_GROUND', serviceName: 'FedEx Ground®', packagingType: 'YOUR_PACKAGING', commit: {…}, customerMessages: Array(1), …}
4: {serviceType: 'STANDARD_OVERNIGHT', serviceName: 'FedEx Standard Overnight®', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
5: {serviceType: 'FEDEX_STANDARD_OVERNIGHT_EXTRA_HOURS', serviceName: 'FedEx Standard Overnight® EH', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
6: {serviceType: 'FEDEX_PRIORITY_OVERNIGHT_EXTRA_HOURS', serviceName: 'FedEx Priority Overnight® EH', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
7: {serviceType: 'PRIORITY_OVERNIGHT', serviceName: 'FedEx Priority Overnight®', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
8: {serviceType: 'FIRST_OVERNIGHT', serviceName: 'FedEx First Overnight®', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
9: {serviceType: 'FEDEX_FIRST_OVERNIGHT_EXTRA_HOURS', serviceName: 'FedEx First Overnight® EH', packagingType: 'YOUR_PACKAGING', commit: {…}, ratedShipmentDetails: Array(1), …}
length: 10
...
I am getting this in an Ajax response to update the page, but where I'm stuck is only grabbing certain ones, like FEDEX_GROUND, FEDEX_EXPRESS_SAVER, FEDEX_2_DAY, and PRIORITY_OVERNIGHT, to display.
$.ajax({
type: "POST",
url: "...",
headers: { ... },
data: { ... },
}).done(function (response) {
const obj = JSON.parse(response);
// I would like this to be each of the specified serviceType only, currently does all of them
$.each(obj.output.rateReplyDetails, function () {
return this.serviceType;
});
I'm guessing it should be something like JSON Object where key serviceType === FEDEX_GROUND, but not sure what that syntax looks like. I found filter() but couldn't get that to work.

My NodeJS route not inserting proper values into table using SQL

I'm new to using node with MySQL but when I tried sending a query to my SQL server to insert the data it wasn't inserting the values from the form submitted. My route code looks like this,
const { application } = require('express')
const express = require('express')
const router = express.Router()
const pool = require('../config/db');
router.post("/create", async (req, res) => {
// Get user input
const name = req.body.name
const country = req.body.country
const dob = req.body.dob
const sql = `INSERT INTO users (name, country, dob) VALUES ('"+req.body.name+"', '"+req.body.country+"','"+req.body.dob+"');`
pool.query(sql, function(error, results){
if (error) {
throw error
}
res.status(201).send(`User added with ID: ${results.id}`)
console.log(name);
})
});
my query previously was like this,
const sql = `INSERT INTO users (name, country, dob) VALUES (name, country, dob);`
But both are not working as far as I'm trying to insert them into the table.
Some important code from my React Form which might help,
constructor(props) {
super(props);
this.options = countryList().getData();
this.state = {
name: '',
options: this.options,
val: null,
country: '',
dob: new Date(),
}
this.handleStartDateChange = this.handleStartDateChange.bind(this);
}
handleNameChange = (e) => {
this.setState({
name: e.target.value
})
}
handleOptionsChange = (val) => {
this.setState({
val
})
this.setState({
country:val.label
})
}
handleStartDateChange(date) {
this.setState({
dob: date
})
}
My handle submit is like this,
const handleSubmit = (e) =>{
e.preventDefault()
axios.post('http://localhost:4000/app/create', this.state)
console.log(this.state);
console.log(this.state) gives this in the console after submitting,
{name: 'Prajwal V', options: Array(249), val: {…}, country: 'Afghanistan', dob: Wed Nov 09 2022 18:02:00 GMT+0530 (India Standard Time)}
country
:
"Afghanistan"
dob
:
Wed Nov 09 2022 18:02:00 GMT+0530 (India Standard Time) {}
name
:
"Prajwal V"
options
:
(249) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
val
:
{value: 'AF', label: 'Afghanistan'}
[[Prototype]]
:
Object
The table contents in PHPMyAdmin,
I hope I've clearly explained my questions. Thank you so much on reviewing this.
I would suggest changing the query in your API. Also, you need to go back and do a SELECT to get the id of the row you are wanting to send back to your front end.
const { application } = require("express");
const express = require("express");
const router = express.Router();
const pool = require("../config/db");
router.post("/create", async (req, res) => {
// Get user input
const { name, country, dob } = req.body;
pool.query(
"INSERT INTO users SET name = ?, country = ?, dob = ?",
[name, country, dob],
(err, results) => {
if (err) {
throw err;
} else {
pool.query(
"SELECT id FROM users WHERE name = ?, country = ?, cob = ?",
[name, country, dob],
(err, results) => {
if (err) {
throw err;
}
if (results) {
res.status(200).send(`User added with ID: ${results.id}`);
console.log(name);
}
}
);
}
}
);
});
Also, make sure your datatypes are correct in your database otherwise MySQL will reject the values you provide.

gridjs: server, how to map data for a simple json array

I'm a java-script newbee, that's why I struggle with the mapping of a simple json array, if it is a response from a server. I've tested it with static json, and it works as expected:
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
data: [
{"dateTime": "2021-12-02 03:11:30.501","host": "master.myhost.com","ipv4": "93.215.66.14", "ipv6": "2003:cc:2fff:9e4:2e91:abff:febf:d839"},
{"dateTime": "2021-12-02 03:44:29.494", "host": "test.myhost.com", "ipv4": "93.203.250.190", "ipv6": "n/a"},
]
}).render(document.getElementById("wrapper"));
But if the same json array is delivered by a server, I don't know how to define my data mapping. That's what I've tried:
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
server: {
url: "http://localhost:8080/info/zone-log",
then: data => data.map([data.dateTime, data.host, data.ipv4, data.ipv6])
}
}).render(document.getElementById("wrapper"));
I get the following error on the JS console: '[Grid.js] [ERROR]: TypeError: [...] is not a function'.
Can somebody explain me, how to do the data mapping correctly?
Edit
Server response:
curl -i http://localhost:8080/info/zone-log
HTTP/1.1 200 OK
Date: Tue, 01 Mar 2022 08:53:39 GMT
Content-Type: application/json
Transfer-Encoding: chunked
[{"dateTime":"2021-12-02 03:11:30.501","host":"master.myhost.com","ipv4":"93.215.66.14","ipv6":"2003:cc:2fff:9e4:2e91:abff:febf:d839"},{"dateTime":"2021-12-02 03:44:29.494","host":"ursa.myhost.com","ipv4":"93.203.250.190","ipv6":"n/a"}, ...}
java-script console log:
data
Array(191) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
[0…99]
​​0: Object { dateTime: "2021-12-02 03:11:30.501", host: "master.myhost.com", ipv4: "93.215.66.14", … }
​​1: Object { dateTime: "2021-12-02 03:44:29.494", host: "ursa.myhost.com", ipv4: "93.203.250.190", … }
[Grid.js] [ERROR]: TypeError: [...] is not a function log.ts:12:21
Looks like data that you are getting is not an array. Hence data.map() is giving type error. Can you please console log the data and see what's coming?
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
server: {
url: "http://localhost:8080/info/zone-log",
then: data => {
console.log("data", data);
return data.map([data.dateTime, data.host, data.ipv4, data.ipv6])
}
}
}).render(document.getElementById("wrapper"));
Most probably the required array is inside another object in data.

Supported Languages in Forge Viewer

Is there a list avaiable of all languages (german, ...), which are supported by the forge-viewer?
I have tried to do this of there source code of the viewer.3d.js and found there an array of languages. As you can think, this way is not very convinient.
As I know, we can get supported locales from Autodesk.Viewing.Private.Lang.getLanguages(). It's an array. Each array item has two attributes. The symbol one is the language code passing language field to Autodesk.Viewing.Initinalizer, and the label one is a humman-readable string telling the locale language name.
Autodesk.Viewing.Private.Lang.getLanguages()
(21) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {symbol: 'en', label: 'English'}
1: {symbol: 'zh-Hans', label: 'Chinese Simplified'}
2: {symbol: 'zh-Hant', label: 'Chinese Traditional'}
3: {symbol: 'zh-HK', label: 'Hong Kong Traditional'}
4: {symbol: 'ja', label: 'Japanese'}
5: {symbol: 'cs', label: 'Czech'}
6: {symbol: 'ko', label: 'Korean'}
7: {symbol: 'pl', label: 'Polish'}
8: {symbol: 'ru', label: 'Russian'}
9: {symbol: 'fr', label: 'French'}
10: {symbol: 'fr-CA', label: 'Canadian French'}
11: {symbol: 'de', label: 'German'}
12: {symbol: 'it', label: 'Italian'}
13: {symbol: 'nl', label: 'Dutch'}
14: {symbol: 'es', label: 'Spanish'}
15: {symbol: 'pt-BR', label: 'Portuguese Brazil'}
16: {symbol: 'tr', label: 'Turkish'}
17: {symbol: 'sv', label: 'Swedish'}
18: {symbol: 'da', label: 'Danish'}
19: {symbol: 'no', label: 'Norwegian'}
20: {symbol: 'en-GB', label: 'British English'}
length: 21
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
Note. It's an internal API, so it might be changed in the future. You will need to use it at your own risk.

ArcGIS JS, extent on service (raster)

I'm creating a layer from service with ArcGISDynamicMapServiceLayer
layerServicios = new esri.layers.ArcGISDynamicMapServiceLayer(service_url, {
id: id_layer,
opacity: 0.9,
imageParameters: imageParams
});
console.log('layerServicios', layerServicios):
{
attributionDataUrl: ""
capabilities: "Map,Query,Data"
className: undefined
copyright: ""
credential: undefined
description: ""
dpi: 96
fullExtent: {type: "extent", xmin: -113.99999550732358, ymin: -62.566660275992355, xmax: -58.9560316118582, ymax: -14.26532106013001, …}
gdbVersion: undefined
getImageUrl: ƒ ()
hasAttributionData: false
id: "layer_mapas_3"
imageFormat: "png8"
imageTransparency: true
infoTemplates: null
initialExtent: {type: "extent", xmin: -70.34055967658617, ymin: -33.83365057356685, xmax: -70.31957965174547, ymax: -33.605022097738875, …}
isPNG32: undefined
layerDefinitions: []
layerInfos: (305) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
loaded: true
maxImageHeight: 4096
maxImageWidth: 4096
maxRecordCount: 1000000000
maxScale: 0
minScale: 0
normalization: true
onError: ƒ ()
onLoad: ƒ ()
onOpacityChange: ƒ ()
etc...
}
When I was working with graphic layer, I had no problem on zoom to extent with:
var gLayer = map.getLayer(id_layer);
var ge = GraphicsUtils.graphicsExtent(gLayer.graphics);
map.setExtent(ge, true);
But now I don't know how to setExtent in this case, with a service thar returns a raster
You could use the fullExtent property of your ArcGISDynamicMapServiceLayer
map.setExtent(rasterLayer.fullExtent);