How, in JavaScript and OpenLayers, can I pass my WKT point string to a method and get back an object that will parse the longitude and latitude into properties for me?
'POINT (XXX YYY)'
to
SomeObject.longitude
and
SomeOjbect.latitude
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityHow, in JavaScript and OpenLayers, can I pass my WKT point string to a method and get back an object that will parse the longitude and latitude into properties for me?
'POINT (XXX YYY)'
to
SomeObject.longitude
and
SomeOjbect.latitude
Try grabbing the coordinates with a regex:
wktString = 'POINT(10.689 -25.092)';
coordFinder = /\(\s?(\S+)\s+(\S+)\s?\)/g;
allMatches = coordFinder.exec(wktString);
lon = parseFloat(allMatches[1]);
lat = parseFloat(allMatches[2]);
ol.format.WKT#readFeature
– Jose Hermosilla Rodrigo Jul 5 '17 at 14:49feature.getGeometry().getCoordinates()
– Jose Hermosilla Rodrigo Jul 5 '17 at 16:00'POINT(10.689 -25.092)'
vs[1189894.0370893013, -2887048.988883849]
? – Rod Jul 5 '17 at 17:214326
to web mercator projection. You can either transform your coordinates (just for use/print) usingol.proj.transform
or useEPSG:4326
as your map projection and let the wkt parser dont transform anything (get ride offeatureProjection
property). – Jose Hermosilla Rodrigo Jul 5 '17 at 17:48