I'm working with openlayers3 and I wanted to load a GeoJSON file from my local ../assets/data/countries.geojson
. Nothing is wrong but it didn't appear on the screen.
This is my code:
<!doctype html>
<html>
<head>
<title>Vector Examples</title>
<link rel="stylesheet" href="http://openlayers.org/en/v3.13.0/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.13.0/build/ol.js"></script>
</head>
<body>
<div id="map" class="map"></div>
<script src="../assets/ol3/js/ol.js"></script>
<script>
var originalSource=new ol.layer.Vector({
source: new ol.source.Vector({
projection : 'EPSG:3857',
url: '../assets/data/countries.geojson',
format: new ol.format.GeoJSON({
defaultDataProjection :'EPSG:4326',
projection: 'EPSG:3857'
})
})
});
var center = ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857');
var view = new ol.View({
center: center,
zoom: 2
});
var map = new ol.Map({
target: 'map',
layers: [originalSource],
view: view
});
</script>
</body>
</html>
<script src="http://openlayers.org/en/v3.13.0/build/ol.js"></script>
and<script src="../assets/ol3/js/ol.js"></script>