简体   繁体   English

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

[英]OpenLayers.Layer.Text displays icons at 0,0

I'm using Text layer from OpenLayers 2.13.1 to display a list of points on the map. 我正在使用OpenLayers 2.13.1中的Text图层在地图上显示点列表。 The problem is that icons are always placed at point 0,0 (Gulf of Africa) instead of at their own positions. 问题在于,图标始终放置在0,0点(非洲海湾)上,而不是位于其自身位置上。

I tried also with OpenLayers.Marker but never changes. 我也尝试使用OpenLayers.Marker,但从未更改。

In both cases I just used examples on openlayers api docs. 在这两种情况下,我仅在openlayers api文档上使用了示例。

Here the code: 这里的代码:

// 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);

Any help would be appreciated! 任何帮助,将不胜感激! Thanks 谢谢

Solved adding projection to text layer: 解决了将投影添加到文本层的问题:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM