【发布时间】:2019-10-11 04:52:05
【问题描述】:
我有:
- Django 应用程序
- 使用 JavaScript
- 使用 OpenLayers 库
- 使用 Parcel 进行捆绑
- (用于包管理的 pipenv 和 yarn)
- (用于开发的 PyCharm)
基本上一切正常,但我遇到了 OpenLayers 的问题,调试似乎很复杂。我试图重新创建cluster example form the OpenLayers page。我的 JavaScript 代码基本上是示例的副本。集群未加载。代码如下:
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
})
});
所以集群层没有加载,但是我得到了这个错误。
这是我的问题
如果那是堆栈跟踪,为什么没有我自己的代码来调用函数?
我猜我的代码隐藏在self-hosted:1009 中,但我无法打开该代码。如果我点击它,我会到达view-source:http://self-hosted/,它会显示“找不到页面”。那么这个自托管匿名代码是什么,在哪里可以找到呢?
还有为什么它会尝试从http://localhost:37575/ 获取文件?我的测试服务器在端口 8000 上运行。我没有创建第二台服务器,也没有在该端口上启动请求。我想一定有一个隐藏在 OpenLayers 库中的请求,但我不知道我在哪里调用它。
另外,为什么我不能在 JavaScript 终端中请求一些值?当我输入变量名时出现此错误:
>> clusters
ReferenceError: clusters is not defined
所以我猜想 parcel 让调试变得更加复杂,但 OpenLayers 需要一个捆绑器,所以我碰壁了。
【问题讨论】:
标签: javascript openlayers parceljs