I want ask, how I can use the MapCircle outwith the Map {} object. I want write a function, which will draw a way, and I thought, that I can do somethink like that:
function putWay (way)
{
for (var i = 0; i < getLatitude.count - 1; i++ )
{
way.center {
longtitude: getLongtitude.get(i).longtitude
latitude: getLatitude.get(i).latitude
}
}
}
Way = MapCircel
getLatitude = listView, where are my data (Latitude) from DB
getLongtitude, this same but Longtitude
And way would be a MapCircel id, but it doesn't work. I think becouse of using the Map properity outwith the Map object, but maybe is a way to using the Map properity outwith Map object? Maybe a pointer or somethink like that? Maybe I can create my own object/properity?
If it were a single item, the solution is as follows:
way.center = QtPositioning.coordinate(getLongtitude.get(i).latitude, getLatitude.get(i).longtitude)
But in your case it is not ideal because the number of points is variable.
When you have a variable amount of data it is better to use a model, I see that you wanted to use LocalStorage but unfortunately it does not allow to read a sqlite by the path, so in this case you must implement a model, in a previous answer and implement it.
Then you have to use a MapItemView and pass it to the MapCircle as a delegate.
SqlQueryModel{
id: querymodel
query: "select * from coordinates"
}
// ...
Map {
// ...
MapItemView{
model: querymodel
delegate: MapCircle {
center: QtPositioning.coordinate(latitude, longitude)
radius: 1.0
color: 'blue'
border.width: 1
}
}
The above is the essential but I also took the liberty to improve your code so you can find it here.
Related
I'm using the aframe-particle-system-component, and was using .setAttribute() on the tick() function to update the particle system in real time, but it performed terribly, leading to almost instant memory-related crashes. Is there a way to directly access the maxAge, opacity, and enabled properties of the system? I'm assuming this is the best way to tackle this as the framework advises that .object3D is directly accessed for performance reasons. I would like to be able to access the particle system in a similar manner. Any help is appreciated.
tldr: here's an example with animated opacity, size, and some toggles. Switching max age seems to wait until all current particles are gone, though no word about it in the docs.
1. Gutting the particle system
The particle system is based on the ShaderParticleEngine, so modyfing it won't be that THREE.js'ish.
From what I can tell, the particle-system creates and stores SPE.Emitter's. You can access them here:
let particleSystem = this.el.component['particle-system']
let emitterGroup = particleSystem.particleGroup.emitters
Changing values - for example, if you have one emitter:
emitterGroup[0].disable() // disables the emitter
emitterGroup[0].opacity.value = 0.1 // sets the opacity
2. A job for a-frame custom components
I'd create a custom component - which will upon any change iterate through the emitter group and change the attributes:
AFRAME.registerComponent('particle-controller', {
schema: {
opacity: {default: 1}
},
init: function() {
let system = this.el.components['particle-system']
this.emitterGroup = system.particleGroup.emitters
},
update: function() {
this.setValueInEmitters(this.emitterGroup, 'opacity', this.data.opacity)
},
// may come in handy when changing more key-value pairs
setValueInEmitters(group, prop, value) {
for (let i = 0; i < group.length; i++) {
group[i].prop.value = value
}
}
})
The schema could be fed with key-value pairs or such to make the component more universal.
3. Why setAttribute is so heavy
Gathering from the source code, any change removes the old particle group and creates a new one from scratch.
I have an InterstitialAd QML object (QtQuick 2, QT 5.13) with onClosed event that is triggered with the interstitial ad is closed. I tried to show the interstitial ad before starting new game with the following QML code:
InterstitialAd {
id: iAd
property variant handlerFunc
onClosed: {
if (handlerFunc) {
handlerFunc
handlerFunc = null
}
}
}
function resetGameWithAd()
{
iAd.handlerFunc = Qt.binding(function() {
console.log("AdTest: calling resetGame()")
scene.resetGame()
})
console.log("AdTest: calling iAd.show()")
iAd.show()
}
where I tried to assign handlerFunc to a function that restarts the game when onClosed event is triggered, but got an effect that I did not expect. The console output of my app is:
qml: AdTest: calling resetGame()
qml: AdTest: calling iAd.show()
so obviously assigning handlerFunc to Qt.binding... actually calls the function (because resetGame is printed first), but I expected that it does only assignment. The similar technique is demonstrated here, with ':' but not with assignment.
What is wrong and what is the right way to implement this?
I also tried a code like this:
function resetGameHandler(params)
{
iAd.closed.connect(function() {
scene.resetGame(params)
iAd.closed.disconnect(/*...???...*/)
})
iAd.show();
}
but with no success because I can't disconnect it, without having a reference to the implicitly created function (as far as I see it means that I need a regular function with a name).
I haven't done any QML for some months, so I might be wrong. But if my memory is any good, this might help you.
To stay close to your approach:
variant is deprecated. Using var instead is recommended.
You won't need Qt.binding(). You can directly assign a function to that property.
Call the function in the property.
InterstitialAd {
id: iAd
property var handlerFunc <-- Use var instead of variant
onClosed: {
if (handlerFunc && typeof handlerFunc === "function") {
handlerFunc() <-- Call it!
handlerFunc = null
}
}
}
iAd.handlerFunc = function() { // doSomething cool here }
Alternatively you might be able to produce the same results with Binding and Connection-Objects in a more declarative way, but the right choice depends on what shall be done onClosed
As of Xcode 11 beta 6…
The Binding structure’s conditional conformance to the Collection protocol is removed.
Going with Apple's recommendation (at that link) of creating an IndexedCollection type, we can avoid boilerplate for List and ForEach like this:
public extension ForEach where Content: View {
init<Base: RandomAccessCollection>(
_ base: Base,
#ViewBuilder content: #escaping (Data.Element) -> Content
)
where
Data == IndexedCollection<Base>,
Base.Element: Identifiable,
ID == Base.Element.ID
{
self.init(IndexedCollection(base: base), id: \.element.id, content: content)
}
}
That takes us from their example,
List(landmarks.indexed(), id: \.1.id) { index, landmark in
Toggle(landmark.name, isOn: self.$landmarks[index].isFavorite)
}
to this:
List(landmarks) { index, landmark in
Toggle(landmark.name, isOn: self.$landmarks[index].isFavorite)
}
But is it possible to write another extension initializer, to allow for avoiding having to use the index and subscript (self.$landmarks[index])?
I've tried making use of dynamicMemberLookup, but if that's the solution, I didn't get it right yet.
In this component code I am trying to use an event to select the meaning of the variable called "name"
to select which entity will copy another entities rotation as the user watches.
Different events will result in different rotations.
So event 1 means that name equals querySelector Object A
Then I am trying to have row get it's own rotation and give it to name's (to) animation and then start
name's animation by emitting moveobject to name.
However I am currently stuck on this problem after investing many hours trying to solve it. Help?
AFRAME.registerComponent("comp", {
init: function () {
let name = {}
this.el.addEventListener("event1", (e) => {
name = document.querySelector('#objectA');
console.log('event1')
// line 13? comp.emit('rowstart)
});
this.el.addEventListener("event2", (e) => {
name = document.querySelector('#objectB');
console.log('event2')
});
let row = document.querySelector('#rowA');
row.addEventListener('rowstart', function (e) {
var rotation = row.getAttribute('rotation')
name.setAttribute('animation', {
to: {
x: rotation.x,
y: rotation.y,
z: rotation.z - 30
}
})
name.emit('moveobject')
});
}
});
I should mention that this link below is what my code looks like when it is ONLY copying rotation, and not using an event to select which entity will be rotated https://glitch.com/edit/#!/copy-rotation?path=index.html:37:8 (edited)
to is not a vector property, you have to pass it as a string.
name.setAttribute('animation', 'to', `${rotation.x} ${rotation.y} ${rotation.z}`);
I have an array collection in Flex which looks like:-
public var expenses:ArrayCollection = new ArrayCollection([
{ Expense:"Taxes", Amount:2000 },
{ Expense:"Rent", Amount:1000 },
{ Expense:"Taxes", Amount:1000 },
{ Expense:"Food", Amount:1000 },
{ Expense:"Food", Amount:200 } ]);
Now the PieSeries has the dataprovider set to 'expenses' with field pointing to 'Amount' and labelField pointing to 'Expenses'. The problem here is that I get 5 pie slices instead of 3 (which is correct when we think that PieSeries will dump whatever exists in the dataProvider to UI).
Is there a way I can get Grouping around this data? Maybe by modifying the dataFunction and labelFunction?
What I expect is 3 slices showing up with value being the net sum - {Taxes:3000, Rent:1000, Food:1200} - similar to GROUP BY Label?
There is a similar question here: How do I display grouped XML data in a Flex pie chart?
If that doesn't work out, I would preprocess the incoming data and create a new dataprovider with unique labels and the sum of the values. This will be a lot less complex that adding custom groupings and data functions.