Im new at OpenLayers and Im trying to understand why my html seems to ignore any javascript function I create. When I create a function in the javascript doc it does works with the map, but when I create a button for that function in HTML it doesnt work. Im in production mode so the openlayers api is running with node.js. Here is my html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mapa prueba01</title>
<style>
#map {
width: 1000px;
height: 800px;
}
</style>
</head>
<body>
<div id="map"></div>
<p id="demo">párrafo</p>
<script src="./index.js"></script>
<input type="button" id="boton" value="boton capa" onclick="funcionCapa()"/>
</body>
</html>
And here is my javascript:
import 'ol/ol.css';
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import {ScaleLine, defaults as defaultControls} from 'ol/control';
import TileSource from 'ol/source/Tile';
import TileWMS from 'ol/source/TileWMS';
var capa1 = new TileLayer({
source: new TileWMS({
url: 'http://localhost:8080/geoserver/wms',
params: { 'LAYERS': 'earth:d39B19R', 'TILED': true },
serverType: 'geoserver',
})
});
var capa2 = new TileLayer({
source: new TileWMS({
url: 'http://localhost:8080/geoserver/wms',
params: { 'LAYERS': 'earth:wrf49BR', 'TILED': true },
serverType: 'geoserver',
})
});
var map = new Map({
target: 'map',
controls: defaultControls().extend( [
new ScaleLine()
]),
layers: [
new TileLayer({
source: new OSM()
}),
capa1,
capa2
],
view: new View({
center: [-413106.304,4923069.399],
zoom: 5
})
});
function funcionCapa(){
capa1.setVisible(false);
};
Thank you everybody