I'm trying to load multiple shapefiles as GeoJSON and display them on OpenLayers.
This is the code:
var map = new ol.Map({
layers: [new ol.layer.Tile({
source: new ol.source.OSM()
})],
target: 'map',
controls: ol.control.defaults({
attributionOptions: {
collapsible: false
}
}),
overlays: [overlay],
view: new ol.View({
projection: 'EPSG:4326',
center: center,
zoom: zoom,
rotation: rotation
})
});
loadshp({
url: './10tnvillage.zip',
encoding: 'big5',
EPSG: 3826
},
function (data) {
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(data,{
featureProjection: 'EPSG:4326'
})
}),
style: setStyle
});
map.addLayer(vectorLayer);
});
loadshp({
url: './abadan.zip',
encoding: 'big5',
EPSG: 3826
},
function (data1) {
var vectorLayer1 = new ol.layer.Vector({
source: new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(data1,{
featureProjection: 'EPSG:4326'
})
}),
style: setStyle
});
map.addLayer(vectorLayer1);
});
It's show the Tile layer and the latest shapefile, but not all of them.
I did used a Array List and pass it to Map object, but didn't work.
var layers = [];
layers.push(new ol.layer.Tile({
source: new ol.source.OSM()
}));
...
layers.push(vectorLayer);
...
layers.push(vectorLayer1);
....
var map = new ol.Map({
layers: layers,
...
So, how can I display all my layers in OpenLayers?