javascript - Openlayers source tileWMS? TypeError: a.addEventListener is not a function -
i want add features tile map, problem ocurred when try use
ol.source.tilewms
the error message is:
typeerror: a.addeventlistener not function
however works with
ol.source.osm
my code:
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 can remove 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();
just change line change layer, when use osm, ok... when use tilewms error appear
layers: [wmslayers, vector],
is there conflict tilewms , vector source?
ol.map.layers expects array of layers - first object in array array.
try this:
var wmslayer = new ol.layer.tile({ extent: extent, source: wmssource }); var map = new ol.map({ layers: [wmslayer, vector], target: 'map', view: view });
Comments
Post a Comment