2021-10-09 openlayers 使用CGCS2000坐标系

1. 开发过程使用的地图服务是超图iserver发布的底图服务,前端使用VUE开发调用地图服务

安装使用到的包

npm install @supermap/iclient-ol
npm install proj4

2. 导入,注册

import { register } from 'ol/proj/proj4';

import proj4 from 'proj4';

import { fromLonLat, addProjection, Projection } from 'ol/proj';

import { getWidth, getCenter } from 'ol/extent';

import TileGrid from 'ol/tilegrid/TileGrid';

3. 开发

proj4.defs("EPSG:4490", "+proj=longlat +ellps=GRS80 +no_defs");

register(proj4);

const EPSG = 'EPSG:4490';

      const projection = new Projection({

        code: EPSG,//EPSG code

        extent: [-180, -90, 180, 90],

        worldExtent: [-180, -90, 180, 90],

        units: "degrees"//Projection units: `'degrees'`, `'ft'`, `'m'`, `'pixels'`, `'tile-pixels'` or `'us-ft'.

      });

      addProjection(projection);

      var projectionExtent = projection.getExtent();

      var size = getWidth(projectionExtent) / 256;

      var resolutions = new Array(18);

      for (var z = 1; z < 19; ++z) {

        resolutions[z] = size / Math.pow(2, z);

      }

      // console.log(resolutions);

      this.map = new Map({

        target: 'map',

        controls: defaults({ attribution: false, zoom: true, rotate: false, collapsed: false }),

        view: new View({

          zoom: 8,

          minZoom: 6,

          maxZoom: 18,

          multiWorld: true,

          projection: projection,

          // extent: [113, 36.1, 119, 42.5],//设置河北省的显示范围

          extent: [-180, -85.05, 180, 85.05],

          center: fromLonLat(centerid, projection) // 显示的中心位置

        })

      });

      const layers = new TileLayer({

        source: new TileSuperMapRest({

          url: url, // supermap iserver 上发布的地图服务,此为使用restful调用

          wrapX: true,

          tileGrid: new TileGrid({

            // extent: [113, 36.1, 119, 42.5],//设置显示范围

            extent: [-180, -85.05, 180, 85.05],

            resolutions: resolutions,

            tileSize: [256, 256]

          })

        }),

        projection: projection,

        opacity: 0.8

      });

      this.map.addLayer(layers);

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值