Create ol.proj.Projection instances with additional properties
This commit is contained in:
@@ -2,7 +2,7 @@ goog.require('ol.Graticule');
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
goog.require('ol.layer.Vector');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.Projection');
|
||||
goog.require('ol.source.GeoJSON');
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@ proj4.defs('ESRI:53009', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +a=6371000 ' +
|
||||
|
||||
// Configure the Sphere Mollweide projection object with an extent,
|
||||
// and a world extent. These are required for the Graticule.
|
||||
var sphereMollweideProjection = ol.proj.get('ESRI:53009');
|
||||
sphereMollweideProjection.setExtent([
|
||||
-9009954.605703328, -9009954.605703328,
|
||||
9009954.605703328, 9009954.605703328]);
|
||||
sphereMollweideProjection.setWorldExtent([-179, -90, 179, 90]);
|
||||
var sphereMollweideProjection = new ol.proj.Projection({
|
||||
code: 'ESRI:53009',
|
||||
extent: [-9009954.605703328, -9009954.605703328,
|
||||
9009954.605703328, 9009954.605703328],
|
||||
worldExtent: [-179, -90, 179, 90]
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
keyboardEventTarget: document,
|
||||
|
||||
@@ -5,21 +5,29 @@ goog.require('ol.control');
|
||||
goog.require('ol.control.ScaleLine');
|
||||
goog.require('ol.layer.Image');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.Projection');
|
||||
goog.require('ol.source.ImageWMS');
|
||||
|
||||
|
||||
// Transparent Proj4js support: ol.proj.get() creates and returns a projection
|
||||
// known to Proj4js if it is unknown to OpenLayers, and registers functions to
|
||||
// transform between all registered projections.
|
||||
// Transparent Proj4js support:
|
||||
//
|
||||
// EPSG:21781 is known to Proj4js because its definition was loaded in the html.
|
||||
// Note that we are getting the projection object here to set the extent. If
|
||||
// you do not need this, you do not have to use ol.proj.get(); simply use the
|
||||
// string code in the view projection below and the transforms will be
|
||||
// registered transparently.
|
||||
var projection = ol.proj.get('EPSG:21781');
|
||||
// The extent is used to determine zoom level 0. Recommended values for a
|
||||
// Now when we create an ol.proj.Projection instance with the 'EPSG:21781' code,
|
||||
// OpenLayers will pick up parameters like units and transform functions from
|
||||
// Proj4js.
|
||||
//
|
||||
// Note that we are setting the projection's extent here, which is used to
|
||||
// determine the view resolution for zoom level 0. Recommended values for a
|
||||
// projection's validity extent can be found at http://epsg.io/.
|
||||
projection.setExtent([485869.5728, 76443.1884, 837076.5648, 299941.7864]);
|
||||
//
|
||||
// If you use Proj4js only to transform coordinates, you don't even need to
|
||||
// create an ol.proj.Projection instance. ol.proj.get() will take care of it
|
||||
// internally.
|
||||
|
||||
var projection = new ol.proj.Projection({
|
||||
code: 'EPSG:21781',
|
||||
extent: [485869.5728, 76443.1884, 837076.5648, 299941.7864]
|
||||
});
|
||||
|
||||
var extent = [420000, 30000, 900000, 350000];
|
||||
var layers = [
|
||||
@@ -67,7 +75,7 @@ var map = new ol.Map({
|
||||
target: 'map',
|
||||
view: new ol.View({
|
||||
projection: projection,
|
||||
center: ol.proj.transform([8.23, 46.86], 'EPSG:4326', 'EPSG:21781'),
|
||||
center: ol.proj.transform([8.23, 46.86], 'EPSG:4326', projection),
|
||||
extent: extent,
|
||||
zoom: 2
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user