OpenLayers系列之-Geometry格式转换

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); 
            });
}
});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值