Ticket #1426 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

KML icons misalign with hotSpot nodes

Reported by: rdewit Owned by: tschaub
Priority: minor Milestone: 2.6 Release
Component: Format.KML Version: SVN
Keywords: Cc:
State: Complete

Description

KML Icons with hotSpot settings misalign. This is because the offset is not calculated properly. Thanks to Lance Dyas for reporting this issue.

The attached patch properly calculates the offset for hotSpot nodes. Please note that offset units in 'pixels' only work correctly when the image size is 32x32 pixels *or* when a width <w> and/or height <h> are defined in the Icon node (deprecated in KML 2.2beta). In all other cases, please use 'fraction' as units. This is because OL cannot automatically determine the size of the icon.

Bonus improvements:

  • implemented 'scale' node parsing
  • fixed a typo in the inline style handling

Works in both FF2 and IE6 and tests pass

Attachments

kml_styling_hotspots.diff Download (5.4 KB) - added by rdewit 5 years ago.
kml_styling_hotspots_v2.diff Download (6.1 KB) - added by rdewit 5 years ago.
Fixed bug in y offset (fractions) + added 'magic' to 'know' that certain URLs are 64x64 pixels (maps.google.com/mapfiles/kml).
kml_styling_hotspots_v3.diff Download (6.4 KB) - added by rdewit 5 years ago.

Change History

Changed 5 years ago by rdewit

Changed 5 years ago by rdewit

Fixed bug in y offset (fractions) + added 'magic' to 'know' that certain URLs are 64x64 pixels (maps.google.com/mapfiles/kml).

  Changed 5 years ago by rdewit

There was a small bug in the y offset for fractions hotspots (fixed). Also added a clause where urls that start with maps.google.com/mapfiles/kml, the icon size is 64x64. Seems to work in most cases, but feels a bit hacky.

Please review patch kml_styling_hotspots_v2.diff

  Changed 5 years ago by crschmidt

The only hacky problem I have with the google URLs (since your logic seems correct) is that we have to multiply the scale by .5, but that seems to be what Google Maps does, so that's not your problem, it's Google's/KML's.

I have a problem here though: in most places, you've multiplied 'x' by scale, but x is a string, not a number, since you don't ever call parseFloat/int on it, do you? Is that okay? In fact, I'm not even sure that you should be multiplying y times scale: the scale is for the size of the icon (which should be used for calculating height/width), *not* scaling the offset, especially not in the pixels case...

I also think that some of your calculations may be wrong. In our scheme, a negative offsetHeight pushes the image up the page. This means that in order to get the bottom, left 0,0 coordinates that KML wants, we have to have our offsetHeight be the *negative* of our graphic height by default. IT looks like this is *not* the case when yUnits is 'fraction'. In my code, I implement this with:

 style["graphicHeight"] * (parseFloat(y)-1.0);

I think you need the same here.

All the others are correct.

  Changed 5 years ago by crschmidt

My comments on scale are wrong: multiplying by it is right (but I still think we need to parseFloat on x/y before we do).

  Changed 5 years ago by crschmidt

  • state changed from Review to Needs More Work

  Changed 5 years ago by rdewit

  • state changed from Needs More Work to Review

Thanx for your input crschmidt. Patch v3 should fix the issues that you mentioned: - parseFloat before doing any calculations - yunit fractions were wrong

Please review this one.

Changed 5 years ago by rdewit

follow-up: ↓ 7   Changed 5 years ago by crschmidt

  • state changed from Review to Needs More Work

I commented on this on IRC, but not here:

Since we're calling parse* on all of these, we should centralize, and just call parseFloat on the x/y when we extract them, rather than separately in each if block.

in reply to: ↑ 6   Changed 5 years ago by rdewit

Replying to crschmidt:

I commented on this on IRC, but not here: Since we're calling parse* on all of these, we should centralize, and just call parseFloat on the x/y when we extract them, rather than separately in each if block.

I replied on this on IRC, but not here: ;-)

Does patch v3 not fix this (this is a new v3, I overwrote the old one)?

  Changed 5 years ago by crschmidt

  • state changed from Needs More Work to Commit

Indeed! Thanks. I'm going to commit this now.

  Changed 5 years ago by crschmidt

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [6494]) Apply patch from rdewit to fix parsing of hotSpot values on Icon objects in KML styles. This fixes issues reported with the location of icons when using KML styling. r=me (Closes #1426)

  Changed 5 years ago by rdewit

  • status changed from closed to reopened
  • state changed from Complete to Needs More Work
  • resolution fixed deleted

As crschmidt reported on IRC: this fix breaks KML in IE6/7. I will look into it today and provide a new patch.

  Changed 5 years ago by crschmidt

I think htis is probably just a sideeffect of #1428, not related to your work.

  Changed 5 years ago by crschmidt

  • state changed from Needs More Work to Awaiting User Feedback

I'm reasonably certain this was just a side effect of #1428. IF we could check  http://dev.openlayers.org/sandbox/euzuro/pop/examples/sundials.html in IE6 / IE7 , and you see sun icons, that means this bug can be closed.

  Changed 5 years ago by crschmidt

  • status changed from reopened to closed
  • state changed from Awaiting User Feedback to Complete
  • resolution set to fixed

I've confirmed that this works in IE7 now. I think this means that this is fixed; closing pending any further reports of the issue.

Note: See TracTickets for help on using tickets.