[英]Openlayers Labels: Prevent displaying of .123 as 0.123
So i am getting some Text from a database and put them as Points on a Vector Layer and put the Text into a Label. 所以我要从数据库中获取一些文本,并将它们作为点放在矢量层上,然后将文本放入标签中。 Problem is that some of the Text thats starts with a '.'
问题在于某些文本多数民众赞成在以“。”开头 following some numbers like are treated like numbers and receive a '0' at the beginning.
在某些数字后面跟随,就像数字一样,并在开头接收“ 0”。
For Example: ".341" is shown as "0.341". 例如:“。341”显示为“ 0.341”。 Internal the Text comes from the Database as ".341", pre Feature insert it is ".341" and after Feature insert it is still ".341".
内部文本从数据库中以“ .341”形式出现,在功能部件插入之前的文本为“ .341”,在功能部件插入之后的文本仍为“ .341”。 Also with typeof i always get "string".
同样使用typeof,我总是得到“字符串”。
In following Code you can see where the label is set: 在以下代码中,您可以看到标签的设置位置:
var style = new OpenLayers.Style({
fillColor: "#ffcc66",
strokeColor: "#ff9933",
strokeWidth: 2,
label: "${text}",
fontColor: "#333333",
fontFamily: "sans-serif",
fontWeight: "bold"
}
If anyone got a clue how to prevent it to be written with '0', would be much appreciated. 如果有人知道如何防止将其写为“ 0”,将不胜感激。
Since i haven't found a way to do it with any options, i went ahead and found the code thats responsible. 由于我还没有找到使用任何选项的方法,因此我继续寻找负责的代码。 Copy pasted into my .js to overwrite it and outcommented the line responsible:
复制粘贴到我的.js中以覆盖它,并超过负责的行的注释:
OpenLayers.Style.createLiteral = function(value, context, feature, property) {
if (typeof value == "string" && value.indexOf("${") != -1) {
value = OpenLayers.String.format(value, context, [feature, property]);
//value = (isNaN(value) || !value) ? value : parseFloat(value);
}
return value;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.