[OpenLayers-Users] Aligning label below Vector feature?

Arnd Wippermann arnd.wippermann at web.de
Fri Oct 16 13:50:19 EDT 2009


Hi,

I have VML.js modified in this way

var xOff = 0;
var yOff = 0;

if (style.labelOffsetX)
    xOff = parseInt(style.labelOffsetX);
if (style.labelOffsetY)
    yOff = parseInt(style.labelOffsetY);

label.style.left = (location.x/resolution - this.offset.x + xOff).toFixed()
+ "px";
label.style.top  = (location.y/resolution - this.offset.y + yOff).toFixed()
+ "px";

An example with ExternalGraphic and Aligned Labels
http://gis.ibbeck.de/OLClient/OLClient.asp?WMC=./data/WMC/ExternalGraphic_an
d_Labels.wmc.xml

Arnd


-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von And.
Gesendet: Freitag, 16. Oktober 2009 18:57
An: users at openlayers.org
Betreff: Re: [OpenLayers-Users] Aligning label below Vector feature?


"I even tried
my hand at hacking OpenLayers.js directly to move _all_ labels 20px or so
down, but couldn't find the right spot.  Any ideas?" 

You can try it:
        var offsetX = style.labelOffsetX ? style.labelOffsetX : 0;
        var offsetY = style.labelOffsetY ? style.labelOffsetY : 0;
        
        var x = (location.x / resolution + this.left + offsetX);
        var y = (location.y / resolution - this.top + offsetY);

In the renderer class SVG.js. It works with SVG (setting the attributes
"labelOffsetX" and "labelOffsetY" in the style of the feature).
But you'll have to do something like it in the class VML.js to work with VML
too.

Good luck.

Regards,
Andre.


Jani Patokallio wrote:
> 
> Greetings,
> 
> The new (for me!) text label feature for Vectors rocks, but is there 
> any way to align the label *below* the associated feature?
> 
> To be specific, I'm using externalGraphics to create icons, and I'd 
> like to center graphic at the point of interest and put the label below
it.
> It would be trivial to put the text at the exact location (align: 
> "cm") and use graphicYOffset to move the icon out of the way, but when 
> zoomed out the icon would then be pointing at the wrong place, which 
> is not acceptable.
> 
> As a semi-workaround, I managed to shift the label to the lower right 
> corner of the icon by using "align: lt" and padding the label with 
> "\xA0\xA0" (Unicode non-breaking space), but this doesn't properly 
> account for the width of the icon.  Moving the label to be below the 
> image with \r, \n or \x-equivalents thereof doesn't work.  I even 
> tried my hand at hacking OpenLayers.js directly to move _all_ labels 
> 20px or so down, but couldn't find the right spot.  Any ideas?
> 
> Cheers,
> -jani
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

--
View this message in context:
http://n2.nabble.com/Aligning-label-below-Vector-feature-tp3835113p3836752.h
tml
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list