I have a map which retrieves Points of Interest from a database and displays them however the Lon Lat need to be transformed into XY to be placed properly.Currently the all just appear at O,O and I believe they have been transformed to decimal degrees.
I have tried using ol.proj.transform but this returns undefined. Do I have to create a calculation to convert these or is there a method to do this? The result of this function is returned to a vector layer which loads the features onto a map, albeit in the wrong position.
There are many examples using Openlayers 2 but the syntax is completely different. My non-working example is below:
/* Features conversion */function wsToCollection(routeData) { //console.log(routeData); var fc = new Object; fc.type = "FeatureCollection"; fc.features = []; for (var i = 0; i < routeData.Points.length; i++) { var feature = new Object; feature.type = "Feature"; //console.log(feature); feature.geometry = new Object; feature.geometry.type = "Point"; feature.geometry.coordinates = []; var Lon = routeData.Points.Longitude; //var LonTrans = ol.proj.transform(Lon, 'EPSG:3857', 'EPSG:4326'); // not working console.log(LonTrans); var Lat = routeData.Points.Latitude; //var LatTrans = Lat.transform('EPSG:3857', 'EPSG:4326'); // also not working feature.geometry.coordinates[0] = routeData.Points.Longitude; feature.geometry.coordinates[1] = routeData.Points.Latitude; feature.properties = new Object; feature.properties.name = routeData.Points.Description; feature.properties.Guid = routeData.Points.Guid; feature.properties.LongId = routeData.Points.LongId; fc.features.push(feature); } return fc;}
أكثر...
I have tried using ol.proj.transform but this returns undefined. Do I have to create a calculation to convert these or is there a method to do this? The result of this function is returned to a vector layer which loads the features onto a map, albeit in the wrong position.
There are many examples using Openlayers 2 but the syntax is completely different. My non-working example is below:
/* Features conversion */function wsToCollection(routeData) { //console.log(routeData); var fc = new Object; fc.type = "FeatureCollection"; fc.features = []; for (var i = 0; i < routeData.Points.length; i++) { var feature = new Object; feature.type = "Feature"; //console.log(feature); feature.geometry = new Object; feature.geometry.type = "Point"; feature.geometry.coordinates = []; var Lon = routeData.Points.Longitude; //var LonTrans = ol.proj.transform(Lon, 'EPSG:3857', 'EPSG:4326'); // not working console.log(LonTrans); var Lat = routeData.Points.Latitude; //var LatTrans = Lat.transform('EPSG:3857', 'EPSG:4326'); // also not working feature.geometry.coordinates[0] = routeData.Points.Longitude; feature.geometry.coordinates[1] = routeData.Points.Latitude; feature.properties = new Object; feature.properties.name = routeData.Points.Description; feature.properties.Guid = routeData.Points.Guid; feature.properties.LongId = routeData.Points.LongId; fc.features.push(feature); } return fc;}
أكثر...