geospatial - OpenLayers 3 get WKT Polygon string -
i have openlayers 3 map can draw polygon.
i have returned wkt string rapresent drawed polygon.
how can it?
jsfiddle code http://jsfiddle.net/michelejs/3zawt33b/7/
here map:
map = new ol.map({ target: 'map', layers: [raster,vector], view: new ol.view({ center: ol.proj.fromlonlat([11.249367, 43.774298]), zoom: 15 }) });
here intaractions me draw polygon:
function addinteraction() { var ct = 0; draw = new ol.interaction.draw({ source: source, type: 'polygon', geometryfunction: function (c, g) { if (goog.isdef(g)) { g.setcoordinates(c); } else { g = new ol.geom.polygon(c); } if (c[0].length > ct) { console.log('click coord : ' + c[0][c[0].length - 1]); var coord = c[0][c[0].length - 1]; $('div#coordinate').html( $('div#coordinate').html() + "<p>" + ( number(coord[0]).tofixed(2) ) + " - " + ( number(coord[1]).tofixed(2) ) + "</p>" ); coordinates.push(coord); ct = c[0].length; } else { console.log('move coord : ' + c[0][c[0].length - 1]); } return g; } }); draw.on('drawend', function(e) { isin = e; checkifin(); lastfeature = e.feature; //write wkt polygon code in div#getaswk }) draw.on('drawstart', function (e) { source.clear(); }); map.addinteraction(draw); } map.addinteraction(draw);
ol3 contains ol.format.wkt class purpose. use writegeometry() method this:
var format = new ol.format.wkt(), wkt = format.writegeometry(yourfeature.getgeometry());
see api-docs: http://openlayers.org/en/v3.0.0/apidoc/ol.format.wkt.html#writegeometry
Comments
Post a Comment