Using List Option, Within single ID image using as Slider - flutter

class QuotationResources {
final String price,vehicleShowcase,vehicleShowcaseLeft,vehicleShowcaseRight,vehicleShowcaseRear;
QuotationResources({
this.vehicleNumber,
this.vehicleShowcase,
this.vehicleShowcaseLeft,
this.vehicleShowcaseRight,
this.vehicleShowcaseRear,
this.price,
});
}
List<QuotationResources> quotationResources = [
QuotationResources(
id: 1,
vehicleShowcase: "assets/images/truck_1.jpeg",
vehicleShowcaseLeft: "assets/images/truck_2.jpg",
vehicleShowcaseRight: "assets/images/truck_3.jpg",
vehicleShowcaseRear: "assets/images/truck_4.jpeg" ),
];
Basically I just want to slider, How to use id=1 images as sliders (like vehicleShowcase,
vehicleShowcaseLeft, vehicleShowcaseRight, vehicleShowcaseRear), below image I need to add in the this format
image: AssetImage(quotationResources.vehicleShowcase),

Related

flutter_quill: How to programmatically set size attributes of a picked up image?

https://pub.dev/packages/flutter_quill page refers to "Custom Size Image for Mobile", however, I am unable to find an example to do the same through code.
var imageURL =
'https://user-images.githubusercontent.com/122956/72955931-ccc07900-3d52-11ea-89b1-d468a6e2aa2b.png';
final doc = Document()..insert(0, BlockEmbed.image(imageURL));
setState(() {
_controller = QuillController(
document: doc, selection: const TextSelection.collapsed(offset: 0));
});
I am looking for a solution to specify attributes for a particular delta.
I use controller to add Style like this
_controller.document.insert(_controller.selection.start , BlockEmbed("image", stl));
_controller.document.format(_controller.selection.start,1,StyleAttribute("mobileWidth: ${_imageSize!.width}; mobileHeight: ${_imageSize!.height}; mobileMargin: 10; mobileAlignment: center"));

How to add properties to leaflet-geoman layer when using the toolbar

I need to add custom props to my created polys. To do so currently when the user select in the toolbar the polygon and create a shape, on the create event I convert it to json remove it from the map add the custom props to the json and reload the newly created layer.
this.map.on('pm:create', e => {
const id = getUID();
const leafId = e.layer._leaflet_id;
const featureGroup = L.featureGroup().addLayer(e.layer);
this.map.eachLayer(layer => {
if (layer._leaflet_id === leafId) {
this.map.removeLayer(layer);
}
});
const data = featureGroup.toGeoJSON();
data.features[0].properties = {
id,
name: `Zone ${id}`
};
this.zoneService.add({id, data: JSON.stringify(data)})
.pipe(
switchMap((res) => this.zoneService.getAll().pipe(this.addToMap(this.map)))
).subscribe();
});
This is working but I feel I am not doing something right here. Adding removing Adding, there must be a better way. Thanks for any help

ion picker options overlaps

Currently, I am working on a ionic application which require ion-picker (multi column picker).
I got the data perfectly as I want but just one time means when I open picker for the first time, but after that when I click second time the all options overlapped, I am not able to upload image because of stackoverflow (10 reputation) policy. so please refer the example here
, I have also tried selectedIndex: 0 as suggested in the GitHub link but nothing change.please let me know if anyone know how to solve this.
Thanks in advance
var myColumns = [
{
name: "days",
options: this.day2,
selectedIndex: 1
},
{
name: "Hours",
options: this.hours2,
selectedIndex: 1
},
{
name: "Minutes",
options: this.minutes2,
selectedIndex: 1
},
{
name: "dayType",
options: this.HourType,
selectedIndex: 1
}
];
const picker = await this.pickerCtrl.create({
buttons: [
{
text: "Done"
},
{ text: "Cancel" }
],
mode: "md",
cssClass: ["datePicker"],
columns: myColumns
});
First of all, I found that the problem is that you put the options with an array, I mean you don't put them manually.
Then I think you have 2 options:
first one is put the options manually(in my opinion is not worth it), and the second one, i found that if you put selectedIndex: 0, on the columns properties, the overlap should be gone, but the picker will open always on the first entry. And if you override this selectedIndex: 0, and put a variable that you can change when ever you want, the overlap should be gone, for the most of the entries, except for the first one and the last one.
That's what occur to me.
Hope this help you.
Edit:
I was looking around and just found this:
let picker = await this.pickerCtrl.create(opts);
picker.present();
picker.onDidDismiss().then(async data => {
let num = await picker.getColumn('num');
this.pickerData = num.options[num.selectedIndex].text;
this.pickerDataPrevious = num.selectedIndex;
num.options.forEach(element => {
delete element.selected;
delete element.duration;
delete element.transform;
});
});
If you loop the options (in that case num.options) and delete this properties, the picker data should work correctly
Just before picker.present();
Add these lines :
picker.columns[0].options.forEach(element => {
delete element.selected;
delete element.duration;
delete element.transform;
});
Ref: https://github.com/ionic-team/ionic-framework/issues/17664
Yup, this is a known issue
The problem is that there are 2 properties being added to the original column's options object: duration & transform
As a workaround, you can manually remove these 2 properties. Here's a clean way to do it.
onShowOptions(): void {
const selectedIndex = this.findOptionIndex(this.defaultLanguage, this.languagesList);
this.pickerController
.create({
columns: [
{
selectedIndex: selectedIndex,
name: 'item',
// here's where the magic happens: spread the object, remove duration & transform properties and keep the rest
options: this.options.map(({ duration, transform, ...rest }) => rest),
},
],
buttons: [
{
text: 'Cancel',
},
{
text: 'Done',
handler: ({ item }) => this.optionSelected(item),
},
],
})
.then((picker: HTMLIonPickerElement) => picker.present());
}

