【发布时间】:2015-03-17 13:11:09
【问题描述】:
我正在使用 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);
任何帮助将不胜感激!谢谢
【问题讨论】:
-
请添加答案作为答案,而不是作为问题的编辑。
标签: javascript openlayers gis