I have:
- Django app
- with JavaScript
- using the OpenLayers library
- using Parcel for bundling
- (pipenv and yarn for package management)
- (PyCharm for development)
Everything works basically, but I ran into a problem with OpenLayers and debugging seems to be complicated. I tried to recreate the cluster example form the OpenLayers page. My JavaScript code is basically a copy of the example. The clusters are not loading. Here is the code:
import 'ol/ol.css';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import Feature from 'ol/Feature.js';
import Point from 'ol/geom/Point.js';
import {Cluster, OSM, Vector} from 'ol/source.js';
import {Circle, Fill, Stroke, Style} from 'ol/style.js';
let distance = 50;
let count = 20000;
let features = new Array(count);
let e = 4500000;
for (let i = 0; i < count; ++i) {
let coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
features[i] = new Feature(new Point(coordinates));
}
let source = new Vector({
features: features
});
let clusterSource = new Cluster({
distance: distance,
source: source
});
let styleCache = {};
let clusters = new Vector({
source: clusterSource,
style: function (feature) {
let size = feature.get('features').length;
let style = styleCache[size];
if (!style) {
style = new Style({
image: new Circle({
radius: 10,
stroke: new Stroke({
color: '#fff'
}),
fill: new Fill({
color: '#3399CC'
})
}),
text: new Text({
text: size.toString(),
fill: new Fill({
color: '#fff'
})
})
});
styleCache[size] = style;
}
return style;
}
});
let raster = new TileLayer({
source: new OSM()
});
let map = new Map({
target: 'map_canvas',
layers: [
raster,
clusters
],
view: new View({
center: [0, 0],
zoom: 2
})
});
So the cluster layer does not load, but I get this error.
Here are my Questions
If that is the stacktrace, why isn't there my very own code, calling the function?
I guess my code is hidden in self-hosted:1009
, but I can't open that code. If I click on that I get to view-source:http://self-hosted/
which shows a "page not found". So what is this self-hosted anonymous code and where can I find it?
Also why does it tries to get a file from http://localhost:37575/
? My test-server runs on port 8000. I did not create a second server nor did I started a request on that port. I guess there must be a request somewhere hidden in the OpenLayers library, but I have no idea where I call that.
Also, why can't I just ask for some values in the JavaScript terminal? I get this error, when I enter a variable name:
>> clusters
ReferenceError: clusters is not defined
So I guess that parcel is making debugging more complicated but a bundler is required by OpenLayers so I am hitting a brick wall.