Google Maps JS 3 addGeoJson data layer callback when loaded - google-maps-api-3

I know the loadGeoJson function has a callback to ascertain when the layer has been loaded, but addGeoJson doesn't have this.
How would I check when all the features have been loaded using addGeoJson? I need to do this in order to then perform other functions on the data.
lyr_featured = new google.maps.Data({map:map});
lyr_featured.addGeoJson(js_featured);

addGeoJson returns the imported features.
from the documentation:
addGeoJson
addGeoJson(geoJson[, options])
Parameters:
geoJson: Object
options (optional): Data.GeoJsonOptions
Return Value: Array<Data.Feature>
Adds GeoJSON features to the collection. Give this method a parsed JSON. The imported features are returned. Throws an exception if the GeoJSON could not be imported.

When using addGeoJson it returns an array of the features added to the map.
that means that:
let features = new google.maps.Data({map: yourMapElement}).addGeoJson(someGeoJsonData);
will give you an array with all the features you have added.
Console.log(features) to see it's structure, and reach information inside it.
Hope that's helpful.

Related

Google Maps - Access object returned by getbounds

I have a simple Google Maps implementation with an editable circle, the 'bounds' object that it creates looks like this...
I am trying to convert these values to an array so I can save them to a database. First I want to try and understand what each value represents.
Googles Docs say that getbounds returns a rectangle so I am confused. Anybody have any relevant docs they can point me at?
That is a google.maps.LatLngBounds object.
It has getNorthEast and getSouthWest methods to get the two corners (and can be used to create a google.maps.Rectangle)

Meteor collection returns no results except in template

I'm new to the Meteor framework, and am having problems accessing data from my collection, outside of a template.
I have a small mongo collection and can retrieve and present its data without problems by using a template. However, when I try to get a cursor or array to use more directly, I get no results returned.
In my script, using find
var dataFind = Fakedata.find();
console.log(dataFind);
console.log(dataFind.count());
gives a cursor object, but a count of zero.
var dataFetch = Fakedata.find().fetch();
console.log(dataFetch);
console.log(dataFetch.length);
gives an empty array, length of zero.
Using the same find() or fetch() from the JS console gives populated objects as I would expect the code above to do. Within a meteor template, everything seems to work fine as well, so the pub/sub seems to be correct.
Any clues as to what I'm doing wrong here?
It looks like your subscriptions aren't ready at the time you try to access your collection data, this is a common gotcha.
When you access your collection data via templates, it is most likely via the use of template helpers which happen to be reactive, so they will rerun when your collections are ready thus displaying the correct data.
When accessing your collections in a non-reactive script though, they will appear empty if the subscription is not yet ready.
You can try using this pattern in your script to execute code only when the subscription is ready :
Meteor.subscribe("mySubscription",function(){
// we are inside the ready callback here so collection date is available
console.log(Fakedata.find().fetch());
});
If you are looking for a more robust approach, try looking at iron:router waitOn mechanism.

is it possible to get the Entity object before objectify saves it (and fill some other data)

I have some personal data structure mixed with "standard fields". I would like to avoid the manual work on simple fields (with datastore native API):
toPersist.setProperty("field1", value1);
toPersist.setUnindexedProperty("field2", value2);
but I still want to get the prefilled Entity instance toPersist so I can add my own #Ignore fields my self
For example:
Entity filled = OfyService.ofy().save().entity(this).fill();
filled.setProperty("mySpecialField", jsonValue);
//...
// I want to save my entities alone
datastore.put( filled );
reversely I'd like to get the Entity object representing each entry in a load() call.
Is this possible? or do I have to dive into Objectify code to hack it?
thanks for your answers
I don't follow your question exactly, but I'm pretty sure what you're looking for are the #OnLoad and #OnSave annotations. You add them to methods within your entity classes, and those methods will be called just after an entity is loaded, or just before one is saved, respectively. The documentation for them is here.
Edit:
After your comments (below) I now understand what you are trying to accomplish. Yes, Objectify supports this (though I have never tried it myself). You want to use the Saver.toEntity() and Loader.fromEntity() methods. It appears you can use them like this:
// Use Objectify to convert a POJO into an Entity
Entity filled = ofy().save().toEntity(myPojo);
// Use Objectify to convert an Entity into a POJO
Object pojoCopy = ofy().load().fromEntity(filled);

What is source in ArrayCollection and XMLListCollection?

What is the role of source for an ArrayCollection or XMLListCollection?
Is it used just once - when constructing a new ArrayCollection or XMLListCollection object and is it copied to some internal data structure of that object?
Because nothing is updated when the source Array (or XMLList) is being modified and the documentation confirms it too:
The underlying XMLList for this collection. The XMLListCollection object does not represent any changes that you make directly to the source XMLList object. Always use the XMLListCollection methods to modify the collection.
This property can be used as the source for data binding. When this property is modified, it dispatches the listChanged event.
I'm asking because Flex examples related to dataProviders always use some Array or XMLList as source of data for a data-driven component. And I wonder, if using Array or XMLList is necessary at all - when for example loading data from external PHP-script.
Using collections ArrayCollection or XMLListCollection, you can apply sorting or filter to them. In this case source will return all the elements in original order without applying filter. I often use source this way. Adding and removing items from collection also modifies original source array.
What about using collections or arrays as data provider, you can use them all in MX lists but Spark lists can only accept IList's which implemented by collections mentioned above.
The advantage of using collections as data provider is in possibility to apply filters and sorting without modifying of original array. And of course possibility to listen collection's changes.
Using pure Array or XMLList in samples, I suppose, is for simplicity and some implementation details of particular client-server interaction.

Writing changes from editable datagrid back to local data store - Adobe Air/Flex

I am using Adobe Air to get data from SalesForce, and present it in a datagrid.
I am using a query to get the data, and then put it into an arraycollection that is bound to the datagrid, this works correctly and the data is displayed.
I have made the datagrid editable, and I am able to change the values in the datagrid, but I cannot find how to save the changes to the local database.
I am using the following code:-
protected function VisitReportGrid_changeHandler(event:ListEvent):void{
app.wrapper.save(VisitReportGridProvider)
}
But this has the following error when I try and compile it:-
1067: Implicit coercion of a value of type mx.collections:ArrayCollection to an unrelated type mx.data:IManaged.
Obviously I am doing this wrong, but I cannot find the correct syntax.
Thanks in advance for your help
Roy
This code is not enough to understand where actually is the problem
Need to know what is VisitReportGridProvider, what is wrapper.save() method.
**after comment:
F3DesktopWrapper.save():
public function save(item:IManaged):void
Saves the specified Managed object to the local database. You must make an explicit call to syncWithServer() to update the data on the salesforce server. However, do not call syncWithServer() too often (batch your save calls) as this may use up your alloted API usage. If the item is in conflict, the conflict will be resolved.
Parameters:
item:IManaged — The managed object to create or update.
you're passing parameter with type ArrayCollection which doesn't implement IManaged interface.
You need to pass the item in the ArrayCollection that was changed to the save function. Like:
acc.fieldCollection.updateObject(new AsyncResponder(function(o:Object, t:Object):void {
app.wrapper.save(o as Account);
}, function(e:Object):void {
}));

Resources