OpenLayers.Layer.Text 在 0,0 处显示图标

OpenLayers.Layer.Text displays icons at 0,0

我正在使用 OpenLayers 2.13.1 中的文本层来显示地图上的点列表。问题是图标总是放置在点 0,0(非洲湾)而不是它们自己的位置。

我也尝试过 OpenLayers.Marker 但从未改变。

在这两种情况下,我只是在 openlayers api 文档上使用示例。

这里是代码:

// WIDGETS
var map, dragpan, toolbar;

// OPENLAYERS
var gmap;
var aMapLayers = [];

// MAP
var url = 'http://' + constants.ip + constants.geoserver;
var panZoom = new OpenLayers.Control.PanZoom();
panZoom.onButtonClick = function(evt) {
    var btn = evt.buttonElement;
    switch (btn.action) {
        case 'panup':
            this.map.pan(0, -this.getSlideFactor('h'));
        break;
        case 'pandown':
            this.map.pan(0, this.getSlideFactor('h'));
        break;
        case 'panleft':
            this.map.pan(-this.getSlideFactor('w'), 0);
        break;
        case 'panright':
            this.map.pan(this.getSlideFactor('w'), 0);
        break;
        case 'zoomin':
            this.map.zoomIn();
        break;
        case 'zoomout':
            this.map.zoomOut();
        break;
        case 'zoomworld':
            proj = new OpenLayers.Projection('EPSG:4326');
            point = selectMarketMap();
            map.setCenter(point.transform(proj, map.getProjectionObject()), 6);
        break;
    }
};

map = new OpenLayers.Map('map', {
    div: 'map',
    projection: 'EPSG:900913',
    displayProjection: 'EPSG:4326',
    controls: [panZoom, new OpenLayers.Control.Navigation()]
});

// PAN/DRAG CONTROLS
dragpan = new OpenLayers.Control.DragPan();
map.addControl(dragpan);

// LAYER GOOGLE MAPS
gmap = new OpenLayers.Layer.Google('Google Streets', {
    numZoomLevels: 20
});

aMapLayers = [gmap];

var text = new OpenLayers.Layer.Text('text', {
    location: './js/textfile.txt'
});
aMapLayers.push(text);

map.addLayers(aMapLayers);
map.addControl(new OpenLayers.Control.LayerSwitcher());

proj = new OpenLayers.Projection('EPSG:4326');
point = selectMarketMap();
map.setCenter(point.transform(proj, map.getProjectionObject()), 6);

如有任何帮助,我们将不胜感激!谢谢

解决了向文本层添加投影的问题:

var text = new OpenLayers.Layer.Text('text', {
    location: './js/textfile.txt',
    projection: map.displayProjection
});