Updated
This commit is contained in:
52
master/examples/vector-layer.js
Normal file
52
master/examples/vector-layer.js
Normal file
@@ -0,0 +1,52 @@
|
||||
var map;
|
||||
|
||||
var raster = new ol.layer.TileLayer({
|
||||
source: new ol.source.MapQuestOpenAerial()
|
||||
});
|
||||
|
||||
var vector = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
projection: ol.projection.get('EPSG:4326')
|
||||
}),
|
||||
style: new ol.style.Style({rules: [
|
||||
new ol.style.Rule({
|
||||
symbolizers: [
|
||||
new ol.style.Polygon({
|
||||
strokeStyle: '#696969',
|
||||
strokeWidth: 1,
|
||||
opacity: 1.5
|
||||
})
|
||||
]
|
||||
})
|
||||
]})
|
||||
});
|
||||
|
||||
var geojson = new ol.parser.GeoJSON();
|
||||
var url = '../test/spec/ol/parser/geojson/countries.json';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
|
||||
/**
|
||||
* onload handler for the XHR request.
|
||||
*/
|
||||
xhr.onload = function() {
|
||||
if (xhr.status == 200) {
|
||||
// this is silly to have to tell the layer the destination projection
|
||||
var projection = map.getView().getProjection();
|
||||
vector.parseFeatures(xhr.responseText, geojson, projection);
|
||||
} else {
|
||||
throw new Error('Data loading failed: ' + xhr.status);
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
|
||||
map = new ol.Map({
|
||||
layers: new ol.Collection([raster, vector]),
|
||||
renderer: ol.RendererHint.CANVAS,
|
||||
target: 'map',
|
||||
view: new ol.View2D({
|
||||
center: new ol.Coordinate(0, 0),
|
||||
zoom: 1
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user