打开图层不会在给定的纬度,lon中显示标签

时间:2016-12-26 07:57:40

标签: javascript openlayers

我尝试在开放图层中的某个点添加标签。可以看到标签,但它位于(0,0)点附近,而不是在给定的lat,lon点。

var point = new OpenLayers.Geometry.Point(lon,lat);
var label_feature = new OpenLayers.Feature.Vector(point);
    label_feature.attributes = {
        myLabel: "my label"
    };

    vector_layer.addFeatures([label_feature]);

这里是矢量样式的偏移值

labelXOffset: "0",
labelYOffset: "12",

我得到了渲染器

var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
                        renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;

由于

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案:

您只需要通过投影转换点:

var projection = new OpenLayers.Projection("EPSG:4326");
point = point.transform(projection, map.getProjectionObject());