Added support for different projections for main map and overview map. Patch by bartvde. Modifications to the original patch:
* caclulation of resolution factor no longer depends on proj4js, * created a member variable for the resolution factor and moved the calculation of the resolution factor to createMap(), * created acceptance test (tests/manual/overviewmap-projection.html). r=me (closes #1620) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7864 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -103,6 +103,12 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
handlers: null,
|
||||
|
||||
/**
|
||||
* Property: resolutionFactor
|
||||
* {Object}
|
||||
*/
|
||||
resolutionFactor: 1,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.OverviewMap
|
||||
* Create a new overview map
|
||||
@@ -402,6 +408,13 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
Math.max(mapExtent.bottom, maxExtent.bottom),
|
||||
Math.min(mapExtent.right, maxExtent.right),
|
||||
Math.min(mapExtent.top, maxExtent.top));
|
||||
|
||||
if (this.ovmap.getProjection() != this.map.getProjection()) {
|
||||
testExtent = testExtent.transform(
|
||||
this.map.getProjectionObject(),
|
||||
this.ovmap.getProjectionObject() );
|
||||
}
|
||||
|
||||
var resRatio = this.ovmap.getResolution() / this.map.getResolution();
|
||||
return ((resRatio > this.minRatio) &&
|
||||
(resRatio <= this.maxRatio) &&
|
||||
@@ -423,8 +436,16 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
// zoom out overview map
|
||||
targetRes = this.maxRatio * mapRes;
|
||||
}
|
||||
this.ovmap.setCenter(this.map.center,
|
||||
this.ovmap.getZoomForResolution(targetRes));
|
||||
var center;
|
||||
if (this.ovmap.getProjection() != this.map.getProjection()) {
|
||||
center = this.map.center.clone();
|
||||
center.transform(this.map.getProjectionObject(),
|
||||
this.ovmap.getProjectionObject() );
|
||||
} else {
|
||||
center = this.map.center;
|
||||
}
|
||||
this.ovmap.setCenter(center, this.ovmap.getZoomForResolution(
|
||||
targetRes * this.resolutionFactor));
|
||||
this.updateRectToMap();
|
||||
},
|
||||
|
||||
@@ -486,6 +507,15 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
});
|
||||
|
||||
if (this.ovmap.getProjection() != this.map.getProjection()) {
|
||||
var sourceUnits = this.map.getProjectionObject().getUnits() ||
|
||||
this.map.units || this.map.baseLayer.units;
|
||||
var targetUnits = this.ovmap.getProjectionObject().getUnits() ||
|
||||
this.ovmap.units || this.ovmap.baseLayer.units;
|
||||
this.resolutionFactor = sourceUnits && targetUnits ?
|
||||
OpenLayers.INCHES_PER_UNIT[sourceUnits] /
|
||||
OpenLayers.INCHES_PER_UNIT[targetUnits] : 1;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -493,14 +523,16 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Updates the extent rectangle position and size to match the map extent
|
||||
*/
|
||||
updateRectToMap: function() {
|
||||
// The base layer for overview map needs to be in the same projection
|
||||
// as the base layer for the main map. This should be made more robust.
|
||||
if(this.map.getUnits() != 'degrees') {
|
||||
if(this.ovmap.getProjection() && (this.map.getProjection() != this.ovmap.getProjection())) {
|
||||
OpenLayers.Console.userError(OpenLayers.i18n("sameProjection"));
|
||||
}
|
||||
// If the projections differ we need to reproject
|
||||
var bounds;
|
||||
if (this.ovmap.getProjection() != this.map.getProjection()) {
|
||||
bounds = this.map.getExtent().transform(
|
||||
this.map.getProjectionObject(),
|
||||
this.ovmap.getProjectionObject() );
|
||||
} else {
|
||||
bounds = this.map.getExtent();
|
||||
}
|
||||
var pxBounds = this.getRectBoundsFromMapBounds(this.map.getExtent());
|
||||
var pxBounds = this.getRectBoundsFromMapBounds(bounds);
|
||||
if (pxBounds) {
|
||||
this.setRectPxBounds(pxBounds);
|
||||
}
|
||||
@@ -512,6 +544,11 @@ OpenLayers.Control.OverviewMap = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
updateMapToRect: function() {
|
||||
var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds);
|
||||
if (this.ovmap.getProjection() != this.map.getProjection()) {
|
||||
lonLatBounds = lonLatBounds.transform(
|
||||
this.ovmap.getProjectionObject(),
|
||||
this.map.getProjectionObject() );
|
||||
}
|
||||
this.map.panTo(lonLatBounds.getCenterLonLat());
|
||||
},
|
||||
|
||||
|
||||
70
tests/manual/overviewmap-projection.html
Normal file
70
tests/manual/overviewmap-projection.html
Normal file
@@ -0,0 +1,70 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../theme/default/style.css" type="text/css" />
|
||||
<link rel="stylesheet" href="../../examples/style.css" type="text/css" />
|
||||
<style type="text/css">
|
||||
.olControlAttribution { bottom: 0px!important }
|
||||
#map {
|
||||
height: 512px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
|
||||
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
// make map available for easy debugging
|
||||
var map;
|
||||
|
||||
function init(){
|
||||
var options = {
|
||||
projection: new OpenLayers.Projection("EPSG:900913"),
|
||||
displayProjection: new OpenLayers.Projection("EPSG:4326"),
|
||||
units: "m",
|
||||
maxResolution: 156543.0339,
|
||||
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
|
||||
20037508, 20037508.34)
|
||||
};
|
||||
map = new OpenLayers.Map('map', options);
|
||||
|
||||
// create Google Mercator layers
|
||||
var gmap = new OpenLayers.Layer.Google(
|
||||
"Google Streets",
|
||||
{'sphericalMercator': true}
|
||||
);
|
||||
map.addLayers([gmap]);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
map.addControl(new OpenLayers.Control.Permalink());
|
||||
map.addControl(new OpenLayers.Control.MousePosition());
|
||||
var ovmap = new OpenLayers.Control.OverviewMap({
|
||||
maxRatio: 16,
|
||||
layers: [new OpenLayers.Layer.WMS("OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'})]
|
||||
});
|
||||
map.addControl(ovmap);
|
||||
ovmap.maximizeControl();
|
||||
if (!map.getCenter()) {map.zoomToMaxExtent()};
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1 id="title">OpenLayers Overview Map Projection Test</h1>
|
||||
|
||||
<div id="tags">
|
||||
</div>
|
||||
<p id="shortdesc">
|
||||
Acceptance test for different projections in map and overview map.
|
||||
The map uses EPSG:900913, the overview map EPSG:4326. Zoom the map and
|
||||
drag both the map and the overview map to see it in action.
|
||||
</p>
|
||||
<div id="map" class="smallmap"></div>
|
||||
|
||||
<div id="docs">
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user