Google Maps - Access object returned by getbounds - google-maps-api-3

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)

Related

Google Maps JS 3 addGeoJson data layer callback when loaded

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.

R Shiny: Does the Input object store the type of input

I'm trying to create a parameter file for my app that the user can upload to re-populate all input fields with the inputs they had used in a previous session.
I know I can get the names and values of all the inputs using reactiveValuesToList(input), but does the 'input' object store the kind of input (text, slider, radioButtons, etc.) anywhere? I'm hoping that there's an easy way to identify the type so I can use the correct update*Input function without using a daisy chain of tryCatches.
Also, is there any way I can learn more about the structure of the input object? Using str(input) isn't really helpful, and I was wondering if there was any good documentation on what all the parts mean and where to find it.
Most of the advanced features of shiny can be found in one of the articles here:
https://shiny.rstudio.com/articles/
You can also find the reference here for all the functions:
https://shiny.rstudio.com/reference/shiny/latest/
What you are trying to do is very similar to bookmarking your app. It is possible that the functionnality you are looking for is already implemented:
https://shiny.rstudio.com/reference/shiny/latest/enableBookmarking.html
Otherwise, if it does not do the trick, you can use session and the onSessionEnded function to save a table with your parameter as it is when closing then use that table to initialise your parameter when the user connect again.

Generating switch-case function out of State chart

Although my question is very simple I can't find an answer for it.
I created a class in Rhapsody and associated a statechart to this class but when I generate the code I can't find and code in the class related to the state chart.
Is there any function that needs to be created as a trigger or am I missing something?
my example state chart:
After searching for a long while I could find the option that was preventing the generation.
First of all, you need to define a reactive class to be able to generate a code for a state machine. This point was OK for me and I thought this was only what matters until I found this property here:
The _CG::Statechart::StatechartStateOperations property
determines whether the code is generated for this feature. The
possible values for this property are:
None (default value) where code is not generated for the feature.
WithoutReactive where the product does not generate calls to OMReactive
WithReactive where the product generates calls to OMReactive

Mixing Google Maps custom overlays with Backbone Views

TL;DR
Is PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype) the "proper" way to have a Backbone View inherit from another "class"?
Long read
We're redoing our site using Backbone and are working on including some mapping functionality.
I've got a Backbone view that handles placing <div>s onto specific points within the browser window; this seems like a natural thing to extend in order have Google's Map API place them on geographical coordinates.
According to the Google API, in order to generate a custom overlay you create a new object and set the prototype for that object to a new instance of google.maps.OverlayView. You then implement three functions on top of that object so that the object responds to:
onAdd
draw
onRemove
Where onAdd is responsible for generating the HTML and then applying it on top of the Map. This subsequently calls draw which positions the element correctly according to the LatLng pairs and bounds you've provided. onRemove gets called when you want to get rid of your layer.
So I've modified my View to include these three methods (which just call render and unrender and are bound to my collection). And then to make "the magic happen" I'm doing:
PinView.prototype = _.extend(PinView.prototype, google.maps.OverlayView.prototype)
Does this look right? I can post the code for the View and the Model on which it's based, but honestly, they're irrelevant to this example -- the code works and I'm able to place custom divs generated through Backbone model, view and controller components on the map without a issue, what I'm asking I guess (and maybe this question is more apropos for programmers.se, so let me know and I'll move it).
This seems to be the easiest way to make my PinView both a Backbone View and a Google Maps OverlayView, but I'm not 100% comfortable with prototypal inheritance to know if I'm doing something "wrong" or breaking something somewhere down the road.
Nice idea! I'm usually a bit sceptical about weather or not you're 'correct' when things work so if you haven't run into a showstopper and the overlays shows up and does what the're supposed to do I'd say you are.
One thing to check out closer, though:
This isn't (and can't) be "real" multiple inheritance - that concept isn't really relevant in a prototype based language: one implementation of a method will inevitable "win" and overwrite the other implementation, at least when using _.extend()
This means that if there are members or methods with the same names in Backbone.View and google.maps.OverlayView the one last in your _.extend() call will be the one that takes over. But when I inspect them using Chrome's Developer Tools I didn't see any obvious collision of this kind.
So my recommendation: continue using this, just test a lot. I'd love to see an example of this technique some time.
Ah! So I've been doing the above, but it's never felt right.
Then I found this discussion on a Backbone group which leads me to the following:
var MyView = (function(){
var view = function(){
Backbone.View.apply(this, arguments);
};
view.extend = Backbone.View.extend;
_.extend(view.prototype, Backbone.View.prototype, google.maps.OverlayView.prototype, [other prototypes...], { [VIEW DEFINITION] });
return view;
}());
This way if we need to override any of the definitions in a class we're extending from, we can since it's earlier in the _.extend chain (later definitions overwrite earlier definitions).
I'm working on 'extending' extend to keep track of the "parent" object's references that would be overridden and providing a method to call them still (like Python's super call). I haven't decided if this should be done through monkey-patching, an intercepter pattern (via underscore's _.tap() method or something else, but I think it'll add a lot of flexibility.
This would allow you to define an initialize view in your "parent" class which could be called by doing something like _.super('ParentClass', 'initialize'); at the end of the "child" class's initialize routine...

Adding and removing markers in openlayers on Drupal after page-load

I have to change the data set displayed on a map according to selections on the page and I would like to do this by creating several marker layers then switching between them based on user input.
For some reason I cannot add a layer after the map has been rendered on the page, seems like it shouldn't be that hard I think I may have the syntax wrong since the way Drupal sets up the map is different from straight forward openlayers.
Can I not get the map object like
var map = Drupal.settings.openlayers.maps["openlayers-map-auto-id-0"];
then add and remove marker layers from it? maybe there's another way of getting it?
Any help appreciated,
- Chris
The Drupal OpenLayers module only stores settings in Drupal.settings.openlayers.maps.
What you need is something like this:
var ol = $('#openlayers-map-auto-id-0').data('openlayers');
var max_extent = ol.openlayers.getMaxExtent(); // Or some other OpenLayers method...
...
The actual OpenLayers instance (as well as a copy of the map-specific settings) are stored with jQuery's .data() method. When you call $('#map-id').data('openlayers') you'll get back an object with map and openlayers members that correspond to the map settings and the actual OL object instance, respectively.
You might want to consider writing an OL behavior to handle your use case -- check out the default behaviors provided by the Drupal OpenLayers module to get a sense of how this works.

Resources