GeoJSON tiles regression in v3.5.0 - geojson

My vector tiles were rendered correctly up to version 3.4, but nothing is displayed in 3.5. There are no errors in the JS console. I haven't found any related changes in the most recent API. Is it a bug?
var tileVectorSource = new ol.source.TileVector({
format: new ol.format.GeoJSON(),
tileGrid: new ol.tilegrid.XYZ({
maxZoom: 19
}),
url: 'data/{z}/{x}/{-y}.json'
});
var vectorLayer = new ol.layer.Vector({
source: tileVectorSource,
style: new ol.style.Style({
fill: new ol.style.Fill({
color: '#9db9e8'
})
})
});
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
view: new ol.View({
center: [1877798, 6568203],
zoom: 6
})
});

You have run into a bug see also: https://github.com/openlayers/ol3/issues/3750
The fix (https://github.com/openlayers/ol3/pull/3747) will hopefully be in the upcoming 3.6 release

Related

GML3 features Openlayers not plotting

Latest Version of Openlayers 3.
var metSource = new ol.source.Vector({
url: "metobjectxml/2.xml",
format: new ol.format.GML3({
defaultDataProjection: 'EPSG:4326'
})
});
var metLayer = new ol.layer.Vector({
source: metSource
});
var mapView = new ol.View({
center: ol.proj.transform([-114.3035, 54.5800], 'EPSG:4326', 'EPSG:900913'),
zoom: 5,
projection: 'EPSG:900913'
});
var map = new ol.Map({
layers: [metLayer],
target: 'map',
view: mapView
});
```
Not plotting anything.
XML file: https://bpaste.net/show/56363886838f
Anyone know why?
This is not supported by OpenLayers. Only GML simple features profile is supported. What you have seems sensor web related.

How to use features from Geojson in openlayers3?

I am using openlayers3 and i want to bring my features from feature.json, it seems when my map is loded I can get the feature file from network as xhr request but i am not able to see my polygons on map. Here below is my code
function showMap() {
var vector = new ol.layer.Vector({
projection: 'EPSG:5650',
source: new ol.source.Vector({
format: new ol.format.GeoJSON(),
projection: 'EPSG:5650',
url: 'feature.json'
})
});
var map = new ol.Map({
target: 'tilemap',
controls: ol.control.defaults({
attributionOptions: /** #type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
layers: [
new ol.layer.Image({
source: new ol.source.ImageWMS({
url: 'http://www.geodaten-mv.de/dienste/adv_dop',
crossOrigin: null,
projection: 'EPSG:5650',
params: {
VERSION: '1.3.0',
LAYERS: 'mv_dop',
FORMAT: 'image/jpeg',
CRS: 'EPSG:5650'
}
})
}),vector
],
view: new ol.View({
projection: 'EPSG:5650',
center: [33355494, 5983295],
zoom: 10
})
});
DisplayTilesServices.setMap(map);
}
I was using olderversion of openlayers and now instead of Using url in source, now I am using features and it works!! see the code below
$http.get('feature.geojson').then(function(res){
var format = new ol.format.GeoJSON();
source=new ol.source.Vector({
projection: 'EPSG:5650',
features:format.readFeatures(res.data)
});
var vectorLayer = new ol.layer.Vector({
source: source
});
map.addLayer(vectorLayer);
},function(){})

vector tile layer does not display when switching from VectorTile (3.10) to TileVector (3.11)

I have this simple layer working with openlayers 3.10
var roads = new ol.layer.Vector({
source: new ol.source.TileVector({
format: new ol.format.TopoJSON(),
tileGrid: ol.tilegrid.createXYZ({maxZoom: 13}),
tilePixelRatio: 16,
url: 'http://MY_SERVER/{z}/{x}/{y}.topojson'
}),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
width: 8,
color: [0xff,0xff,0,0.3]
})
})
});
And then it is laid out on top of an OSM/mapnik layer:
var map = new ol.Map({
layers: [
mapnik,
roads
],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([25, 46]),
zoom: 7,
minZoom:7,
maxZoom:17
})
});
However the 3.11 version
new ol.layer.VectorTile({
source: new ol.source.VectorTile({
// ...
})
});
fails. The tile server is invoked, putting in a styling function reveals that the features are loaded properly, but no feature is displayed! There is no error on the console. What am I doing wrong?
With v3.11.0 release ol.source.TileVector was removed. You may use ol.source.VectorTile from now on. Also change your code from ol.layer.Vector to ol.layer.VectorTile. See changelog and an example.

WFS layer not displayed in OL3 when loading as GeoJSON from geoserver

I am trying to load my layer from Geoserver as WFS layer in my OL3 application.
Here is my code to create WFS layer:
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent, resolution, projection) {
return 'http://localhost:8080/geoserver/wfs?service=WFS&' +
'version=1.0.0&request=GetFeature&typename=main:Building_WGS&' +
'outputFormat=application/json&srsname=EPSG:4326&';
},
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({
}))
});
var vector1 = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
To make my code complete here is the code where I have created map object:
var centerpos = [84.2, 28.2];
var newpos = ol.proj.transform(centerpos,'EPSG:4326','EPSG:900913');
var maxExtent = [80.05844110726194,26.34796712822462,88.2015218371264,30.44742963310623];
var map = new ol.Map({
layers: [baseLayerOSM, vector1],
target: 'map',
//controls: [new CustomControl()],
view: new ol.View({
extent:ol.proj.transformExtent(maxExtent, 'EPSG:4326', 'EPSG:900913'),
projection : 'EPSG:900913', // OSM projection
center : newpos,
minZoom:7,
zoom: 7
})
});
I can see the OSM layer in my map. But I can't see the layer Building_WGS. I have a workspace main in geoserver.
When I copy the URL
'http://localhost:8080/geoserver/wfs?service=WFS&' +
'version=1.0.0&request=GetFeature&typename=main:Building_WGS&' +
'outputFormat=application/json&srsname=EPSG:4326&';
I can see the JSON contents.
Can anyone suggest what am I doing wrong in my code?
I even tried to add crossOrigin:"Anonymous" but that doesn't help either.
HELP please
AJ

How to set zoom and center automatically based on GeoJSON features

I load some features from .json file, and would like to automatically set view wuth zoom to see all loaded features. I user OpenLayers version 3.
Here's what I have:
var gjsonFile = new ol.layer.Vector({
source: new ol.source.GeoJSON({
url: 'map.json',
projection: 'EPSG:3857'
})
})
});
var map = new ol.Map({
view: new ol.View({
center: ol.proj.transform([-77.0087,38.8691], 'EPSG:4326', 'EPSG:3857'),
zoom: 12
}),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
gjsonFile
],
target: 'map1'
});
Vector sources have a #getExtent() method that gives you the extent of all features currently loaded in the source. To set the map's view to that extent as soon as the file is loaded, add the following code:
var source = gjsonFile.getSource();
var onChangeKey = source.on('change', function() {
if (source.getState() == 'ready') {
source.unByKey(onChangeKey);
map.getView().fitExtent(source.getExtent(), map.getSize());
}
});

Resources