中心不工作
https://jsfiddle.net/YuK1Game/katcr16L/8/
let olView = new ol.View({
center: [35.689634, 139.692101],
zoom: 4,
});
Run Code Online (Sandbox Code Playgroud)
中心 35.689634, 139.692101 是日本的东京。但是,它不起作用谢谢
35.689634 个苹果和 39.692101 个香蕉不是东京的正确坐标。每个坐标都有一个特定的投影,没有它,数据就毫无意义。
视图也有一个投影,默认为EPSG:3857。您的坐标在EPSG:4326(WGS84) 中。
投影。默认为 EPSG:3857(球面墨卡托)
第二个错误是你混合了X和Y,应该是 [139.692101, 35.689634]
const center = ol.proj.transform([139.692101, 35.689634], 'EPSG:4326', 'EPSG:3857');
console.log('center is:', center);
let olView = new ol.View({
center: center,
zoom: 4
// default projection: 'EPSG:3857'
});
let olLayers = [
new ol.layer.Tile({
source: new ol.source.OSM(),
})
];
new ol.Map({
layers: olLayers,
view: olView,
target: 'app',
});Run Code Online (Sandbox Code Playgroud)
<link href="https://openlayers.org/en/v4.6.4/css/ol.css" rel="stylesheet"/>
<script src="https://openlayers.org/en/v4.6.4/build/ol-debug.js"></script>
<div id="app"></div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2171 次 |
| 最近记录: |