i have gone through few different examples on , nothing ever seems work. trying draw point on map using geojson source. here have:
var staticgeo = new ol.source.geojson(({ object: { type: 'feature collection', crs: { type: 'name', properties: {name: 'epsg:4326'} }, features: [{ type: 'feature', geometry: { type: 'point', coordinates: [0,0] } }] }, projection: 'epsg:3857' })); var vectorsource = new ol.source.vector({ source: staticgeo }); var vectorlayer = new ol.layer.vector({ source: vectorsource, style: new ol.style.style({ fill: new ol.style.fill({ color: 'rgba(255,255,255,0.2)' }), stroke: new ol.style.stroke({ color: 'blue', width: 1 }) }) }) this.map.addlayer(vectorlayer);
this.map refers ol.map object working. overall seems lot of code should seemingly trivial (maybe doing wrong?).
from ol 3.5.0 add geojson
this:
var geojsonobject = { 'type': 'featurecollection', 'crs': { 'type': 'name', 'properties': { 'name': 'epsg:4326' } }, 'features': [ { 'type': 'feature', 'geometry': { 'type': 'point', 'coordinates': [21.54967, 38.70250] } } ] }; var features = new ol.format.geojson().readfeatures(geojsonobject, { featureprojection: 'epsg:3857' }); var vectorsource = new ol.source.vector({ features: features });
note projection coordinates.
Comments
Post a Comment