Mapbox rectangle line from bounds from two points - gps

I use Mapbox and my goal is to create a rectangle from my bounds. I also center my map into the bounds.
While Mapbox can figure out all my four coordinates for fitBounds, it does not do the same thing for the line. Instead it draws the line as a line between the two points.
How can I...
...draw a rectangle instead?
...calculate the other two coordinates needed?
A part of the code
const bounds = [
[17.76069212, 59.22761885],
[18.20001876, 59.44007814],
];
var map = new mapboxgl.Map({
container: "map",
style: "mapbox://styles/mapbox/streets-v11",
});
map.fitBounds(bounds, {
padding: 16,
});
map.on("load", () => {
map.addSource("route", {
type: "geojson",
data: {
type: "Feature",
properties: {},
geometry: {
type: "LineString",
coordinates: bounds,
},
},
});
map.addLayer({
id: "route",
type: "line",
source: "route",
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#888",
"line-width": 8,
},
});
});
I saw turf.js and it seems possible with it, but it's a large library to just draw a rectangle.
I will accept a library as an answer if it's small.
If the solution is a math formula, I need a code example to get the hang of it.

With your pair of bounds coords you always can create a rectangle in mapbox without any library... it's a matter of creating the 4 corners using your data of bottom-left/top-right.
Mapbox requires to create a fifth point that is the same as the initial one.
Using yours you can create a feature to add to your line layer, and it will paint a rectangle... it would be like this:
{
"geometry": {
"coordinates": [
[
[
17.76069212,
59.22761885
],
[
17.76069212,
59.44007814
],
[
18.20001876,
59.44007814
],
[
18.20001876,
59.22761885
],
[
17.76069212,
59.22761885
]
]
],
"type": "Polygon"
},
"type": "Feature",
"properties": {}
}

Related

Update Amcharts4 chart dynamically using vue js

I'm using AmCharts4 with Vue.JS,
For the moment I've added default chart design when page loads, But when I trying to add dynamic values after page loads (Using Button click), It doesn't reflect on view.
Code:- gist
data: () => ({
dataForChart: {
data: [{
"name": "Anne",
"steps": 32
}, {
"name": "Rose",
"steps": 30
}, {
"name": "Jane",
"steps": 25
}]
}
}),
chart creation on mounted()
let chart = am4core.create("chart-div", am4charts.XYChart);
chart.data = this.dataForChart.data
when dynamically change values using button click those data doesnt reflect on chart.
method followed to change data set.
this.dataForChart.data = {
data: [{
"name": "Anne",
"steps": 54
}, {
"name": "Rose",
"steps": 44
}, {
"name": "Jane",
"steps": 33
}]
}
The reason for this is that although this.dataForChart.data is reactive (it's a vue instance property) the chart.data (amcharts chart property) is not.
You have to manually set chart.data array values whenever your this.dataForChart.data property changes. I've done this by setting a watcher on this.dataForChart.data like so:
watch: {
dataForChart: {
data(values) {
this.chart.data = values;
},
deep: true
}
}
Cheers!

Draw an animated line between two markers in MapBox

I'm new to mapbox
I import some markers from a csv file, and i can draw lines between them manually , from each port to its destination.
for example from Morocco to China, but if i show you my map, you can't know where is the Port and what is the Destination : from Morocco to China or the reverse. so, for this reason i would like draw an animated line from each port to its destination.
For the moment i don't have any code, i found in the below link how to draw an animated line but i couldn't do it between to markers, because they talk about a sinusoidal function.
https://www.mapbox.com/mapbox.js/example/v1.0.0/dynamically-drawing-a-line/
Can you help me please ?
Thank you !
In the example you linked, you can change the add() function to start drawing at your first point and stop drawing at your last. Ideally your markers are in the order you want the line to be drawn:
// add your points
var points = [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [0, 0]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [10, -10]
},
"properties": {}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [50, 50]
},
"properties": {}
}
]
// add a variable for keeping track of points
var y = 0;
// Start drawing the polyline.
add();
function add() {
// add a point on the line for the new marker
polyline.addLatLng(
L.latLng(points[y].geometry.coordinates[1],
points[y].geometry.coordinates[0])
);
// Pan the map along with where the line is being added.
map.setView(points[y].geometry.coordinates, 3);
// Continue to draw and pan the map by calling `add()`
// until `y` reaches the number of points
if (++y < points.length) window.setTimeout(add, 1000);
}

sWidth is not working in dataTables

I am trying to fix column width instead of dataTable choosing it automatically , hence i am trying to set sWidth but its not applying. Following is my code,
$(document).ready(function(){
$('#Emp_table').dataTable()
.columnFilter({
aoColumns: [ {type:"text"},
{ type: "text" },
{ type: "select",bSmart: false,"sType": "string", "sWidth": "5%" },
{ type: "select" },
{ type: "select" },
{ type: "select"},
{ type: "select" },
{ type: "select" }
],
});
});
Here all works fine like filter by text or value except the column width, because of that the table length is extending beyond my page. Even though my first value is ID which is not even more than 3 digits the width takes for around 10 characters . Not only sWidth, even bSmart i am trying to false but still it works with smart filter .
You need to set http://datatables.net/reference/option/autoWidth to false
Also it looks like you're creating your table a bit oddly.
For datatables 1.10 use:
$('#Emp_table').DataTable({
'columns': [
{"type": "string", "width": "5%" },
// etc...
],
'autoWidth': false,
})

