在OpenParyers v5.3.0中,使用Parcel不能从本地位置连接矢量层。
此带有本地URL的代码不起作用:
import GeoJSON from 'ol/format/GeoJSON';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
var map = new Map({
target: 'map',
layers: [
new VectorLayer({
source: new VectorSource({
format: new GeoJSON(),
url: './data/geojson/countries.geojson'
})
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
此代码有效:
import GeoJSON from 'ol/format/GeoJSON';
import Map from 'ol/Map';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import View from 'ol/View';
var map = new Map({
target: 'map',
layers: [
new VectorLayer({
source: new VectorSource({
format: new GeoJSON(),
url: 'https://openlayers.org/en/v5.3.0/examples/data/geojson/countries.geojson'
})
})
],
view: new View({
center: [0, 0],
zoom: 2
})
});
此代码在没有包裹的情况下有效:
var map = new ol.Map({
layers: [
new ol.layer.Vector({
source: new ol.source.Vector({
url: './data/geojson/countries.geojson',
format: new ol.format.GeoJSON()
})
})
],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 3
})
});
是什么阻止了使用Parcel从本地位置连接“ countries.geojson”?