Revision cc3c9807
Added by Andreas Kohlbecker over 10 years ago
7.x/modules/cdm_dataportal/js/map/openlayers_map.js | ||
---|---|---|
29 | 29 |
baseLayerNames: ["osgeo_vmap0"], |
30 | 30 |
defaultBaseLayerName: 'osgeo_vmap0', |
31 | 31 |
maxZoom: 4, |
32 |
minZoom: 0 |
|
32 |
minZoom: 0, |
|
33 |
/** |
|
34 |
* allows the map to display parts of the layers which are outside |
|
35 |
* the maxExtent if the aspect ratio of the map and of the baselayer |
|
36 |
* are not equal |
|
37 |
*/ |
|
38 |
displayOutsideMaxExtent: true, |
|
39 |
customWMSBaseLayerData: { |
|
40 |
name: "Euro+Med", |
|
41 |
url: "http://edit.africamuseum.be/geoserver/topp/wms", |
|
42 |
params: {layers: "topp:em_tiny_jan2003", format:"image/png", tiled: true}, |
|
43 |
projection: "EPSG:7777777", |
|
44 |
maxExtent: "-1600072.75, -1800000, 5600000, 5850093", |
|
45 |
unit: 'm' |
|
46 |
} |
|
33 | 47 |
}; |
34 | 48 |
})(jQuery); |
35 | 49 |
|
... | ... | |
64 | 78 |
projections: projections, |
65 | 79 |
mapExtends: mapExtends, |
66 | 80 |
getLayerByName: function(layerName){} // initially empty fuction, will be populated by openlayers_layers.js |
67 |
// TODO remove below lines before release |
|
68 |
// availableLayers: { |
|
69 |
// |
|
70 |
// layers: {}, // initially empty, will be populated by openlayers_layers.js |
|
71 |
// |
|
72 |
// createAllLayers: function() { |
|
73 |
// for (var key in this.layers) { |
|
74 |
// if (this.layers.hasOwnProperty(key)){ |
|
75 |
// var layer = this.layers[key]; |
|
76 |
// layer.create(); |
|
77 |
// }; |
|
78 |
// }; |
|
79 |
// } |
|
80 |
// } |
|
81 | 81 |
}; |
82 | 82 |
|
83 | 83 |
})(); // end of namespace definition for CdmOpenLayers |
... | ... | |
119 | 119 |
new OpenLayers.Control.Navigation({zoomWheelEnabled: false, handleRightClicks:true, zoomBoxKeyMask: OpenLayers.Handler.MOD_CTRL}) |
120 | 120 |
]; |
121 | 121 |
|
122 |
var dataProj = new OpenLayers.Projection("EPSG:4326"); |
|
122 |
// var dataProj = new OpenLayers.Projection("EPSG:4326");
|
|
123 | 123 |
|
124 | 124 |
var dataLayerOptions = { |
125 |
maxExtent: window.CdmOpenLayers.mapExtends.epsg_900913, |
|
126 | 125 |
isBaseLayer: false, |
127 | 126 |
displayInLayerSwitcher: true |
128 | 127 |
}; |
... | ... | |
139 | 138 |
*/ |
140 | 139 |
this.init = function(){ // public function |
141 | 140 |
|
142 |
createLayers(options.baseLayerNames, options.defaultBaseLayerName); |
|
141 |
createLayers(options.baseLayerNames, options.defaultBaseLayerName, options.customWMSBaseLayerData);
|
|
143 | 142 |
|
144 |
initOpenLayers();
|
|
143 |
initMap();
|
|
145 | 144 |
|
146 | 145 |
// -- Distribution Layer -- |
147 | 146 |
var mapServiceRequest; |
... | ... | |
228 | 227 |
|
229 | 228 |
var info = "<dl>"; |
230 | 229 |
info += "<dt>zoom:<dt><dd>" + map.getZoom() + "</dd>"; |
231 |
info += "<dt>resolution:<dt><dd>" + map.getResolution() + "</dd>"; |
|
232 |
info += "<dt>max resolution:<dt><dd>" + map.getMaxResolution() + "</dd>"; |
|
233 |
info += "<dt>scale:<dt><dd>" + map.getScale() + "</dd>"; |
|
234 |
info += "<dt>extend bbox:<dt><dd>" + map.getExtent().toBBOX() + " (" + mapExtendDegree.toBBOX() + ")</dd>";
|
|
235 |
info += "<dt>maxExtend bbox:<dt><dd>" + map.getMaxExtent().toBBOX() + "</dd>";
|
|
230 |
info += "<dt>map resolution:<dt><dd>" + map.getResolution() + "</dd>";
|
|
231 |
info += "<dt>map max resolution:<dt><dd>" + map.getMaxResolution() + "</dd>";
|
|
232 |
info += "<dt>map scale:<dt><dd>" + map.getScale() + "</dd>";
|
|
233 |
info += "<dt>map extent bbox:<dt><dd>" + map.getExtent().toBBOX() + " (" + mapExtendDegree.toBBOX() + ")</dd>";
|
|
234 |
info += "<dt>map maxExtent bbox:<dt><dd>" + map.getMaxExtent().toBBOX() + "</dd>";
|
|
236 | 235 |
info += "<dt>baselayer projection:<dt><dd>" + map.baseLayer.projection.getCode() + "</dd>"; |
237 | 236 |
info += "</dl>"; |
238 | 237 |
|
... | ... | |
244 | 243 |
}; |
245 | 244 |
|
246 | 245 |
/** |
247 |
* Initialize the Openlayers viewer with the base layer
|
|
246 |
* Initialize the Openlayers Map with the base layer
|
|
248 | 247 |
*/ |
249 |
var initOpenLayers = function(){
|
|
248 |
var initMap = function(){
|
|
250 | 249 |
|
251 | 250 |
|
252 | 251 |
if(options.showLayerSwitcher === true){ |
253 | 252 |
defaultControls.push(new OpenLayers.Control.LayerSwitcher({'ascending':false})); |
254 | 253 |
} |
255 | 254 |
|
256 |
// var maxExtendByAspectRatio = cropBoundsToAspectRatio(defaultBaseLayer.maxExtent, mapWidth/mapHeight);
|
|
255 |
// var maxExtentByAspectRatio = cropBoundsToAspectRatio(defaultBaseLayer.maxExtent, mapWidth/mapHeight);
|
|
257 | 256 |
var maxResolution = null; |
257 |
// gmaps has no maxExtent at this point, need to check for null |
|
258 | 258 |
if(defaultBaseLayer.maxExtent != null){ |
259 |
// gmaps has no maxExtend at this point |
|
260 |
maxResolution = defaultBaseLayer.maxExtent.getWidth()/ mapWidth; |
|
259 |
maxResolution = Math[(options.displayOutsideMaxExtent ? 'max' : 'min')]( |
|
260 |
defaultBaseLayer.maxExtent.getWidth() / mapWidth, |
|
261 |
defaultBaseLayer.maxExtent.getHeight() / mapHeight |
|
262 |
); |
|
261 | 263 |
} |
262 |
|
|
263 |
console.log("maxResolution: " + maxResolution); |
|
264 |
// console.log("restrictedExtent: " + maxExtendByAspectRatio.toBBOX()); |
|
264 |
console.log("mapOptions.maxResolution: " + maxResolution); |
|
265 |
console.log("mapOptions.restrictedExtent: " + defaultBaseLayer.maxExtent); |
|
265 | 266 |
|
266 | 267 |
map = new OpenLayers.Map( |
267 | 268 |
"openlayers_map", |
... | ... | |
270 | 271 |
controls: defaultControls, |
271 | 272 |
|
272 | 273 |
// maxResolution determines the lowest zoom level and thus places the map |
273 |
// in its maximum extend into the available view port so that no additinal
|
|
274 |
// in its maximum extent into the available view port so that no additinal
|
|
274 | 275 |
// gutter is visible and no parts of the map are hidden |
275 | 276 |
// see http://trac.osgeo.org/openlayers/wiki/SettingZoomLevels |
277 |
// IMPORTANT!!! |
|
278 |
// the maxResulution set here will be overwritten if the baselayers maxResolution |
|
279 |
// it is set |
|
276 | 280 |
maxResolution: maxResolution, |
277 | 281 |
|
278 |
// setting restrictedExtent the the maxExtend prevents from panning the
|
|
282 |
// setting restrictedExtent the the maxExtent prevents from panning the
|
|
279 | 283 |
// map out of its bounds |
280 | 284 |
restrictedExtent: defaultBaseLayer.maxExtent, |
281 | 285 |
// maxExtent: defaultBaseLayer.maxExtent, |
... | ... | |
296 | 300 |
map.addLayers(baseLayers); |
297 | 301 |
map.setBaseLayer(defaultBaseLayer); |
298 | 302 |
|
303 |
// calculate the bounds to zoom to |
|
299 | 304 |
zoomToBounds = zoomToBoundsFor(options.boundingBox, defaultBaseLayer); |
300 |
|
|
301 | 305 |
zoomToBounds = cropBoundsToAspectRatio(zoomToBounds, map.getSize().w / map.getSize().h); |
302 |
|
|
303 |
|
|
304 | 306 |
console.log("zoomToBounds: " + zoomToBounds); |
305 | 307 |
|
306 |
// zoom to the extend of the bbox
|
|
308 |
// zoom to the extent of the bbox
|
|
307 | 309 |
map.zoomToExtent(zoomToBounds, true); |
308 | 310 |
|
309 | 311 |
// readjust if the zoom level is out side of the min max |
310 |
if(map.getZoom() > options.maxZoom){ |
|
311 |
map.zoomTo(options.maxZoom); |
|
312 |
} else if(map.getZoom() < options.minZoom){ |
|
313 |
map.zoomTo(options.minZoom); |
|
314 |
} |
|
312 |
// if(map.getZoom() > options.maxZoom){
|
|
313 |
// map.zoomTo(options.maxZoom);
|
|
314 |
// } else if(map.getZoom() < options.minZoom){
|
|
315 |
// map.zoomTo(options.minZoom);
|
|
316 |
// }
|
|
315 | 317 |
|
316 | 318 |
}; |
317 | 319 |
|
... | ... | |
374 | 376 |
// zoom to the required area |
375 | 377 |
if(mapResponseObj.bbox !== undefined){ |
376 | 378 |
var newBounds = OpenLayers.Bounds.fromString( mapResponseObj.bbox ); |
379 |
newBounds.transform(layer.projection, map.getProjectionObject()); |
|
377 | 380 |
if(dataBounds !== null){ |
378 | 381 |
dataBounds.extend(newBounds); |
379 | 382 |
} else if(newBounds !== undefined){ |
380 | 383 |
dataBounds = newBounds; |
381 | 384 |
} |
382 |
map.zoomToExtent(dataBounds.transform(dataProj, map.getProjectionObject()), false);
|
|
385 |
map.zoomToExtent(dataBounds, false); |
|
383 | 386 |
|
384 | 387 |
if(map.getZoom() > options.maxZoom){ |
385 | 388 |
map.zoomTo(options.maxZoom); |
... | ... | |
467 | 470 |
/** |
468 | 471 |
* |
469 | 472 |
*/ |
470 |
var createLayers = function( baseLayerNames, defaultBaseLayerName){ |
|
471 |
for(var i = 0; i < baseLayerNames.length; i++) { |
|
473 |
var createLayers = function( baseLayerNames, defaultBaseLayerName, customWMSBaseLayerData){ |
|
474 |
var i = 0; |
|
475 |
for(; i < baseLayerNames.length; i++) { |
|
472 | 476 |
baseLayers[i] = window.CdmOpenLayers.getLayerByName(baseLayerNames[i]); |
473 | 477 |
if(baseLayerNames[i] == defaultBaseLayerName){ |
474 | 478 |
defaultBaseLayer = baseLayers[i]; |
475 | 479 |
} |
476 | 480 |
} |
481 |
if(false && customWMSBaseLayerData){ |
|
482 |
var wmsLayer = createWMSBaseLayer( |
|
483 |
customWMSBaseLayerData.name, |
|
484 |
customWMSBaseLayerData.url, |
|
485 |
customWMSBaseLayerData.params, |
|
486 |
customWMSBaseLayerData.projection, |
|
487 |
customWMSBaseLayerData.unit, |
|
488 |
OpenLayers.Bounds.fromString(customWMSBaseLayerData.maxExtent) |
|
489 |
); |
|
490 |
// FIXME remove HACK (customWMSBaseLayerData as default) |
|
491 |
baseLayers[i++] = wmsLayer; |
|
492 |
defaultBaseLayer = wmsLayer; |
|
493 |
} |
|
477 | 494 |
}; |
478 | 495 |
|
479 | 496 |
/** |
... | ... | |
542 | 559 |
* @param layer |
543 | 560 |
* the Openlayers.Layer |
544 | 561 |
* |
545 |
* @return the bboxstring projected onto the layer and intersected with the maximum extend of the layer
|
|
562 |
* @return the bboxstring projected onto the layer and intersected with the maximum extent of the layer
|
|
546 | 563 |
*/ |
547 | 564 |
var zoomToBoundsFor = function(bboxString, layer){ |
548 | 565 |
var zoomToBounds; |
549 | 566 |
if(typeof bboxString == 'string' && bboxString.length > 6) { |
550 | 567 |
zoomToBounds = OpenLayers.Bounds.fromString(bboxString); |
568 |
// transform bounding box given in degree values to the projection of the base layer |
|
569 |
zoomToBounds.transform(CdmOpenLayers.projections.epsg_4326, layer.projection); |
|
570 |
} else if(layer.maxExtent) { |
|
571 |
zoomToBounds = layer.maxExtent; |
|
572 |
// no need to transform since the bounds are obtained from the layer |
|
551 | 573 |
} else { |
552 | 574 |
zoomToBounds = new OpenLayers.Bounds(-180, -90, 180, 90); |
575 |
// transform bounding box given in degree values to the projection of the base layer |
|
576 |
zoomToBounds.transform(CdmOpenLayers.projections.epsg_4326, layer.projection); |
|
553 | 577 |
} |
554 |
// transform bounding box given in degree values to the projection of the base layer |
|
555 |
zoomToBounds.transform(CdmOpenLayers.projections.epsg_4326, layer.projection); |
|
556 | 578 |
|
557 | 579 |
zoomToBounds = intersectionOfBounds(layer.maxExtent, zoomToBounds); |
558 | 580 |
|
... | ... | |
576 | 598 |
} |
577 | 599 |
}; |
578 | 600 |
|
601 |
/** |
|
602 |
* Creates a WMS Base layer |
|
603 |
* @param String name |
|
604 |
* A name for the layer |
|
605 |
* @param String url |
|
606 |
* Base url for the WMS (e.g. http://wms.jpl.nasa.gov/wms.cgi) |
|
607 |
* @param Object params |
|
608 |
* An object with key/value pairs representing the GetMap query string parameters and parameter values. |
|
609 |
* @param Object projection |
|
610 |
* A OpenLayers.Projection object |
|
611 |
*/ |
|
612 |
var createWMSBaseLayer= function(name, url, params, projection, unit, maxExtent){ |
|
613 |
|
|
614 |
if(maxExtent == null){ |
|
615 |
maxExtent = CdmOpenLayers.mapExtends.epsg_4326.clone(); |
|
616 |
maxExtent.transform(CdmOpenLayers.projections.epsg_4326, projection); |
|
617 |
} |
|
618 |
|
|
619 |
return new OpenLayers.Layer.WMS( |
|
620 |
name, |
|
621 |
url, |
|
622 |
params, |
|
623 |
{ |
|
624 |
maxExtent: maxExtent, |
|
625 |
projection: projection, |
|
626 |
unit: unit, |
|
627 |
isBaseLayer: true, |
|
628 |
displayInLayerSwitcher: true |
|
629 |
} |
|
630 |
); |
|
631 |
}; |
|
632 |
|
|
579 | 633 |
}; // end of CdmOpenLayers.Map |
580 | 634 |
})(); |
581 | 635 |
|
Also available in: Unified diff
refactoring map settings and rendering