vue-chartjs: is it possible to dynamically change color based on value

Using vue-chartjs is it possible to change to color of the bar?
This is similar to this question which is based on chart.js
chart.js bar chart color change based on value, and the jsfiddle provided in the answer is exactly what I'm looking for, except within vue-chartjs.
Any help appreciated
So this should be your chart calling (in my case, I named it bar-chart)
<bar-chart
:chart-data="barData"
:options="barChartOptions">
</bar-chart>
:chart-data and :options are 2 props defined when I create my bar component:
Vue.component('bar-chart', {
extends: VueChartJs.Bar,
props: ['chartData', 'options'],
So your barData, should be an object like this:
{datasets: [...], labels: [...]}
Your dataset is an array with the charts you want to show. So if you want to show only 1 data, than your array only has one position. So let's assume that by now. We'll use dataset = dataset[0]
Your dataset accepts some properties, 2 of them are a must:
Data (an array with the data you want to show)
Label (the name of the label when you hover on the bardata. It should display "Label: value"
It also accepts some other properties like:
fill
hoverBackgroundColor
backgroundColor
check more here: https://www.chartjs.org/docs/latest/charts/bar.html
so now, your backgroundColor property is either a color value (e.g. red, #FF0000), or an array.
If it is an array, then this should be true dataset.bgColors.length === dataset.data.length
and each dataset.bgColors array position is the color of the respective value in the dataset.data array.
dataset: {
data: [1,2,-3,-4,2,1]
backgroundColor: ['green', 'green', 'red', 'red', 'green', 'green']
...
}
So now, you can just build a bgColors array with the color you want, based on your data.
------------- UPDATING THE DATA -----------------
To anybody else who is looking for a way to UPDATE your chart data after it was rendered. It's a different question, but to help the community:
When you set your chart component, you can define a watch for the chartData prop, so when the chartData changes, the method is called and you re-render the chart:
Vue.component('bar-chart', {
extends: VueChartJs.Bar,
props: ['chartData', 'options'],
methods: {
renderLineChart () {
this.renderChart(this.chartData, this.options)
}
},
mounted () {
this.renderLineChart()
},
watch: {
chartData: function () {
this.$data._chart.destroy()
this.renderLineChart()
}
}
})
IMPORTANT: Make sure you make a new copy of the new chartData object info because the watch will only check if the object itself changed, not its inner properties.
However, if you really want to change ONLY the dataset.data or dataset.backgroundColor or any other, than the watcher will not know it changed. You can use the property deep: true in the watcher for this, as it will check changes deep inside the chartData object:
watch:
chartData: {
handler: function () {
this.$data._chart.destroy()
this.renderLineChart()
},
deep: true
}
}
I hope the answer was clear for everyone.
Best regards

Clustering custom html markers with mapbox-gl-js

I'm using the mapbox-gl-js API and I'm using it with react to create some custom markers as follows:
let div = document.createElement('div');
let marker = new mapboxgl.Marker(div, {
offset: [ -20, 80 ]
});
marker.setLngLat(person.geometry.coordinates);
render(
<MapPersonIcon />,
div,
() => {
marker.addTo(map);
}
);
This worked great. However I would now like to cluster these markers, producing the same affect as the functionality found with layers i.e.
https://www.mapbox.com/mapbox-gl-js/example/cluster/
Does anyone know whether this is possible (hopefully with custom clusters too) or whether it will be available in an upcoming release?
This feature is now in Mapbox GL js - https://docs.mapbox.com/mapbox-gl-js/example/cluster-html/
Key takeaways:
When setting your data source using map.addSource, make sure you define cluster: true and clusterRadius: int, like so:
map.addSource( 'sourceName', {
type: "geojson",
data: {
type: 'FeatureCollection',
features: [JSON]
},
cluster: true,
clusterRadius: 80,
});
That will push mapbox to cluster your icons, but you need to tell mapbox what to do when it clusters those icons:
map.on( 'moveend', updateMarkers ); // moveend also considers zoomend
The business (trimmed down for relevance):
function updateMarkers(){
var features = map.querySourceFeatures( 'sourceName' );
for ( var i = 0; i < features.length; i++ ) {
var coords = features[ i ].geometry.coordinates;
var props = features[ i ].properties;
if ( props.cluster ){ // this property is only present when the feature is clustered
// generate your clustered icon using props.point_count
var el = document.createElement( 'div' );
el.classList.add( 'mapCluster' );
el.innerText = props.point_count;
marker = new mapboxgl.Marker( { element: el } ).setLngLat( coords );
} else { // feature is not clustered, create an icon for it
var el = new Image();
el.src = 'icon.png';
el.classList.add( 'mapMarker' );
el.dataset.type = props.type; // you can use custom data if you have assigned it in the GeoJSON data
marker = new mapboxgl.Marker( { element: el } ).setLngLat( coords );
}
marker.addTo( map );
}
NOTE: Don't copy paste this code, rather use it in conjunction with https://docs.mapbox.com/mapbox-gl-js/example/cluster-html/ to get the whole picture. Hope this helps!
Answering own question:
At current it seems that this isn't possible as per mapbox's github:
If you would like to cluster your markers you will need to use mapbox's native maki icons (please see above example picture & URL) until a plugin is available for your custom HTML markers.