Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Render countries from GeoJSON

This reveals a number of issues that still need to be addressed.
  • Loading branch information...
commit f96193082389df3184b7d56df0409b6e9f9b3b64 1 parent 84527c4
@tschaub tschaub authored
Showing with 21 additions and 11 deletions.
  1. +20 −10 examples/vector-layer.js
  2. +1 −1  src/ol/layer/vectorlayer.exports
View
30 examples/vector-layer.js
@@ -8,6 +8,7 @@ goog.require('ol.geom.LineString');
goog.require('ol.geom.Point');
goog.require('ol.layer.TileLayer');
goog.require('ol.layer.Vector');
+goog.require('ol.parser.GeoJSON');
goog.require('ol.projection');
goog.require('ol.source.MapQuestOpenAerial');
goog.require('ol.source.Vector');
@@ -19,21 +20,30 @@ var raster = new ol.layer.TileLayer({
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
- projection: ol.projection.getFromCode('EPSG:3857')
+ projection: ol.projection.getFromCode('EPSG:4326')
})
});
-vector.addFeatures([
- new ol.Feature({
- g: new ol.geom.LineString([[-10000000, -10000000], [10000000, 10000000]])
- }),
- new ol.Feature({
- g: new ol.geom.LineString([[-10000000, 10000000], [10000000, -10000000]])
- }),
- new ol.Feature({g: new ol.geom.Point([-10000000, 5000000])})
-]);
+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();
+
var map = new ol.Map({
layers: new ol.Collection([raster, vector]),
renderer: ol.RendererHint.CANVAS,
View
2  src/ol/layer/vectorlayer.exports
@@ -1,3 +1,3 @@
@exportClass ol.layer.Vector ol.layer.LayerOptions
-@exportProperty ol.layer.Vector.prototype.addFeatures
+@exportProperty ol.layer.Vector.prototype.parseFeatures

0 comments on commit f961930

Please sign in to comment.
Something went wrong with that request. Please try again.