how to get points return from OpenLayers.Control.DrawFeature

前端 未结 1 1865
慢半拍i
慢半拍i 2021-01-06 07:07


  


Mapping project


        
相关标签:
1条回答
  • 2021-01-06 07:10

    You can just add an event handler for the 'featureadded' event on each DrawFeature control, and then write out the feature's geometry using OpenLayers.Format.WKT, like this:

    for(var key in drawControls) {
      map.addControl(drawControls[key]);
    
      // register a listener on each control
      drawControls[key].events.register('featureadded', drawControls[key], function(f) {
    
        // create a WKT reader/parser/writer          
        var wkt = new OpenLayers.Format.WKT();
    
         // write out the feature's geometry in WKT format
         var out = wkt.write(f.feature);
         console.log(out);
       });
    }
    

    Example Output:
    POLYGON((17.71874986589 9.6328123658895,20.53124986589 -10.05468763411,37.93359361589 9.2812498658895,17.71874986589 9.6328123658895))

    0 讨论(0)
提交回复
热议问题