码迷,mamicode.com
首页 > Web开发 > 详细

ol3 Demo3 ----加载gpx,geojson格式的数据

时间:2018-02-19 15:18:49      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:return   mat   style   ret   tle   body   nbsp   width   cli   

下面是pgx格式的数据效果展示

技术分享图片

核心代码:

      var gpx = new ol.layer.Vector({
        title:‘GPX‘,
        source: new ol.source.Vector({
          url: ‘cycling-vietnam-without-baggage.gpx‘, 
          format: new ol.format.GPX()
        }),
        style: function(feature) {
          return style[feature.getGeometry().getType()];
        }
      });

说明:cycling-vietnam-without-baggage.gpx 是一个本地文件,其中Crome不支持上述加载,可以使用火狐加载查看。


 

下面是geojson格式的效果图:

技术分享图片

核心代码:

 var vectorLayer = new ol.layer.Vector({
        source: new ol.source.Vector({
          url: ‘test.geojson‘,
          format: new ol.format.GeoJSON()
        }),
        style: function(feature) {
          style.getText().setText(feature.get(‘name‘));
          return style;
        }
      });

 说明:同样crome浏览器不支持,使用火狐浏览器可以查看。

 

ol3 Demo3 ----加载gpx,geojson格式的数据

标签:return   mat   style   ret   tle   body   nbsp   width   cli   

原文地址:https://www.cnblogs.com/id-666/p/8453784.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!