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技术分享
  • 相关阅读:
    实验一
    BZOJ 2564
    P4557 [JSOI2018]战争
    移动自动化-Mac-IOS-appium环境搭建
    Node安装mac版本
    删除N天前文件和空文件
    Python之jsonpath模块
    性能学习
    参数化
    查找测试用例
  • 原文地址:https://www.cnblogs.com/dqygiser/p/9215839.html
Copyright © 2011-2022 走看看