其他分享
首页 > 其他分享> > openlayer加载arcgis服务

openlayer加载arcgis服务

作者:互联网

1、ArcGIS动态服务

import ImageLayer from 'ol/layer/Image';
import CustomImageArcGISRest from "./CustomImageArcGISRest";

function  createDynamicArcGISLayer  (url, zIndex, radio) {
  if (!radio) radio = 1.0;
  return new ImageLayer({
    source: new CustomImageArcGISRest({
      ratio: radio,
      url: url
    }),
    zIndex
  });
}
CustomImageArcGISRest.js内容(改写原来的ImageArcGISRest)
import ImageArcGISRest from 'ol/source/ImageArcGISRest'
import {appendParams} from "ol/uri";
import {assert} from "ol/asserts";


/**
 *
 * 兼容非标准URL形式的MapServer
 *
 *
 */
class CustomImageArcGISRest extends ImageArcGISRest {


  constructor(opt_options) {
    super(opt_options);
  }


  getRequestUrl_(extent, size, pixelRatio, projection, params) {
    // ArcGIS Server only wants the numeric portion of the projection ID.
    const srid = projection.getCode().split(':').pop();

    params['SIZE'] = size[0] + ',' + size[1];
    params['BBOX'] = extent.join(',');
    params['BBOXSR'] = srid;
    params['IMAGESR'] = srid;
    params['DPI'] = Math.round(90 * pixelRatio);

    const url = this.url_;


    let _modifiedUrl = url
      .replace(/MapServer\/?$/, 'MapServer/export')
      .replace(/ImageServer\/?$/, 'ImageServer/exportImage');

    if (_modifiedUrl == url) {
      _modifiedUrl = url.concat('/export');
    }

    const modifiedUrl = _modifiedUrl;

    if (modifiedUrl == url) {
      assert(false, 50); // `options.featureTypes` should be an Array
    }

    return appendParams(modifiedUrl, params);
  }

}


export default CustomImageArcGISRest;
2、ArcGIS切片服务

import XYZ from 'ol/source/XYZ'
import Tile from 'ol/layer/Tile'
import TileGrid from 'ol/tilegrid/TileGrid'

function createTiledArcGISLayer (url, zIndex, _EPSG) { let SRID = _EPSG || '4528'; return new Tile({ source: new XYZ({ url: `${url}/tile/{z}/{y}/{x}`, projection: get(`EPSG:${SRID}`), tileGrid: new TileGrid(window.applicationConfig.tileInfo), }), zIndex }); }

关于window.applicationConfig.tileInfo要看你的服务配置,例如

    tileInfo: {
      tileSize: 256,
      origin: [34876800, 10002100],
      extent: [40453740.474700004, 3442540.7754500005, 40557073.819, 3541460.3122000005],
      resolutions: [
        132.2919312505292,
        76.35146092731352,
        38.17573046365676,
        19.08786523182838,
        9.543932616046483,
        4.771966307890949,
        2.3859831539454746,
        1.1929915769727373,
        0.5964957886186606,
        0.14912394722081113
      ]
    },

 

 




标签:ol,openlayer,url,arcgis,modifiedUrl,params,CustomImageArcGISRest,import,加载
来源: https://www.cnblogs.com/yangzhengier/p/14336568.html