Ticket #893 (closed feature: fixed)

Opened 5 years ago

Last modified 5 years ago

specify externalGraphic offset

Reported by: fredj Owned by: fredj
Priority: minor Milestone: 2.5 Release
Component: Layer.Vector Version: SVN
Keywords: Cc:
State:

Description

It would be nice if externalGraphic handle offset just like OpenLayers.Layer.Markers does.

Example:

externalGraphic: "my_icon.png",
graphicWidth: 18,
graphicHeight: 26,
graphicYOffset: 0,
graphicXOffset: 9,
fillOpacity: 1

Attachments

externalGraphicOffset.code.patch Download (2.3 KB) - added by fredj 5 years ago.
Renderer/VML.js Renderer/SVG.js patch
patch-893-A0.diff Download (6.4 KB) - added by elemoine 5 years ago.
new patch based on fredj's (see comment)
patch-893-A1.diff Download (6.4 KB) - added by elemoine 5 years ago.
New patch fixing a stupid error in the tests. Still don't know if the tests pass on IE. I'll give it a try myself once I have IE handy.
patch-893-A2.diff Download (7.7 KB) - added by elemoine 5 years ago.
patch-893-A3.diff Download (8.0 KB) - added by fredj 5 years ago.
Fix the VML problems found in patch-893-A2

Change History

follow-up: ↓ 2   Changed 5 years ago by fredj

  • status changed from new to assigned

Changed 5 years ago by fredj

Renderer/VML.js Renderer/SVG.js patch

in reply to: ↑ 1   Changed 5 years ago by elemoine

  • keywords review added

Replying to fredj:

New patch based on fredj's. Applies to current SVN. Includes an example of use in vector-features.html. Adds appropriate tests in Layer/test_Vector.html. Tests pass on FF. Could someone run the tests on IE (no w$ handy)?

Changed 5 years ago by elemoine

new patch based on fredj's (see comment)

  Changed 5 years ago by crschmidt

  • milestone set to 2.5 Release

I'll review this and run tests in IE.

  Changed 5 years ago by crschmidt

Tests pass in IE.

  Changed 5 years ago by crschmidt

Actually, they don't. I've let Eric know what the failure is. (Sorry, I had two copies of OL accidentally and didn't know it.)

Changed 5 years ago by elemoine

New patch fixing a stupid error in the tests. Still don't know if the tests pass on IE. I'll give it a try myself once I have IE handy.

  Changed 5 years ago by crschmidt

New tests pass in IE now! (Really, this time.)

follow-up: ↓ 9   Changed 5 years ago by fredj

Thanks for to patch Eric.

The new can patch can cause problem if graphicXOffset or graphicYOffset are set to 0:

var xOffset = style.graphicXOffset || (0.5 * width);

set xOffset to "0.5 * width" because 0 is evaluated as false.

Other problem:

In test_Vector.html, near line 254 the test pass because root.firstChild.getAttributeNS(null, 'x') and (geometryX / renderer.getResolution() + renderer.left) both return NaN.

  Changed 5 years ago by crschmidt

  • keywords review removed

Removing review keyword. Eric, could you prepare a new patch?

Fred, thanks for reviewing this one.

in reply to: ↑ 7   Changed 5 years ago by elemoine

Replying to fredj:

Thanks for to patch Eric. The new can patch can cause problem if graphicXOffset or graphicYOffset are set to 0: {{{

var xOffset = style.graphicXOffset (0.5 * width); }}} set xOffset to "0.5 * width" because 0 is evaluated as false.

I fixed this by testing whether graphicX|YOffset is undefined or not, in the same way you did in your patch.

Other problem: In test_Vector.html, near line 254 the test pass because root.firstChild.getAttributeNS(null, 'x') and (geometryX / renderer.getResolution() + renderer.left) both return NaN.

Good catch! The problem came from the fact that renderer.setCenter() was never called resulting in renderer.left and renderer.top being not set. I added a map.zoomToMaxExtent() so that renderer.setCenter() gets called.

To be consistent with the way the original marker offset works, I also did this: graphicXOffset must be negative to offset the marker on the left, and graphicYOffset must be negative to offset the marker to the top (and vice versa).

Again, I haven't run the tests on IE, and they'll probably fail. Will do that as soon as I can. I'm posting the patch anyway, for fredj and others to review...

Changed 5 years ago by elemoine

follow-up: ↓ 11   Changed 5 years ago by fredj

I checked to code on IE and found a problem with graphicYOffset.

With the VML renderer, the y coordinates are flipped so the yOffset have to be flipped too.

To have a 'visual' check, apply the patch and load examples/vector-features.html: the bottom of the red marker (the one on the right) have to be exactly on the green point.

(hope you can understand my poor English)

The following patch fix the problem and the units tests.

(hope that my code is not as bad as my English ...)

Changed 5 years ago by fredj

Fix the VML problems found in patch-893-A2

in reply to: ↑ 10   Changed 5 years ago by elemoine

Replying to fredj:

I checked to code on IE and found a problem with graphicYOffset. With the VML renderer, the y coordinates are flipped so the yOffset have to be flipped too. To have a 'visual' check, apply the patch and load examples/vector-features.html: the bottom of the red marker (the one on the right) have to be exactly on the green point. (hope you can understand my poor English) The following patch fix the problem and the units tests. (hope that my code is not as bad as my English ...)

Thanks a lot fredj. The patch looks complete and good now.

  Changed 5 years ago by elemoine

  • keywords review added

  Changed 5 years ago by crschmidt

  • keywords commit added; review removed

Erik and I discussed this, and I'm willing to call this one ready -- commit when ready.

  Changed 5 years ago by elemoine

  • keywords commit removed
  • status changed from assigned to closed
  • resolution set to fixed

(In [4268]) allow user to specify offsets for externalGraphic (closes #893)

Note: See TracTickets for help on using tickets.