您的位置:首页 > 运维架构

OpenLayers系列之-Geometry格式转换

2016-07-21 19:31 197 查看
Geometry有多种格式,例如WKT, GML, KML等格式。OpenLayers提供Geometry格式的转换方法,可以实现不同格式的Geometry的转换。Geometry格式转换类位于OpenLayers.Format命名空间下。本文以WKT--> GML的转换来说明OpenLayers Geometry格式转换方法的使用。1. 定义WKT Geometry
<Ship mmsi="209371000" position="POINT(121.7229 31.318561666666668)" shipdomain="POLYGON ((250.72289999999998 31.318561666666668, 201.0260966507277 47.09294825323749, 166.94331969198262 50.04947279928925, 150.88040212866733 50.800981724128654, 141.48677815291356 51.082439819580216, 135.01533832248563 51.21210145997425, 129.99014132220967 51.277447790156515, 125.69925693637005 51.30905792766835, 121.7229 51.31856166666667, 117.74654306362996 51.30905792766835, 113.45565867779032 51.277447790156515, 108.43046167751437 51.21210145997425, 101.95902184708645 51.082439819580216, 92.56539787133266 50.80098172412866, 76.50248030801738 50.04947279928925, 42.41970334927235 47.092948253237495, -7.277100000000004 31.318561666666653, 42.41970334927228 15.544175080095846, 76.50248030801737 12.58765053404409, 92.56539787133266 11.836141609204681, 101.95902184708643 11.554683513753115, 108.43046167751437 11.425021873359086, 113.45565867779032 11.359675543176817, 117.74654306362994 11.32806540566499, 121.7229 11.318561666666668, 125.69925693637005 11.32806540566499, 129.99014132220967 11.359675543176817, 135.0153383224856 11.425021873359086, 141.48677815291353 11.554683513753119, 150.88040212866733 11.836141609204681, 166.94331969198254 12.587650534044087, 201.0260966507276 15.544175080095835, 250.72289999999998 31.318561666666668))" speed="12.3" loa="129.0" width="20.0" type="货轮" updatetime="2015-06-15 18:38:00.0"/>
$.ajax({  url: 'http://localhost:8080/AssistSystem/getShipsDomain.do',type: 'GET',dataType: 'xml',success: function(xml) {$(xml).find("Ship").each(function(i){//这里 shipdomain 为wkt 数据var shipdomain = $(this).attr("shipdomain");var wktFormat = new ol.format.WKT();var feature = wktFormat.readFeature(shipdomain, {        dataProjection: 'EPSG:4326',        featureProjection: 'EPSG:3857'      });source.addFeature(feature);             });}});
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息