Comments (6)
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.
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.
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.
var bd09Extent = [-20037726.37, -12474104.17, 20037726.37, 12474104.17];
Thank you very much, tested to work fine
from openlayers.
@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.
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.
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)
- Offscreen canvas example not working
- ESM implementation does not work HOT 2
- The `removeLastPoint` function in the official example is not functioning correctly. HOT 4
- WebGL Vector Layer flickering since 10.0.0 HOT 2
- Improve examples to use createLoader() for WMS HOT 2
- Non-tiled WMS is rendered inefficiently HOT 13
- V10 seems to introduce a detached tile image memory leak HOT 4
- KeyboardPan not working with nested custom elements HOT 2
- RasterSource using inappropriate resolutions and not using correctly specified resolutions
- DataTileSource 的 getTile 方法拿不到数据(getTile(...).getData()) HOT 2
- image in center Polygon HOT 1
- Using version 2.0.0 of WFS, for a transaction, the WFS format writes filters filtering on FeatureId, whereas WFS 2.0.0 should be using ResourceID HOT 1
- WMS capabilities parser for WMS 1.1.1
- TileLayer with extent does not wrapX HOT 2
- Zoom snapping HOT 3
- `getFeaturesInExtent` not returning features for tile layer when zoom is outside `minZoom` or `maxZoom` HOT 2
- There is a missing keyword in the Basic Concepts tutorial
- After updating to V10, .getFeaturesInExtent returns empty array HOT 3
- Error when zooming in and out multiple times in tile layers HOT 1
- Modify in ref do not work in Vue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openlayers.