This patch moves the vector style, originally defined in openlayers.layers.js, to a theme function - theme_openlayers_vector_styles() - so it can be overridden. Doing this also opens the door to setting creating the default style through the UI in the settings form.
I'm not convinced that what I've done here is the absolute best approach, but it solves the immediate issue. I'd be curious to hear your thoughts on this one.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | styles_hook.patch | 11.43 KB | rsoden |
| #3 | marker_theming_and_format.patch | 9.71 KB | tmcw |
| #2 | marker_theming.patch | 9 KB | tmcw |
| #1 | marker_theming.patch | 9.05 KB | rsoden |
Comments
Comment #1
rsoden commentedactually attaching the patch this time :)
Comment #2
tmcw commentedVersion of that patch minus the console.log() function calls :)
(never mind, that version sucks... improving on it now)
Comment #3
tmcw commentedHere's a fixed patch, with a few formatting improvements.
Comment #4
rsoden commentedThanks for the cleanup Tom :) Patch applies and works as advertised.
Comment #5
zzolo commentedHey. I was thinking about this earlier today. I think this should should be a hook. The reason why is to be able to support an interface of choosing styles. It also might make sense to have a theme function in between. So, here's the workflow that I am thinking.
1) Get styles from a hook.
2) Through the settings form, users can choose which styles to use for features or other stylistic places.
3) Run styles through a theme function in case someone wants to override what a specific style is.
I guess my main goal is to provide a collection of styles, like GMap does with markers, but something a little more simpler to extend. It also leaves a lot of room to do things like have different styles based on content type or taxonomy terms.
The theme only method is good and looks like it will work, but does it is only overrides instead of building a collection of styles.
Let me know what you think?
--
zzolo
Comment #6
rsoden commentedYeah, I think you're right. I'll take a stab at getting the hook built. I'll look at the GMap module re: 'a collection of styles.'
Thanks :)
Comment #7
zzolo commentedHere is what I imagine that goes along with how we have been doing our hooks. This is the hook_openlayers_styles_info().
Then this is the callback defined in the hook. There is not much reason to separate out each style into its own function, so we can just create a big array with options.
The OpenLayers API module would provide a couple defaults, then we could make a more in depth openlayers_styles module, as this has been how we have been doing similar things.
Also, since this is a very visual aspect of the site, it might make sense to run this through a theme, so that themers can simply override some of the styles that are defined without creating a whole new module and implementing hooks. Basically, it just passes the collected array of styles to a theme and by default returns it. Here's how it would look when putting together the styles array:
This would all be represented in a new fieldset in the settings form. There would be a dropdown of all styles for "default", "select", and "temporary" (though we dont really use this one).
Let me know what you think. It seems like a little much, but will provide the most flexibility. Also, this does not really address icons as marker, which is a shame. We could do something similar with that as well.
Also, I had noted in the views plugin that we should remove the style php code option if this hook/theme layer was implemented, but it would be really helpful to have the php provide the style for an instance where the feature will have a variable radius based on other data.
Comment #8
zzolo commentedOh, and we could get fancy and make a map on the settings form have a feature that is updated with the style choices via some JS. This way people can actually see what a style looks like before saving.
Comment #9
rsoden commentedAttached is the first pass at a styles hook for openlayers. It follows the same general pattern as the other hooks (layers,behaviors) provided. Forms at admin/settings/openlayers and views options have been updated.
The main thing missing here is an option for rules-based styling (making features bigger/smaller/different colors/etc) based on various attributes. This is obviously critical but I'm not sure I have an elegant way to implement this given the current architecture. There's a few non-elegant ways of doing it but I thought I 'd post this and see if anyone has thoughts/suggestions.
Comment #10
zzolo commented@rsoden,
Thanks for the patch. It looks good. The only problem I have with it is the way it works in the Views part. The styles (and control) options should be in the Settings Form (meaning the OpenLayers settings form), and then it is just a matter of getting the form to work in the plugin settings. We should be able to just add specific settings for the Views in the plugin, and use the existing from to customize the map itself.
As for rules based styles: I think this is important, but the best thing to do is use the PHP textarea that is in there now, and just make it a little better (making these changes will help a lot). First off, almost all use of rules-based styles would be in Views (though it could integrate with lots of things). Second, creating an interface for a rules system can get pretty complicated. It would be awesome if we could leverage an existing module. Token comes to mind, with Token Rules. But, again, I would put this down as post 1.0.
I am going to work on getting this patch in and making some changes to it.
Comment #11
rsoden commentedSounds great. Let me know when this goes in.
One question on the rules-based styles. Could you post a working example of code for the textarea that does this? I tried poking around a bit but wasn't able to get anything going. Would be great to get an example into the docs.
Comment #12
zzolo commentedCommited: http://drupal.org/cvs?commit=226994
Feel free to test out. Changing name to address the views PHP views thingy.
Comment #13
zzolo commentedSo, I fixed some bugs last night that were not allowing the default styling to work.
I alos tested out the Variable Styling in the Views Plugin, which does seem to work. Though it should probably support the four different kinds of styles for each feature, not just the default (if it is possible).
Heres my example function to use some fields to manipulate radius and color. Its not efficient, but the idea is there.
And then the code to go in the Views Plugin would be:
Comment #14
zzolo commentedI have changed the variable styles to use a theme function now. So the options form for the View Plugin simply is a checkbox to enable whether or not to look for the theme. The only problem I might see with this is exporting/importing views. But since variable styles is a visual thing, it makes sense. So, here is an example:
One could check the views name and display to change per view.
Comment #15
zzolo commentedSeems to be working fine. Marking as fixed. Please re-open or start a ticket if you run into any bugs.