I've written some code to create a vector layer based on a GeoJSON file located on my computer. I've deployed the tomcat server and put my GeoJSON file in some path like:
webapps/OpenLayersAsset/countries.geojson
Next using the following code to show the file but I get the error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/OpenLayersAssets/countries.geojson". Does it cause the byGeoJSON location or something else?
var countrySource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: 'http://localhost:8080/OpenLayersAssets/countries.geojson',
projection: 'EPSG:3857'
});
var countryLayer = new ol.layer.Vector({
source: countrySource
});
var center = ol.proj.transform([51.34, 35.65], 'EPSG:4326', 'EPSG:3857');
var view = new ol.View({
center: center,
zoom: 8
});
var map = new ol.Map({
target: 'map',
layers: [countryLayer],
view: view
});