[OpenLayers-Users] Vector labels at different zoom levels
Arnd Wippermann
arnd.wippermann at web.de
Mon Apr 12 18:09:33 EDT 2010
Hi Jeff,
that's the styleMap I use to get the effect. Still in IE the labels with the
font-size = 0px will drawn in very small letters?!
Labels are a function of the zoomlevel (context) and the features are a
function of the attribute popClass (UniqueValueRules).
var styleMapCapitols;
function setStyleMapCapitols()
{
var context = {
getFontSize : function(ft){
var diffZ = map.getZoom() - 4;
var popclass = parseInt(ft.attributes.popclass);
if(popclass > 10 && map.getZoom() > 1)
return(map.getZoom() + 7 + "px");
else if(diffZ > 0 && popclass>9)
return (10 + 1*diffZ +"px")
else if(diffZ > 0)
return (8 + 1*diffZ +"px")
else
return("0px");
},
getName : function (ft){
return ft.attributes.name;
}
};
var template = {
strokeColor: "#0000FF",
strokeOpacity: 1,
strokeWidth: 3,
fillColor: "#00AAFF",
fillOpacity: 1,
pointRadius: 5,
pointerEvents: "visiblePainted",
label : "${getName}",
labelOffsetX: "10",
labelOffsetY: "-10",
fontColor: "red",
fontSize: "${getFontSize}",
fontFamily: "Arial",
fontWeight: "bold",
labelAlign: "lt"
};
styleMapCapitols = new OpenLayers.StyleMap(new
OpenLayers.Style(template, {context:context}) );
var tata = {fillColor: '#FFAADD', pointRadius: 5, label :
"${getName}",labelOffsetX: "10",labelOffsetY: "20",fontColor:
"yellow",fontSize: "${getFontSize}",fontFamily: "Arial",fontWeight:
"bold",labelAlign: "lt"}
var popArrO = [0.5 , 0.5 , 0.5 , 0.5 , 0.5 ,
0.5 , 0.5 , 0.5 , 0.75 , 0.75 , 0.75];
var popArrW = [1 , 1 , 1 , 1 , 1 , 1
, 2 , 2 , 2 , 2 , 2 ];
var popArrR = [2 , 2 , 3 , 3 , 4 , 4
, 5 , 5 , 6 , 7 , 10];
var popArrC = ['#FFFF00', '#00FF00', '#AA00FF', '#0000FF', '#FF8800',
'#FF0000', '#FFAAAA', '#AAFFAA', '#AAAAFF', '#FF00FF', '#FF00AA'];
var lookup = {}; //popclass beginnt mit 1!
for(var i=0;i<11;i++)
lookup[i+1] = new OpenLayers.Util.applyDefaults({pointRadius:
popArrR[i], fillColor: popArrC[i], fillOpacity: popArrO[i], strokeWidth:
popArrW[i], strokeColor: popArrC[i]}, tata);
styleMapCapitols.addUniqueValueRules("default", "popclass", lookup);
}
setStyleMapCapitols();
an example:
http://gis.ibbeck.de/OLClient/OLClient.asp?KARTE=k10000
Arnd
_____
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von Jeff Dege
Gesendet: Montag, 12. April 2010 22:19
An: users at openlayers.org
Betreff: [OpenLayers-Users] Vector labels at different zoom levels
I'm adding some attributes to the GML data I'm using to draw a vector layer,
and have set the label member of the style object to display those
attributes.
It works fine, except that it looks lousy when I zoom out. The labels are
still drawn the same, even though the features may be nearly invisible.
How do I turn off the rendering of labels, when the scale exceeds some
threshold? (Note - I still want to draw the features, I simply don't want
the labels.)
I've tried adding a listener to map.movestart, that changes the value of
layer.styleMap.styles['default'.defaultStyle.label, but that only affects
future renderings of the map, it has no effect on the current zoom.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100413/e9428795/attachment.html
More information about the Users
mailing list