gpt4 book ai didi

javascript - Openlayers源码tileWMS?类型错误 : a. addEventListener 不是函数

转载 作者:行者123 更新时间:2023-12-01 03:19:33 25 4
gpt4 key购买 nike

我想向我的瓦片 map 添加功能,当我尝试使用时出现问题

ol.source.TileWMS

错误信息是:

TypeError: a.addEventListener is not a function

但是它可以与

ol.source.OSM

我的代码:

var projection = new ol.proj.Projection({
code: 'EPSG:32719',
extent: [441867.78, 1116915.04, 833978.56, 10000000.00]
});

var extent = [576631.5686027373,8119272.722829757,655823.9357532839,8286730.359291008];

var wmsSource = new ol.source.TileWMS({
url: 'http://192.168.5.94:8080/geoserver/wms',
params: {'LAYERS': 'layer'},
ratio: 1,
serverType: 'geoserver'
});

var wmsLayers = [
new ol.layer.Tile({
extent: extent,
source: wmsSource
})
];

var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});

var source = new ol.source.Vector({wrapX: false});

var vector = new ol.layer.Vector({
source: source
});

var view = new ol.View({
projection: projection,
center: [593169.72792, 8174979.55243],
//center: ol.proj.fromLonLat([-16.5088, -68.1388], projection),
extent: extent,
zoom: 12
});

var map = new ol.Map({
controls: ol.control.defaults().extend([
new ol.control.ScaleLine()
]),
layers: [wmsLayers, vector],
target: 'map',
view: view
});

var draw; // global so we can remove it later

function addInteraction(){
draw = new ol.interaction.Draw({
source: source,
type: 'Point'
});
map.addInteraction(draw);
}

map.on('singleclick', function(evt) {
var coordinate = map.getEventCoordinate(evt.originalEvent);
console.log(coordinate);
document.getElementById('latitud').value = coordinate[0];
document.getElementById('longitud').value = coordinate[1];
addInteraction();
});

addInteraction();

只需更改此行即可更改我的图层,当我使用 OSM 时,一切正常...但是当我使用 TileWMS 时出现错误

layers: [wmsLayers, vector],

与TileWMS和Vector源有冲突吗?

最佳答案

ol.Map.layers 需要一个图层数组 - 数组中的第一个对象是一个数组。

试试这个:

var wmsLayer = new ol.layer.Tile({
extent: extent,
source: wmsSource
});

var map = new ol.Map({
layers: [wmsLayer, vector],
target: 'map',
view: view
});

关于javascript - Openlayers源码tileWMS?类型错误 : a. addEventListener 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45305429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com