Problem/Motivation
Hi,
I was working this afternoon with Openlayers Styles and I wondered if images styles from Drupal core (Imagecache in D6) could be applied to Openlayers styles (Icons for markers).
Also in Views, it should be possible to use a image field as a marker for Openlayers, so I could leverage the power of image styles directly.
Proposed resolution
Add a new 'Openlayers' formatter and provide options.
Remaining tasks
Implementing Tokens in Openlayers formatter's form (in Views).
User interface changes
- New 'Openlayers' formatter with image field in Views.
- New Openlayers style form when you select the 'Openlayers' formatter.
- New select box in the Style form with image styles as options.
API changes
No API changes at first sight.
Original report by Pol
Comments
Comment #1
polHere's a first working version of the patch, implementing the second solution, it adds a select box in the style form.
Comment #2
polNew patch working flawlessly.
It also fix a problem in the styles add/edit form.
The form function
openlayers_ui_styles_formis using a preview function to generate the preview style on the right.This form element calls:
'#markup' => openlayers_ui_style_preview($preview_style, TRUE),The function openlayers_ui_style_preview calls:
The function
openlayers_render_stylemodify the icon path and return the style array.As
$preview_styleis passed by reference, the $style in the form functionopenlayers_ui_styles_formgets modified and if you used a relative path for the icon former, you'll be getting an absolute path after submit, which is not good.I made a trick to copy the
$preview_fileinto a new variable, even if you change it, it will not alter the original$style.Maybe there is a better method to do it, just let me know, I'm waiting for feedback.
Comment #3
polNew version of the patch, allowing us to see the styles applied on the icon in the styles list.
Comment #4
zzolo commentedHey @Pol. Thanks for your work on this. I have some questions and reservations, though.
On a similar note, it would be really cool to get the URL of an image field in Views and use that as the value (obviously supporting Styles). The issue with this is that the Views integration with Image field does not provide a URL.
Let me know what you think.
Comment #5
polHi @zzolo,
There is no dynamic but it's a cool feature, knowing that if you want to have your style in different style, now you can do it.
You can get url with
image_style_urlor a path withimage_style_path.On a similar note, it would be really cool to get the URL of an image field in Views and use that as the value (obviously supporting Styles). The issue with this is that the Views integration with Image field does not provide a URL.
That is also something to do and probably my next thing to do 'in the train' :-)
Do you already have some ideas, paths to follow to do it ? Anything is welcome.
On the other hand, have you checked the problem described in comment #2 ? That's something to fix for next release...
Thanks !
Comment #6
nod_To avoid serialize/unserialize, you could use
clonedepending on what the variable is.and zzolo was talking about openlayers' style API, not Drupal's image one.
Comment #7
polHi @nod_,
I tried with
cloneand it doesn't works, that's why I usedunserialize/serialize.Comment #8
polHello,
I talked with @zzolo and he gave me a couple of advice for this patch:
And that's what I did.
The comments #2, #6 and #7 are now obsolete.
Comment #9
polHello,
I made a new patch fixing the problem that @zzolo talked in comment #4:
This is a first working patch for a Views Integration for styles.
Test it and let me know what to improve.
I will add support for token soon.
How to use it ?
So, in a few words, now when you add a Openlayers Data Overlay, you are able to map a Style field.
The Style field must be an image (obviously), it means that a image field should exists in the fields list.
You also have to choose the 'Openlayer' formatter for images.
There you will be able to configure the style as it was added manually in Openlayers.
Dont forget, If you map a Style field, the style settings in the edit map form will be overriden and useless.
Comment #10
dasjoComment #11
polUpdated patch for 7.x-2.x.
Comment #12
polIt looks like I forgot an important patch in the last patch, I fixed it with this.
This patch has been tested and showed in a presentation, so, I know it's working :-)
Comment #13
polI added a new feature to the patch.
By default, if no 'graphicWidth' and 'graphicHeight' are set, it will use 12 (pixels) for each.
It would be cool to set automatically those to the width and height from the generated image.
This is done in that part of the patch:
Comment #14
polIs there someone available to review this patch ?
Comment #15
zzolo commentedAnyone else tested this yet? Also, moving to 3.x; seems like too big of a feature to add now to 2.x
Comment #16
polComment #17.0
(not verified) commentedUpdate issue.