sencha touch dynamic chart

in Sencha Touch 2.1 how can I load the chart dynamically from json, also with dynamic fields store, chart axes, and chart series,
I know maybe this is too much, but I need to display many kind of data, If I create 1 chart component for each display means I have to create more than 15 chart component, I'm afraid it get bloated
I did not complete this dynamically, but I made it seem dynamic.
I first request a user to fill out a form.
I also have multiple panels that holds charts with empty stores, in the form of several different layouts.
Based on the user's form, I show and hide panels, or chart when they need to be displayed only after loading the store with the required data.
yes it is bulky, and they are static, but I found it slightly easier to handle than dynamically loading.
EDIT
After thinking,
have you tried a function like
function dynamiccharts(var1, var2, var3){
return Ext.chart.Chart({
....
})
}
variables would include things like data, url, store or etc.
This is my example creating a chart on controller inside a panel: axis, series, store fields, url are became parameters, PAR_FORM is global variable showing the difference between views, I'm using this code for another chart (Column, Pie)
Ext.define("Geis.controller.app", {
extend: "Ext.app.Controller",
config: {
refs: {
mainview: 'mainview',
barchartview: 'barchartview',
btnShowChartAnggaran: '#btnShowChartAnggaran'
},
control: {
'btnShowChartAnggaran': {
tap: 'onShowChartAnggaran'
}
}
}
createBarChart: function(fields, series_xfield, series_yfield, url) {
this.getBarchartview().add(new Ext.chart.CartesianChart({
id: 'barchartgenerateview',
store: {
fields: fields,
proxy: {
type: 'jsonp',
url: url
}
},
background: 'white',
flipXY: true,
colors: Geis.view.ColorPatterns.getBaseColors(),
interactions: [
{
type: 'panzoom',
axes: {
"left": {
allowPan: true,
allowZoom: true
},
"bottom": {
allowPan: true,
allowZoom: true
}
}
},
'itemhighlight'
],
series: [{
type: 'bar',
xField: series_xfield,
yField: series_yfield,
highlightCfg: {
strokeStyle: 'red',
lineWidth: 3
},
style: {
stroke: 'rgb(40,40,40)',
maxBarWidth: 30
}
}],
axes: [{
type: 'numeric',
position: 'bottom',
fields: series_yfield,
grid: {
odd: {
fill: '#e8e8e8'
}
},
label: {
rotate: {
degrees: -30
}
},
maxZoom: 1
},
{
type: 'category',
position: 'left',
fields: series_xfield,
maxZoom: 4
}]
}));
Ext.getCmp('barchartgenerateview').getStore().load();
},
onShowChartAnggaran: function() {
this.getBarchartview().remove(Ext.getCmp('barchartgenerateview'), true);
if (PAR_FORM == 'Dana Anggaran') {
this.createBarChart(['kode', 'keterangan', 'nilai'], 'keterangan', 'nilai',
Geis.util.Config.getBaseUrl() + 'anggaran/laporan/json/get_dana_anggaran_json/');
} else if (PAR_FORM == 'Alokasi Anggaran') {
this.createBarChart(['kode', 'keterangan', 'belanja_pegawai', 'belanja_barang', 'belanja_modal'],
'keterangan', ['belanja_pegawai', 'belanja_barang', 'belanja_modal'],
Geis.util.Config.getBaseUrl() + 'anggaran/laporan/json/get_alokasi_json/');
}
this.getMainview().animateActiveItem(1, {type:'slide', direction:'left'});
}
});
base on my experiment if you want to activate the interactions features you need to set the chart id dynamically too, for example by creating Global Counter Variable

Dojox Data Chart xaxis

I'm wonder is it possible to proper setting each xaxis in dojox.charting.DataChart
here is my data.JSON for example:
{
"label": "btmlabel",
"items": [
{ "mydata":"ANDT", "btmlabel":[{value: 1, text: "22 April 10.34AM"},{value: 2, text: "22 April 10.40AM"}], "data":[{"x":1,"y":1},{"x":2,"y":3}] }
]
}
and trying to draw xaxis which failed(show empty in xaxis) with below code:
var chartPrefs = {
chartPlot: {type:dojox.charting.plot2d.Markers, tension:"S"},
scroll:true,
xaxis:{labelFunc:"seriesLabels"},
}
chart = new dojox.charting.DataChart("chartNode", chartPrefs);
chart.setStore(store, {mydata:"*"}, "data");
});
It looks like your json object structure is invalid for charting. It would be better use the following structure:
var storeData = {
"label": "btmlabel",
"items":
[
{
"btmlabel": "22 April 10.34AM",
"data": 1
},
{
"btmlabel": "22 April 10.40AM",
"data": 3
}
]
}
and creating chart:
dojo.addOnLoad(function () {
var storeForChart = new dojo.data.ItemFileWriteStore({ data: storeData });
var chartPrefs = {
chartPlot: { type: dojox.charting.plot2d.Markers, tension: "S" },
comparative: true,
xaxis: { labelFunc: "seriesLabels" }
}
chart = new dojox.charting.DataChart("chartNode", chartPrefs);
chart.setStore(storeForChart, { data: "*" }, "data");
});
View source of this page - here working example.
Read good article about chart building - introducing-dojox-datachart
EDIT:
Also look this page. I think it will be very helpful for you.