Openlayers 3 如何在Openlayers 3.5中的不同投影中添加功能

Openlayers 3 如何在Openlayers 3.5中的不同投影中添加功能,openlayers-3,Openlayers 3,我正在使用Openlayer 3.5并加载一个OSM映射“EPSG:3857” 但我的webService功能在“EPSG:4326”中 因此,我如何使地图在4326或新的功能是在3857。 我更喜欢第一种选择。查看常见问题部分: 如何更改地图的投影? 您很可能希望将OpenLayers的默认投影更改为更适合您所在区域或特定数据的投影 可以通过“视图”属性设置地图的投影。以下是一些例子: //OpenLayers支持世界大地测量系统1984,EPSG:4326: var map = new ol

我正在使用Openlayer 3.5并加载一个OSM映射“EPSG:3857”

但我的webService功能在“EPSG:4326”中

因此,我如何使地图在4326或新的功能是在3857。
我更喜欢第一种选择。

查看常见问题部分:

如何更改地图的投影? 您很可能希望将OpenLayers的默认投影更改为更适合您所在区域或特定数据的投影

可以通过“视图”属性设置地图的投影。以下是一些例子:

//OpenLayers支持世界大地测量系统1984,EPSG:4326:

var map = new ol.Map({
  view: new ol.View({
    projection: 'EPSG:4326'
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});

// To use other projections, you have to register the projection in OpenLayers:
//
// By default OpenLayers does not know about the EPSG:21781 (Swiss) projection.
// So we create a projection instance for EPSG:21781 and pass it to
// ol.proj.addProjection to make it available to the library for lookup by its
// code.
var swissProjection = new ol.proj.Projection({
  code: 'EPSG:21781',
  // The extent is used to determine zoom level 0. Recommended values for a
  // projection's validity extent can be found at http://epsg.io/.
  extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
  units: 'm'
});
ol.proj.addProjection(swissProjection);

// we can now use the projection:
var map = new ol.Map({
  view: new ol.View({
    projection: swissProjection
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});

我们建议您在epsg.io上查找投影参数(如有效范围)。

查看常见问题部分:

如何更改地图的投影? 您很可能希望将OpenLayers的默认投影更改为更适合您所在区域或特定数据的投影

可以通过“视图”属性设置地图的投影。以下是一些例子:

//OpenLayers支持世界大地测量系统1984,EPSG:4326:

var map = new ol.Map({
  view: new ol.View({
    projection: 'EPSG:4326'
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});

// To use other projections, you have to register the projection in OpenLayers:
//
// By default OpenLayers does not know about the EPSG:21781 (Swiss) projection.
// So we create a projection instance for EPSG:21781 and pass it to
// ol.proj.addProjection to make it available to the library for lookup by its
// code.
var swissProjection = new ol.proj.Projection({
  code: 'EPSG:21781',
  // The extent is used to determine zoom level 0. Recommended values for a
  // projection's validity extent can be found at http://epsg.io/.
  extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
  units: 'm'
});
ol.proj.addProjection(swissProjection);

// we can now use the projection:
var map = new ol.Map({
  view: new ol.View({
    projection: swissProjection
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});

我们建议在epsg.io上查找投影参数(如有效范围)。

要将特征重新投影到
epsg:3857
,可以在解析WKT字符串中的特征时设置选项
dataProjection
featureProjection
。另见


要将要素重新投影到
EPSG:3857
,可以在解析WKT字符串中的要素时设置选项
dataProjection
featureProjection
。另见


不适合我。如果我添加了投影,则底图甚至不适用于EPSG中的appearOSM:4326不适用于我。如果我添加投影,则底图甚至不显示在EPSG:4326中
var map = new ol.Map({
  view: new ol.View({
    projection: 'EPSG:4326'
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});

// To use other projections, you have to register the projection in OpenLayers:
//
// By default OpenLayers does not know about the EPSG:21781 (Swiss) projection.
// So we create a projection instance for EPSG:21781 and pass it to
// ol.proj.addProjection to make it available to the library for lookup by its
// code.
var swissProjection = new ol.proj.Projection({
  code: 'EPSG:21781',
  // The extent is used to determine zoom level 0. Recommended values for a
  // projection's validity extent can be found at http://epsg.io/.
  extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864],
  units: 'm'
});
ol.proj.addProjection(swissProjection);

// we can now use the projection:
var map = new ol.Map({
  view: new ol.View({
    projection: swissProjection
    // other view properties like map center etc.
  })
  // other properties for your map like layers etc.
});
var format = new ol.format.WKT();
var feature;
$.each(data, function (i, link) {
    feature = format.readFeature(link.geom, {
      dataProjection: 'EPSG:4326',
      featureProjection: 'EPSG:3857'
    });
    wktTraffic.addFeature(feature);
})