Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graticule control improvements #1375

Merged
merged 12 commits into from
Oct 17, 2014
17 changes: 10 additions & 7 deletions examples/graticule.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
<script src="http://svn.osgeo.org/metacrs/proj4js/trunk/lib/proj4js-compressed.js"></script>
<script type="text/javascript">
Proj4js.defs["EPSG:42304"]="+title=Atlas of Canada, LCC +proj=lcc +lat_1=49 +lat_2=77 +lat_0=49 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs";

OpenLayers.Projection.defaults["EPSG:42304"] = {
maxExtent: [-2200000,-712631,3072800,3840000],
worldExtent: [-180, 30, 180, 90],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about EPSG:42304 but can you explain how you get to the value of 30 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A leftover from playing around. I changed it to 0, which is kind of obvious for polar projections.

units: 'm'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also how come units need to be repeated in defaults, when they are part of the projection object itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to. Removing.

}
// Allow date line wrapping for 10 worlds by using -1800 and 1800
// instead of -180 and 180.
OpenLayers.Projection.defaults["EPSG:4326"].worldExtent = [-1800, -90, 1800, 90];
var graticuleCtl1, graticuleCtl2;
var map1, map2;
function init(){
Expand Down Expand Up @@ -56,7 +63,6 @@
};

function initProjected(){
var extent = new OpenLayers.Bounds(-2200000,-712631,3072800,3840000);
graticuleCtl2 = new OpenLayers.Control.Graticule({
labelled: true,
targetSize: 200
Expand All @@ -68,10 +74,6 @@
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Navigation()
],
//scales: tempScales,
maxExtent: extent,
maxResolution: 50000,
units: 'm',
projection: 'EPSG:42304'
};
map2 = new OpenLayers.Map('map2', mapOptions);
Expand All @@ -85,7 +87,7 @@
});

map2.addLayers([dm_wms]);
if (!map2.getCenter()) map2.zoomToExtent(extent);
map2.setCenter([436400, 1564045], 1);
}
</script>
</head>
Expand Down Expand Up @@ -114,3 +116,4 @@ <h1 id="title">Graticule Example</h1>
</ul>
</body>
</html>

106 changes: 47 additions & 59 deletions examples/polar-projections.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,69 @@
var map, layer, overlay;

var projectionOptions = {
'EPSG:3574': {
projection: new OpenLayers.Projection('EPSG:3574'),
units: 'm',
maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
maxResolution: 5505054 / 128,
numZoomLevels: 18
},
'EPSG:3576': {
projection: new OpenLayers.Projection('EPSG:3576'),
units: 'm',
maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
maxResolution: 5505054 / 128,
numZoomLevels: 18
},
'EPSG:3571': {
projection: new OpenLayers.Projection('EPSG:3571'),
units: 'm',
maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
maxResolution: 5505054 / 128,
numZoomLevels: 18
},
'EPSG:3573': {
projection: new OpenLayers.Projection('EPSG:3573'),
units: 'm',
maxExtent: new OpenLayers.Bounds(-5505054, -5505054, 5505054, 5505054),
maxResolution: 5505054 / 128,
numZoomLevels: 18
}
OpenLayers.Projection.defaults['EPSG:3574'] = {
maxExtent: [-5505054, -5505054, 5505054, 5505054],
worldExtent: [-180.0, 0.0, 180.0, 90.0],
units: 'm'
};
OpenLayers.Projection.defaults['EPSG:3576'] = {
maxExtent: [-5505054, -5505054, 5505054, 5505054],
worldExtent: [-180.0, 0.0, 180.0, 90.0],
units: 'm'
};
OpenLayers.Projection.defaults['EPSG:3571'] = {
maxExtent: [-5505054, -5505054, 5505054, 5505054],
worldExtent: [-180.0, 0.0, 180.0, 90.0],
units: 'm'
};
OpenLayers.Projection.defaults['EPSG:3573'] = {
maxExtent: [-5505054, -5505054, 5505054, 5505054],
worldExtent: [-180.0, 0.0, 180.0, 90.0],
units: 'm'
};

function setProjection() {
projCode = this.innerHTML;
var oldExtent = map.getExtent();
var oldCenter = map.getCenter();
var oldProjection = map.getProjectionObject();
// map projection is controlled by the base layer
map.baseLayer.addOptions(projectionOptions[projCode]);

// the base layer controls the map projection
layer.addOptions({projection: projCode});

// with the base layer updated, the map has the new projection now
var newProjection = map.getProjectionObject();

// transform the center of the old projection, not the extent
map.setCenter(
oldCenter.transform(oldProjection, newProjection,
map.getZoomForExtent(oldExtent.transform(oldProjection, newProjection))
));

for (var i=map.layers.length-1; i>=0; --i) {
// update grid settings
map.layers[i].addOptions(projectionOptions[projCode]);
// redraw layer - just in case center and zoom are the same in old and
// new projection
map.layers[i].redraw();
}
map.setCenter(oldCenter.transform(oldProjection, newProjection));

// update overlay layers here
overlay.addOptions({projection: newProjection});

// re-fetch images for all layers
layer.redraw();
overlay.redraw();
}

function init() {
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS(
'world',
'http://v2.suite.opengeo.org/geoserver/wms',
{layers: 'world', version: '1.1.1'},
projectionOptions['EPSG:3574']
'countries',
'http://suite.opengeo.org/geoserver/wms',
{layers: 'opengeo:borders', version: '1.1.1'},
{projection: 'EPSG:3574', displayOutsideMaxExtent: true}
);
overlay = new OpenLayers.Layer.WMS(
'world',
'http://v2.suite.opengeo.org/geoserver/wms',
{transparent: 'true', layers: 'world:borders', styles: 'line'},
projectionOptions['EPSG:3574']
'cities',
'http://suite.opengeo.org/geoserver/wms',
{layers: 'opengeo:cities', version: '1.1.1', transparent: true},
{projection: 'EPSG:3574', displayOutsideMaxExtent: true,
isBaseLayer: false}
);
overlay.isBaseLayer = false;
map.addLayers([layer, overlay]);
map.zoomToMaxExtent();

map = new OpenLayers.Map('map', {
center: [25000, 25000],
zoom: 1,
layers: [layer, overlay]
});
map.addControl(new OpenLayers.Control.Graticule());

// add behaviour to dom elements
document.getElementById('epsg3574').onclick = setProjection;
document.getElementById('epsg3576').onclick = setProjection;
Expand Down
Loading