簡體   English   中英

OpenLayers.Layer.Text在0,0顯示圖標

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

我正在使用OpenLayers 2.13.1中的Text圖層在地圖上顯示點列表。 問題在於,圖標始終放置在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
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM