Git Product home page Git Product logo

Comments (6)

mike-000 avatar mike-000 commented on September 26, 2024

Using the example in #10374 (comment) you would need to make the projection global for the view to wrap. However the Baidu tiles overflow the projection extent and do not render correctly when the view wraps if the source projection is set as global. To overcome that you must define two projections https://codesandbox.io/s/xyz-forked-hj52y7?file=/index.js

from openlayers.

ajhxk avatar ajhxk commented on September 26, 2024

Using the example in #10374 (comment) you would need to make the projection global for the view to wrap. However the Baidu tiles overflow the projection extent and do not render correctly when the view wraps if the source projection is set as global. To overcome that you must define two projections https://codesandbox.io/s/xyz-forked-hj52y7?file=/index.js

感谢回复, 我需要定义两个坐标系是嘛?
Thanks for the reply, I need to define two coordinate systems, right?

但是下面这个地址 我不能访问成功
But below this address, I can't access it successfully

https://codesandbox.io/s/xyz-forked-hj52y7?file=/index.js

from openlayers.

mike-000 avatar mike-000 commented on September 26, 2024
import "ol/ol.css";
import Map from "ol/Map";
import View from "ol/View";
import Tile from "ol/layer/Tile";
import XYZ from "ol/source/XYZ";
import TileGrid from "ol/tilegrid/TileGrid";
import {
  Projection,
  addProjection,
  addCoordinateTransforms,
  transform
} from "ol/proj";
import projzh from "projzh";

var bd09Extent = [-20037726.37, -12474104.17, 20037726.37, 12474104.17];

var baiduMercator = new Projection({
  code: "baidu",
  extent: bd09Extent,
  units: "m",
});
addProjection(baiduMercator);
addCoordinateTransforms(
  "EPSG:4326",
  baiduMercator,
  projzh.ll2bmerc,
  projzh.bmerc2ll
);
addCoordinateTransforms(
  "EPSG:3857",
  baiduMercator,
  projzh.smerc2bmerc,
  projzh.bmerc2smerc
);

var baiduMercatorG = new Projection({
  code: "baiduG",
  extent: bd09Extent,
  units: "m",
  global: true,
});
addProjection(baiduMercatorG);
addCoordinateTransforms(
  "EPSG:4326",
  baiduMercatorG,
  projzh.ll2bmerc,
  projzh.bmerc2ll
);
addCoordinateTransforms(
  "EPSG:3857",
  baiduMercatorG,
  projzh.smerc2bmerc,
  projzh.bmerc2smerc
);

var bmercResolutions = new Array(19);
for (var i = 0; i < 19; ++i) {
  bmercResolutions[i] = Math.pow(2, 18 - i);
}

var urls = [0, 1, 2, 3].map(function(sub) {
  return (
    "http://maponline" +
    sub +
    ".bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=1&udt=20191119"
  );
});
var baiduSource = new XYZ({
  projection: baiduMercator,
  wrapX: true,
  url:
    "http://maponline{0-3}.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=1&udt=20191119",
  tileGrid: new TileGrid({
    minZoom: 3,
    resolutions: bmercResolutions,
    origin: [0, 0],
    extent: bd09Extent
  })
});
var xyzTileUrlFunction = baiduSource.getTileUrlFunction();
var tmsTileUrlFunction = function([z, x, y]) {
  return xyzTileUrlFunction([z, x, -y - 1]);
};
baiduSource.setTileUrlFunction(tmsTileUrlFunction);
var baidu = new Tile({
  source: baiduSource
});
new Map({
  target: "map",
  layers: [baidu],
  view: new View({
    center: transform([121.51, 31.55], "EPSG:4326", "baidu"),
    zoom: 1,
    projection: baiduMercatorG
  })
});

The same example using StackBlitz https://stackblitz.com/edit/js-23bvsn?file=index.js,package.json,index.html

from openlayers.

ajhxk avatar ajhxk commented on September 26, 2024

var bd09Extent = [-20037726.37, -12474104.17, 20037726.37, 12474104.17];

Thank you very much, tested to work fine

from openlayers.

ajhxk avatar ajhxk commented on September 26, 2024

@mike-000 你好 我按照上述方法 添加了个 额外的 baiduG 的坐标系,并且在初始化 view的时候 使用的是BD09G, 现在遇到一个问题 我们在缩放或者移动地图的时候 会出现 空白区域,且我看了network下瓦片请求没有出现404或者异常的情况。但当我们将view下使用的坐标系改成 BD09 则不会有此问题 。我观察了 BD09与BD09G的差异 就在与 global 配置。 请问出现这种情况 有合适的解决方案嘛 ?
下方是 简要代码:

const createBD09 = () => {
  // 创建百度墨卡托坐标系
  const baiduMercator = new Projection({
    code: BD09,
    units: 'm',
    extent: bd09Extent
  })
  // 添加百度墨卡托坐标系
  addProjection(baiduMercator)
  // 添加百度墨卡托坐标系与WGS84坐标系之间的转换
  addCoordinateTransforms(
    'EPSG:4326',
    baiduMercator,
    projzh.ll2bmerc,
    projzh.bmerc2ll
  )
  // 添加百度墨卡托坐标系与墨卡托坐标系之间的转换
  addCoordinateTransforms(
    'EPSG:3857',
    baiduMercator,
    projzh.smerc2bmerc,
    projzh.bmerc2smerc
  )
}
const createBD09G = () => {
    // 创建百度墨卡托坐标系
    const baiduMercatorG = new Projection({
      code: BD09G,
      units: 'm',
      extent: bd09Extent,
      global: true
    })
    // 添加百度墨卡托坐标系
    addProjection(baiduMercatorG)
    // 添加百度墨卡托坐标系与WGS84坐标系之间的转换
    addCoordinateTransforms(
      'EPSG:4326',
      baiduMercatorG,
      projzh.ll2bmerc,
      projzh.bmerc2ll
    )
    // 添加百度墨卡托坐标系与墨卡托坐标系之间的转换
    addCoordinateTransforms(
      'EPSG:3857',
      baiduMercatorG,
      projzh.smerc2bmerc,
      projzh.bmerc2smerc
    )
}
function getProjectionByOptions(options) {
  let gisEngine = options.gisEngine;
  let size = options.size;
  let projection = 'EPSG:3857';
  switch (gisEngine) {
  case Default.gisEngineKey.BAIDU_ONLINE:
  case Default.gisEngineKey.BAIDU_OFFLINE:
    projection = BD09G;
    // projection = BD09;
    break;
  case Default.gisEngineKey.BITMAP:
    projection = new Projection({
      code: 'xkcd-image',
      unit: 'pixels',
      extent: [0, 0, size.w, size.h]
    });
    break;
  default:
    break;
  }
  return projection;
}
....
  view = new View({
    center,
    minZoom,
    extent: extent ? extent : undefined,
    zoom,
    maxZoom,
    projection: getProjectionByOptions(params),
    constrainResolution: true,
    smoothResolutionConstraint: false
  });

from openlayers.

mike-000 avatar mike-000 commented on September 26, 2024

The source projection should not be global, the view projection must be global. Source projection BD09 and view projection BD09G works well.

Source projection BD09 and view projection EPSG:3857 is not so good.
image
That might be because the two projections have a slightly offset antemeridian. transform([[-180, 0], "EPSG:4326", "BD09") returns [-20037002.787653632, 603.7006072154708] which is slightly offset from the BD09 projection extent

from openlayers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.