-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map instance and behavior settings #110
Comments
Something that still needs more thought is the "make behaviors more reusable" piece. I believe that instance + behavior settings are a prerequisite for this and specific behaviors can be tackled separate of this issue, but want to leave one idea I'm pondering: a reusable "zoom" behavior. There's already an |
@paul121 I like where this is going - especially the part about making a Just to play devil's advocate though;
|
Good question, I had kind of forgotten about this really. But looking at implementations it seems like it's only used for one thing really, and it's not really a behavior "setting". The only core behaviors that use it are But obviously a Interestingly, the core farmOS-map behaviors load
Right, a new "mechanism" probably isn't necessary. Part of the problem is that Drupal modules can't populate the I think
Yes! Instead of a hook there is a Instead of that, I'd like to propose behaviors start populating their settings specific to each map instance from which
Yeah, fair question. I suppose this depends on the nature of the setting and behavior... Just as an example, obviously it would be a lot of work to have a control to toggle the But looking forward to bringing more capabilities into the map it would be great to have this ability. Not so much changing "settings" over time, but changing the "state" of the map is better way to think of it? The |
Maybe it's useful to make a distinction between one-off behaviors which target a limited page/purpose vs ones which provide general functionality and are likely to need configuration on a per-page or per-instance basis. Currently the recommended way to add a behavior is via (function () {
farmOS.map.behaviors.myMapCustomizations = {
attach: function (instance) {
// Do something here - perhaps parameterized on global state or `instance.target` (elem id)
},
};
}()); Even with the current API you can have a "glue behavior" which delegates to a more general behavior and passes page/instance specific settings; (function () {
farmOS.map.behaviors.myMapCustomizations = {
attach: function (instance) {
instance.attachBehavior(window.someOtherBehaviorRegistery.generalAwesomeness, { /* settings here */ });
},
};
}()); In my 2.x playground PR, I've simplified this a little by exposing the "registry" where That means that the above example could be simplified to; (function () {
farmOS.map.behaviors.myMapCustomizations = {
attach: function (instance) {
instance.attachBehavior('generalAwesomeness', { /* settings here */ });
},
};
}()); I guess the point I'm trying to make is that the farmOS-map API could already be considered functionally complete - even without my 2.x changes. Behaviors already can be configured at a fine-granularity just by not putting behaviors that need per-instance customization into I'd argue that this issue should be a farmOS issue about what kind of API/patterns farmOS needs to have for plumbing settings/data gracefully into farmOS-map. New requirements for the farmOS-map API clearly could emerge from there, but I'm not sure it's necessary. |
Why?
Started exploring this idea in #94 - we might not have the need for "multiple maps" on a page, but many of these limitations could be addressed to improve support of "configurable maps" and reusable behaviors.
Many of our current Drupal behaviors define "global" behavior settings in the
Drupal.settings.farm_map.behaviors.{behavior_name}
JS namespace. When these behaviors are attached, they use these variables to change what they do (hence I'm calling them "settings", could also be considered "state"). Some behaviors also depend on "instance specific" settings in a similar way:Drupal.settings.farm_map.wkt[instance.target]
.Also, in farmOS 2.x we've created both "map type" and "map behavior" config entities. Config entities are a great mechanism for providing low-code configuration and would be a great way of providing these map instance and behavior "settings".
What's missing? A standard interface to provide map-instance specific "settings" in farmOS-map! This would have some benefits:
settings.behaviors.popup.enabled
. This provides a standard place for behaviors and controls to provide settings. It also allows for one behavior to modify another behaviors settings (throughout the lifetime of the map in a page)Example
A good example of both "behavior settings" and "instance settings" is the WKT behavior:
Implementation
I think we have a few options here...
A simple option might be to add
instance.getSettings()
/instance.setSetting()
methods to the farmOS-map instance itself. Perhapsinstance.getBehaviorSettings()
/instance.setBehaviorSetting()
helper methods as well. Thesettings
object could live on the instance here: https://github.com/farmOS/farmOS-map/blob/1.x/src/instance/instance.js#L27A more robust (and even simpler?) option might be to use what's already available to us! The OL Map extends the OL BaseObject which provides the concept of "properties" and relevant methods that we could reuse for this purpose:
get(), getKeys(), getProperties(), set(), setProperties(), unset()
. Since BaseObject extends Observable each of these properties can be observed as well:instance.map
but provide some helper methods oninstance
?The text was updated successfully, but these errors were encountered: