testing in https://jsfiddle.net/geocodezip/yvekp0ud/1/ I found weird trouble.
I was testing the same nodejs code with both URLs:
https://openlayers.org/en/latest/examples/data/kml/2012-02-10.kml **works with nodejs**
https://geo.anantara.cl/maps/kml/doc.kml **dosen't works with nodejs**
So, I found is necessary configure an apache web server, including the following AddType
Apache Web Server Configuration
So, same nodejs code, the results were:
1) Doesn't works if both kml files are on my web server apache (2012-02-10.kml and doc.kml)
2) If only test with the file 2012-02-10.kml but in the server openlayers.org
For other hand, if i use the following url **http://kmlviewer.nsspot.net/**for to test both files on my web server, with google maps, works all.
I guess there is some bug in openlayers or in my code or perhaps the kml file generated with google earth don't like to openlayers.
My code is:
import 'ol/ol.css';
import { Map, View } from 'ol';
import TileLayer from 'ol/layer/Tile';
import VectorLayer from 'ol/layer/Vector';
import OSM from 'ol/source/OSM';
import KML from 'ol/format/KML';
import VectorSource from 'ol/source/Vector';
var openstreet = new TileLayer({
source: new OSM()
});
var geomapa = new VectorLayer({
source: new VectorSource({
//url: 'https://geo.anantara.cl/maps/kml/doc.kml',
//url: 'https://geo.anantara.cl/maps/kml/2012-02-10.kml',
url: 'https://openlayers.org/en/latest/examples/data/kml/2012-02-10.kml',
format: new KML()
})
});
const map = new Map({
target: 'map',
layers: [openstreet, geomapa],
view: new View({
center: [0, 0],
zoom: 0
})
});
My HTML code is
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Using Parcel with OpenLayers</title>
<style>
#map {
width: 400px;
height: 250px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="./index.js"></script>
</body>
</html>