How can I use a SVG image as a Layer (so not as a map marker) with OpenLayers-3
I was unable to get any output of my SVG image when using any of the ol.source.Vector
and ol.format.Feature
instances.
Small example:
var mapLayer = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'image.svg',
format: new ol.format.Feature() // http://openlayers.org/en/v3.12.1/apidoc/ol.format.Feature.html
}),
});
I was able to get output when using the ImageStatic layer, but this uses/generates(?) a static image so the advantages of SVG are gone.
Example:
// Not sure if I need this for SVG, but is is required for an image
var extent = [0, 0, 1000, 1000]; // random image size
var projection = new ol.proj.Projection({
code: 'test',
units: 'pixels',
extent: extent
});
var mapLayer = new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'image.svg',
projection: projection,
imageExtent: extent
})
});
I already tried the trick with setting the Content-type:
to image/svg+xml
but this did not help me at all.
So, again:
How can I (if possible) use a SVG image a a layer with OpenLayers-3?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…