嗨我正在试图在地图上打印一组标签(OSM),问题是我不知道如何在特定坐标上设置这些标签,标签出现在地图上,但它就像我没有设置坐标我附上来源。
var vectorLayer = new OpenLayers.Layer.Vector("Etiquetas", {
styleMap: new OpenLayers.StyleMap({'default':{
strokeColor: "",
strokeOpacity: 1,
strokeWidth: 3,
fillColor: "",
fillOpacity: 0,
pointRadius: 6,
pointerEvents: "visiblePainted",
label : "${etiqueta}",
fontColor: "${favColor}",
fontSize: "10px",
fontFamily: "Courier New, monospace",
fontWeight: "bold",
labelOutlineColor: "white",
labelOutlineWidth: 3
}},{ visibility: true, displayInLayerSwitcher: true })
});
var pointFeature;
var point;
for (i = 0; i < elementos.length; i++) {
var datos_ubicacion = elementos[i].split("|");
if (datos_ubicacion[0] != "") {
var long = parseFloat(datos_ubicacion[7]);
var lati = parseFloat(datos_ubicacion[6]);
var coordenada = new OpenLayers.LonLat(long,
lati).transform(new OpenLayers.Projection('EPSG:4326'),
map.getProjectionObject());
point = new OpenLayers.Geometry.Point(lati,long);
pointFeature = new OpenLayers.Feature.Vector(point);
pointFeature.attributes=
{
etiqueta: datos_ubicacion[1],
favColor: 'black'
};
}
}
map.addLayer(vectorLayer);
}
vectorLayer.addFeatures([pointFeature]);
我解决了,只需要进行坐标转换
var point = new OpenLayers.Geometry.Point(long,lati);
point = point.transform(new OpenLayers.Projection('EPSG:4326'),
map.getProjectionObject());
pointFeature = new OpenLayers.Feature.Vector(point);