openlayers View是否支持北美albers等面积圆锥曲线工程(102008)?
Does openlayers View support north american albers equal area conic project (102008)?
我尝试在视图中使用投影时得到以下堆栈跟踪(在没有投影的 hello world 项目中):openlayers 视图中的“EPSG:102008”:
View.js:1474 Uncaught TypeError: Cannot read property 'getExtent' of null
at createResolutionConstraint (View.js:1474)
at View.applyOptions_ (View.js:326)
at new View (View.js:312)
at Object.parcelRequire.index.js.ol/ol.css (index.js:43)
view: new View({
center: [-10997148, 4569099],
zoom: 5,
projection: "EPSG:102008"
})
在没有投影的情况下,地图显示了一个空的浏览器窗格和上面的异常。
更新:
前两个答案帮助我让它正常工作。我无法使用转换(一直给我一个关于使用有限数字的例外),但只是使用 proj4() 来投影原始点。我如何指定 albers 格式的中心点?
proj4.defs('ESRI:102008', '+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs');
register(proj4);
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
}),
new TileLayer({
source: new TileArcGISRest({
url: esriUrl
})
})
],
view: new View({
center: proj4('EPSG:3857', 'ESRI:102008', [-10997148, 4569099]),
// center: [-10997148, 4569099],
zoom: 5,
projection: 'ESRI:102008'
})
});
更新更新:
还发现我可以这样做:
center: proj4('EPSG:4326', 'ESRI:102008', [-79.995888, 40.440624]),
EPSG:102008 不是 openlayers 的一部分。您将必须添加它,即使用 proj4。请参阅:[https://openlayers.org/en/latest/examples/sphere-mollweide.html?q=proj41
代码是 "ESRI:102008"(不是 EPSG)。有关 proj4 的定义,请参阅 https://epsg.io/102008。您的中心坐标似乎是 web 墨卡托,需要进行转换。
proj4.defs("ESRI:102008","+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs");
ol.proj.proj4.register(proj4);
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: ol.proj.transform([-10997148, 4569099], "EPSG:3857", "ESRI:102008"),
zoom: 5,
projection: "ESRI:102008"
})
});
html, body, .map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
<div id="map" class="map"></div>
我尝试在视图中使用投影时得到以下堆栈跟踪(在没有投影的 hello world 项目中):openlayers 视图中的“EPSG:102008”:
View.js:1474 Uncaught TypeError: Cannot read property 'getExtent' of null
at createResolutionConstraint (View.js:1474)
at View.applyOptions_ (View.js:326)
at new View (View.js:312)
at Object.parcelRequire.index.js.ol/ol.css (index.js:43)
view: new View({
center: [-10997148, 4569099],
zoom: 5,
projection: "EPSG:102008"
})
在没有投影的情况下,地图显示了一个空的浏览器窗格和上面的异常。
更新:
前两个答案帮助我让它正常工作。我无法使用转换(一直给我一个关于使用有限数字的例外),但只是使用 proj4() 来投影原始点。我如何指定 albers 格式的中心点?
proj4.defs('ESRI:102008', '+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs');
register(proj4);
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new OSM()
}),
new TileLayer({
source: new TileArcGISRest({
url: esriUrl
})
})
],
view: new View({
center: proj4('EPSG:3857', 'ESRI:102008', [-10997148, 4569099]),
// center: [-10997148, 4569099],
zoom: 5,
projection: 'ESRI:102008'
})
});
更新更新:
还发现我可以这样做:
center: proj4('EPSG:4326', 'ESRI:102008', [-79.995888, 40.440624]),
EPSG:102008 不是 openlayers 的一部分。您将必须添加它,即使用 proj4。请参阅:[https://openlayers.org/en/latest/examples/sphere-mollweide.html?q=proj41
代码是 "ESRI:102008"(不是 EPSG)。有关 proj4 的定义,请参阅 https://epsg.io/102008。您的中心坐标似乎是 web 墨卡托,需要进行转换。
proj4.defs("ESRI:102008","+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs");
ol.proj.proj4.register(proj4);
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
center: ol.proj.transform([-10997148, 4569099], "EPSG:3857", "ESRI:102008"),
zoom: 5,
projection: "ESRI:102008"
})
});
html, body, .map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
<link href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" rel="stylesheet" />
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
<div id="map" class="map"></div>