zoukankan      html  css  js  c++  java
  • openlayers加载geojson数据 *


    1. 获取GeoJSON数据,可以通过http请求获取,也可以自己定义json数据。
      注意格式
    var geojsonObject = {
            'type': 'FeatureCollection',
            'crs': {
              'type': 'name',
              'properties': {
                'name': 'EPSG:3857'
              }
            },
            'features': [{
              'type': 'Feature',
              'geometry': {
                'type': 'Point',
                'coordinates': [0, 0]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'LineString',
                'coordinates': [[4e6, -2e6], [8e6, 2e6]]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'LineString',
                'coordinates': [[4e6, 2e6], [8e6, -2e6]]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'Polygon',
                'coordinates': [[[-5e6, -1e6], [-4e6, 1e6], [-3e6, -1e6]]]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'MultiLineString',
                'coordinates': [
                  [[-1e6, -7.5e5], [-1e6, 7.5e5]],
                  [[1e6, -7.5e5], [1e6, 7.5e5]],
                  [[-7.5e5, -1e6], [7.5e5, -1e6]],
                  [[-7.5e5, 1e6], [7.5e5, 1e6]]
                ]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'MultiPolygon',
                'coordinates': [
                  [[[-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6], [-3e6, 6e6]]],
                  [[[-2e6, 6e6], [-2e6, 8e6], [0, 8e6], [0, 6e6]]],
                  [[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6], [3e6, 6e6]]]
                ]
              }
            }, {
              'type': 'Feature',
              'geometry': {
                'type': 'GeometryCollection',
                'geometries': [{
                  'type': 'LineString',
                  'coordinates': [[-5e6, -5e6], [0, -5e6]]
                }, {
                  'type': 'Point',
                  'coordinates': [4e6, -5e6]
                }, {
                  'type': 'Polygon',
                  'coordinates': [[[1e6, -6e6], [2e6, -4e6], [3e6, -6e6]]]
                }]
              }
            }]
          };
    
    1. 创建矢量图层Source
    var vectorSource = new ol.source.Vector({
            features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
          });

    3.创建图层并绑定Source

     var vectorLayer = new ol.layer.Vector({
            source: vectorSource,
            style: ''
          });

    4.添加到map中即可

    GIS开发https://www.giserdqy.comGIS,WebGIS,ArcGIS,OpenLayers,Leaflet,Geoserver,PostGIS,BIM,空间大数据,GeoAI技术分享
  • 相关阅读:
    更新user的方法
    django里的http协议
    django的第一个问题
    一台机器上配置多个ip地址;访问宿主机上的容器
    virtio 之后的数据直连
    virtio是啥子
    perf的采样模式和统计模式
    perf的统计模式: 突破口: x86_perf_event_update
    arp_filter的验证,使用net namespace
    阿里云Windows 2008一键安装包配置php web环境图文安装教程(IIS+Php+Mysql)
  • 原文地址:https://www.cnblogs.com/dqygiser/p/9215839.html
Copyright © 2011-2022 走看看