bringing all changes from sandbox/euzuro/LayersReworking down into the trunk. this is a merge of r656:HEAD http://svn.openlayers.org/sandbox/euzuro/LayersReworking
git-svn-id: http://svn.openlayers.org/trunk/openlayers@806 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -27,10 +27,11 @@
|
||||
|
||||
function init(){
|
||||
// these should be object methods or something
|
||||
map = new OpenLayers.Map( $('map'), {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
||||
map = new OpenLayers.Map( $('map') );
|
||||
var basemap = new OpenLayers.Layer.WMS( "Boston",
|
||||
"http://boston.freemap.in/cgi-bin/mapserv?",
|
||||
{map: '/www/freemap.in/boston/map/mass.map', layers: 'border,water,roads', format: 'png'} );
|
||||
{map: '/www/freemap.in/boston/map/mass.map', layers: 'border,water,roads', format: 'png'},
|
||||
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
||||
var rapid = new OpenLayers.Layer.WMS( "Rapid Transit",
|
||||
"http://boston.freemap.in/cgi-bin/mapserv?",
|
||||
{map: '/www/freemap.in/boston/map/mass.map', layers: 'rapid_transit', format: 'png', transparent:'true'} );
|
||||
|
||||
@@ -20,19 +20,33 @@
|
||||
function init(){
|
||||
map = new OpenLayers.Map( $('map') );
|
||||
gmap = new OpenLayers.Layer.Google( "Google" );
|
||||
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||
map.addLayer(gmap);
|
||||
|
||||
markers = new OpenLayers.Layer.Markers("markers");
|
||||
map.addLayer(markers);
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||
map.addLayer(layer);
|
||||
map.addLayer(gmap);
|
||||
map.addControl( new OpenLayers.Control.LayerSwitcher() );
|
||||
}
|
||||
|
||||
function add() {
|
||||
var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',new OpenLayers.Size(10,17));
|
||||
marker = new OpenLayers.Marker(new OpenLayers.LonLat(2, 41), icon);
|
||||
markers.addMarker(marker);
|
||||
}
|
||||
|
||||
function remove() {
|
||||
markers.removeMarker(marker);
|
||||
}
|
||||
|
||||
// -->
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1>OpenLayers Example</h1>
|
||||
<div id="map"></div>
|
||||
<div style="background-color:green" onclick="add()"> click to add the marker to the map</div>
|
||||
<div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,16 +19,17 @@
|
||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
var markers = new OpenLayers.Layer.Markers( "Markers" );
|
||||
map.addLayer(markers);
|
||||
var newl = new OpenLayers.Layer.Text( "text", "./textfile.txt" );
|
||||
var newl = new OpenLayers.Layer.Text( "text", { location:"./textfile.txt"} );
|
||||
map.addLayer(newl);
|
||||
var size = new OpenLayers.Size(10,17);
|
||||
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
|
||||
var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',size,offset);
|
||||
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),icon));
|
||||
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,45),icon));
|
||||
marker = new OpenLayers.Marker(new OpenLayers.LonLat(90,10),icon);
|
||||
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,45),icon.clone()));
|
||||
marker = new OpenLayers.Marker(new OpenLayers.LonLat(90,10),icon.clone());
|
||||
marker.events.register('mousedown', marker, function(evt) { alert(this.icon.url); Event.stop(evt); });
|
||||
markers.addMarker(marker);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
map.addLayer(layer);
|
||||
|
||||
var newl = new OpenLayers.Layer.Text( "text", "./textfile.txt" );
|
||||
var newl = new OpenLayers.Layer.Text( "text", {location: "./textfile.txt"} );
|
||||
map.addLayer(newl);
|
||||
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
|
||||
@@ -95,7 +95,7 @@ function runMVS() {
|
||||
safeArgs.zoom);
|
||||
|
||||
if (safeArgs.data) {
|
||||
theMVS.addLayer(new OpenLayers.Layer.Text("Data", safeArgs.data));
|
||||
theMVS.addLayer(new OpenLayers.Layer.Text("Data", {location: safeArgs.data}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
52
examples/wms.html
Normal file
52
examples/wms.html
Normal file
@@ -0,0 +1,52 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="imagetoolbar" content="no"> <!--ie image gizmo OFF!-->
|
||||
<style type="text/css">
|
||||
#map {
|
||||
width: 800px;
|
||||
height: 475px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var lon = 5;
|
||||
var lat = 40;
|
||||
var zoom = 5;
|
||||
var map, layer;
|
||||
|
||||
function init(){
|
||||
map = new OpenLayers.Map( $('map') );
|
||||
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||
map.addLayer(layer);
|
||||
|
||||
markers = new OpenLayers.Layer.Markers("markers");
|
||||
map.addLayer(markers);
|
||||
|
||||
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
|
||||
map.addControl( new OpenLayers.Control.LayerSwitcher() );
|
||||
}
|
||||
|
||||
function add() {
|
||||
var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',new OpenLayers.Size(10,17));
|
||||
marker = new OpenLayers.Marker(new OpenLayers.LonLat(2, 41), icon);
|
||||
markers.addMarker(marker);
|
||||
}
|
||||
|
||||
|
||||
function remove() {
|
||||
markers.removeMarker(marker);
|
||||
}
|
||||
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<div id="map"></div>
|
||||
<div style="background-color:green" onclick="add()"> click to add the marker to the map</div>
|
||||
<div style="background-color:red" onclick="remove()"> click to remove the marker from the map</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -33,31 +33,20 @@ OpenLayers.Control.KeyboardDefaults.prototype =
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultKeyDown: function (evt) {
|
||||
|
||||
var slide = this.map.getResolution() * this.slideFactor;
|
||||
var center = this.map.getCenter();
|
||||
|
||||
var newCenter = center.copyOf();
|
||||
|
||||
switch(evt.keyCode) {
|
||||
case Event.KEY_LEFT:
|
||||
newCenter = newCenter.add( -slide, 0);
|
||||
this.map.pan(-50, 0);
|
||||
break;
|
||||
case Event.KEY_RIGHT:
|
||||
newCenter = newCenter.add( slide, 0);
|
||||
this.map.pan(50, 0);
|
||||
break;
|
||||
case Event.KEY_UP:
|
||||
newCenter = newCenter.add( 0, slide);
|
||||
this.map.pan(0, -50);
|
||||
break;
|
||||
case Event.KEY_DOWN:
|
||||
newCenter = newCenter.add( 0, -slide);
|
||||
this.map.pan(0, 50);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!newCenter.equals(center)) {
|
||||
this.map.setCenter(newCenter);
|
||||
Event.stop(evt);
|
||||
}
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
|
||||
@@ -113,23 +113,18 @@ OpenLayers.Control.PanZoom.prototype =
|
||||
buttonDown: function (evt) {
|
||||
if (!Event.isLeftClick(evt)) return;
|
||||
|
||||
var slide = this.map.getResolution() * this.slideFactor;
|
||||
var center = this.map.getCenter();
|
||||
|
||||
var newCenter = center.copyOf();
|
||||
|
||||
switch (this.action) {
|
||||
case "panup":
|
||||
newCenter = newCenter.add( 0, slide);
|
||||
this.map.pan(0, -50);
|
||||
break;
|
||||
case "pandown":
|
||||
newCenter = newCenter.add( 0, -slide);
|
||||
this.map.pan(0, 50);
|
||||
break;
|
||||
case "panleft":
|
||||
newCenter = newCenter.add( -slide, 0);
|
||||
this.map.pan(-50, 0);
|
||||
break;
|
||||
case "panright":
|
||||
newCenter = newCenter.add( slide, 0);
|
||||
this.map.pan(50, 0);
|
||||
break;
|
||||
case "zoomin":
|
||||
this.map.zoomIn();
|
||||
@@ -138,14 +133,10 @@ OpenLayers.Control.PanZoom.prototype =
|
||||
this.map.zoomOut();
|
||||
break;
|
||||
case "zoomworld":
|
||||
this.map.zoomToFullExtent();
|
||||
this.map.zoomToMaxExtent();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!newCenter.equals(center)) {
|
||||
this.map.setCenter(newCenter);
|
||||
}
|
||||
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
|
||||
@@ -24,6 +24,10 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
OpenLayers.Control.PanZoom.prototype.initialize.apply(this, arguments);
|
||||
this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoomBar.X,
|
||||
OpenLayers.Control.PanZoomBar.Y);
|
||||
|
||||
// put code here to catch "changebaselayer" event from map, because
|
||||
// we are going to have to redraw this thing each time, because
|
||||
// maxZoom will/might change.
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -60,7 +64,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
var id = "OpenLayers_Control_PanZoomBar_Slider" + this.map.id;
|
||||
var slider = OpenLayers.Util.createAlphaImageDiv(id,
|
||||
centered.add(-1,
|
||||
(this.map.getZoomLevels())*this.zoomStopHeight),
|
||||
(this.map.getMaxZoomLevel())*this.zoomStopHeight),
|
||||
new OpenLayers.Size(20,9),
|
||||
imgLocation+"slider.png",
|
||||
"absolute");
|
||||
@@ -74,7 +78,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
this.sliderEvents.register("click", this, this.doubleClick);
|
||||
|
||||
sz = new OpenLayers.Size();
|
||||
sz.h = this.zoomStopHeight*(this.map.getZoomLevels()+1);
|
||||
sz.h = this.zoomStopHeight*(this.map.getMaxZoomLevel()+1);
|
||||
sz.w = this.zoomStopWidth;
|
||||
var div = null
|
||||
|
||||
@@ -110,7 +114,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
this.map.events.register("zoomend", this, this.moveZoomBar);
|
||||
|
||||
centered = centered.add(0,
|
||||
this.zoomStopHeight*(this.map.getZoomLevels()+1));
|
||||
this.zoomStopHeight*(this.map.getMaxZoomLevel()+1));
|
||||
return centered;
|
||||
},
|
||||
/*
|
||||
@@ -131,7 +135,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
var y = evt.xy.y;
|
||||
var top = Position.page(evt.object)[1];
|
||||
var levels = Math.floor((y - top)/this.zoomStopHeight);
|
||||
this.map.zoomTo(this.map.getZoomLevels() - levels);
|
||||
this.map.zoomTo(this.map.getMaxZoomLevel() - levels);
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
@@ -193,7 +197,7 @@ OpenLayers.Control.PanZoomBar.prototype =
|
||||
*/
|
||||
moveZoomBar:function() {
|
||||
var newTop =
|
||||
(this.map.getZoomLevels() - this.map.getZoom()) * this.zoomStopHeight
|
||||
(this.map.getMaxZoomLevel() - this.map.getZoom()) * this.zoomStopHeight
|
||||
+ this.startTop + 1;
|
||||
this.slider.style.top = newTop + "px";
|
||||
},
|
||||
|
||||
@@ -53,7 +53,7 @@ OpenLayers.Icon.prototype = {
|
||||
* @type OpenLayers.Icon
|
||||
*/
|
||||
clone: function() {
|
||||
return new OpenLayers.Icon(this.size, this.url, this.offset);
|
||||
return new OpenLayers.Icon(this.url, this.size, this.offset);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,17 +13,43 @@ OpenLayers.Layer.prototype = {
|
||||
/** @type DOMElement */
|
||||
div: null,
|
||||
|
||||
/** This variable is set in map.addLayer, not within the layer itself
|
||||
/** This variable is set when the layer is added to the map, via the
|
||||
* accessor function setMap()
|
||||
*
|
||||
* @type OpenLayers.Map */
|
||||
map: null,
|
||||
|
||||
|
||||
// OPTIONS
|
||||
|
||||
/** @type String */
|
||||
projection: null,
|
||||
|
||||
/** @type OpenLayers.Bounds */
|
||||
maxExtent: null,
|
||||
|
||||
/** @type float */
|
||||
maxResolution: null,
|
||||
|
||||
/** @type int */
|
||||
minZoomLevel: null,
|
||||
|
||||
/** @type int */
|
||||
maxZoomLevel: null,
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name) {
|
||||
initialize: function(name, options) {
|
||||
if (arguments.length > 0) {
|
||||
|
||||
//add options to layer
|
||||
Object.extend(this, options);
|
||||
|
||||
this.name = name;
|
||||
if (this.div == null) {
|
||||
this.div = OpenLayers.Util.createDiv();
|
||||
@@ -46,14 +72,17 @@ OpenLayers.Layer.prototype = {
|
||||
|
||||
/**
|
||||
* @params {OpenLayers.Bounds} bound
|
||||
* @params {Boolean} zoomChanged tells when zoom has changed, as layers have to do some init work in that case.
|
||||
* @params {Boolean} zoomChanged tells when zoom has changed, as layers
|
||||
* have to do some init work in that case.
|
||||
*/
|
||||
moveTo: function (bound, zoomChanged) {
|
||||
// not implemented here
|
||||
return;
|
||||
//this function should be implemented by all subclasses.
|
||||
},
|
||||
|
||||
/**
|
||||
/** Set the map property for the layer. This is done through an accessor
|
||||
* so that subclasses can override this and take special action once
|
||||
* they have their map variable set.
|
||||
*
|
||||
* @param {OpenLayers.Map} map
|
||||
*/
|
||||
setMap: function(map) {
|
||||
@@ -62,11 +91,12 @@ OpenLayers.Layer.prototype = {
|
||||
|
||||
/**
|
||||
* @returns Whether or not the layer is a base layer. This should be
|
||||
* determined individually by all subclasses.
|
||||
* determined individually by all subclasses. Default is false
|
||||
* @type Boolean
|
||||
*/
|
||||
isBaseLayer: function() {
|
||||
//this function should be implemented by all subclasses.
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -87,6 +117,158 @@ OpenLayers.Layer.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Layer Options */
|
||||
/* */
|
||||
/* Accessor functions to Layer Options parameters */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @type String
|
||||
*/
|
||||
getProjection: function() {
|
||||
return this.projection;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getMaxExtent: function() {
|
||||
return this.maxExtent;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type float
|
||||
*/
|
||||
getMaxResolution: function() {
|
||||
return this.maxResolution;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The minimum zoom level that can be reached in this layer
|
||||
* @type int
|
||||
*/
|
||||
getMinZoomLevel: function() {
|
||||
return this.minZoomLevel;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The maximum zoom level that can be reached in this layer
|
||||
* @type int
|
||||
*/
|
||||
getMaxZoomLevel: function() {
|
||||
return this.maxZoomLevel;
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Baselayer Functions */
|
||||
/* */
|
||||
/* The following functions must all be implemented */
|
||||
/* by all base layers */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @returns Degrees per Pixel
|
||||
* @type float
|
||||
*/
|
||||
getResolution: function() {
|
||||
var viewSize = this.map.getSize();
|
||||
var extent = this.map.getExtent();
|
||||
return Math.max( extent.getWidth() / viewSize.w,
|
||||
extent.getHeight() / viewSize.h );
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} viewPortPx
|
||||
*
|
||||
* @returns An OpenLayers.LonLat which is the passed-in view port
|
||||
* OpenLayers.Pixel, translated into lon/lat by the layer
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
getLonLatFromViewPortPx: function (viewPortPx) {
|
||||
var size = this.map.getSize();
|
||||
var center = this.map.getCenter(); //map center lon/lat
|
||||
var res = this.map.getResolution();
|
||||
|
||||
var delta_x = viewPortPx.x - (size.w / 2);
|
||||
var delta_y = viewPortPx.y - (size.h / 2);
|
||||
|
||||
return new OpenLayers.LonLat(center.lon + delta_x * res ,
|
||||
center.lat - delta_y * res);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into view port pixels
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getViewPortPxFromLonLat: function (lonlat) {
|
||||
var resolution = this.map.getResolution();
|
||||
var extent = this.map.getExtent();
|
||||
return new OpenLayers.Pixel(
|
||||
Math.round(1/resolution * (lonlat.lon - extent.left)),
|
||||
Math.round(1/resolution * (extent.top - lonlat.lat))
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @return {int}
|
||||
*/
|
||||
getZoomForExtent: function (bounds) {
|
||||
// this should be implemented by subclasses
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||
* current viewPort.
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getExtent: function () {
|
||||
// this should be implemented by subclasses
|
||||
var extent = null;
|
||||
|
||||
var center = this.map.getCenter();
|
||||
if (center != null) {
|
||||
|
||||
var res = this.getResolution();
|
||||
var size = this.map.getSize();
|
||||
var w_deg = size.w * res;
|
||||
var h_deg = size.h * res;
|
||||
|
||||
return new OpenLayers.Bounds(center.lon - w_deg / 2,
|
||||
center.lat - h_deg / 2,
|
||||
center.lon + w_deg / 2,
|
||||
center.lat + h_deg / 2);
|
||||
|
||||
}
|
||||
|
||||
return extent;
|
||||
/** ALT CALCULATION FOR GETEXTENT
|
||||
|
||||
var size = this.getSize();
|
||||
|
||||
var tlPx = new OpenLayers.Pixel(0,0);
|
||||
var tlLL = this.getLonLatFromViewPortPx(tlPx);
|
||||
|
||||
var brPx = new OpenLayers.Pixel(size.w, size.h);
|
||||
var brLL = this.getLonLatFromViewPortPx(brPx);
|
||||
|
||||
extent = new OpenLayers.Bounds(tlLL.lon,
|
||||
brLL.lat,
|
||||
brLL.lon,
|
||||
tlLL.lat);
|
||||
**/
|
||||
},
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Layer"
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ OpenLayers.Layer.Google = Class.create();
|
||||
OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
/** @type Boolean */
|
||||
viewPortLayer: true,
|
||||
isFixed: true,
|
||||
|
||||
/** @type GMap2 gmap stores the Google Map element */
|
||||
gmap:null,
|
||||
@@ -27,8 +27,18 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
*
|
||||
* @param {String} name
|
||||
*/
|
||||
initialize: function(name) {
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, [name]);
|
||||
initialize: function(name, options) {
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
|
||||
|
||||
if (this.minZoomLevel == null) {
|
||||
this.minZoomLevel = -1;
|
||||
}
|
||||
if (this.maxZoomLevel == null) {
|
||||
this.maxZoomLevel = 16;
|
||||
}
|
||||
if (this.maxExtent == null) {
|
||||
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -50,21 +60,29 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
* @param {int} zoomChanged
|
||||
* @param {Boolean} zoomChanged
|
||||
*/
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
moveTo:function(bounds, zoomChanged) {
|
||||
|
||||
if ((this.gmap != null) && (!this.dragging)) {
|
||||
|
||||
var olCenter = this.map.getCenter();
|
||||
var gCenter = this.getGMapCenter();
|
||||
var newCenter = this.map.getCenter();
|
||||
var newZoom = this.map.getZoom();
|
||||
|
||||
var olZoom = this.map.getZoom();
|
||||
if (newCenter != null) {
|
||||
var gCenter = this.gmap.getCenter();
|
||||
var gZoom = this.gmap.getZoom();
|
||||
|
||||
if ((!olCenter.equals(gCenter)) || ((olZoom +1) != gZoom)) {
|
||||
this.gmap.setCenter(new GLatLng(olCenter.lat, olCenter.lon),
|
||||
olZoom + 1);
|
||||
var currentCenter = this.getOLLonLatFromGLatLng(gCenter);
|
||||
var currentZoom = this.getOLZoomFromGZoom(gZoom);
|
||||
|
||||
if ( (!newCenter.equals(currentCenter)) ||
|
||||
(newZoom != currentZoom) ) {
|
||||
|
||||
this.gmap.setCenter(this.getGLatLngFromOLLonLat(newCenter),
|
||||
this.getGZoomFromOLZoom(newZoom));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -73,6 +91,7 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
*
|
||||
*/
|
||||
loadGMap:function() {
|
||||
|
||||
// create div and set to same size as map
|
||||
var gDiv = OpenLayers.Util.createDiv(this.name);
|
||||
var sz = this.map.getSize();
|
||||
@@ -82,6 +101,8 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
// create GMap, hide nav controls
|
||||
this.gmap = new GMap2(this.div);
|
||||
|
||||
// this causes the GMap to set itself to Map's center/zoom
|
||||
this.moveTo();
|
||||
|
||||
// catch pans and zooms from GMap
|
||||
@@ -101,6 +122,11 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
"dragend",
|
||||
this.dragEnd.bindAsEventListener(this));
|
||||
|
||||
// catch pans and zooms from GMap
|
||||
GEvent.addListener(this.gmap,
|
||||
"drag",
|
||||
this.catchPanZoom.bindAsEventListener(this));
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -123,27 +149,206 @@ OpenLayers.Layer.Google.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
* @param {event} e
|
||||
*/
|
||||
catchPanZoom: function(e) {
|
||||
var olCenter = this.getGMapCenter();
|
||||
|
||||
var gCenter = this.gmap.getCenter();
|
||||
var gZoom = this.gmap.getZoom();
|
||||
|
||||
this.map.setCenter(olCenter, gZoom - 1);
|
||||
var olCenter = this.getOLLonLatFromGLatLng(gCenter);
|
||||
var olZoom = this.getOLZoomFromGZoom(gZoom);
|
||||
|
||||
this.map.setCenter(olCenter, olZoom);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} viewPortPx
|
||||
*
|
||||
* @returns An OpenLayers.LonLat which is the passed-in view port
|
||||
* OpenLayers.Pixel, translated into lon/lat by GMAPS
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
getLonLatFromViewPortPx: function (viewPortPx) {
|
||||
var gPoint = this.getGPointFromOLPixel(viewPortPx);
|
||||
var gLatLng = this.gmap.fromDivPixelToLatLng(gPoint)
|
||||
|
||||
return this.getOLLonLatFromGLatLng(gLatLng);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into view port pixels BY GMAPS
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getViewPortPxFromLonLat: function (lonlat) {
|
||||
var gLatLng = this.getGLatLngFromOLLonLat(lonlat);
|
||||
var gPoint = this.gmap.fromLatLngToDivPixel(gLatLng)
|
||||
|
||||
return this.getOLPixelFromGPoint(gPoint);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @returns An OpenLayers.LonLat with the center of the gmap, or null if
|
||||
* the GMap has not been centered yet
|
||||
* @return {int}
|
||||
*/
|
||||
getZoomForExtent: function (bounds) {
|
||||
var gBounds = this.getGLatLngBoundsFromOLBounds(bounds);
|
||||
var gZoom = this.gmap.getBoundsZoomLevel(gBounds);
|
||||
|
||||
return this.getOLZoomFromGZoom(gZoom);
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||
* current viewPort.
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getExtent: function () {
|
||||
if (this.gmap.getCenter() == null) {
|
||||
this.moveTo();
|
||||
}
|
||||
var gLatLngBounds = this.gmap.getBounds();
|
||||
return this.getOLBoundsFromGLatLngBounds(gLatLngBounds);
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Translation Functions */
|
||||
/* */
|
||||
/* The following functions translate GMaps and OL */
|
||||
/* formats for Pixel, LonLat, Bounds, and Zoom */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
//
|
||||
// TRANSLATION: GZoom <-> OpenLayers Zoom
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {int} gZoom
|
||||
*
|
||||
* @returns An OpenLayers Zoom level, translated from the passed in gZoom
|
||||
* @type int
|
||||
*/
|
||||
getOLZoomFromGZoom: function(gZoom) {
|
||||
return (gZoom - 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {int} olZoom
|
||||
*
|
||||
* @returns A GZoom level, translated from the passed in olZoom
|
||||
* @type int
|
||||
*/
|
||||
getGZoomFromOLZoom: function(olZoom) {
|
||||
return (olZoom + 1);
|
||||
},
|
||||
|
||||
//
|
||||
// TRANSLATION: GLatLng <-> LonLat
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {GLatLng} gLatLng
|
||||
*
|
||||
* @returns An OpenLayers.LonLat, translated from the passed in GLatLng
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
getGMapCenter:function() {
|
||||
var olCenter = null;
|
||||
var gCenter = this.gmap.getCenter();
|
||||
if (gCenter != null) {
|
||||
olCenter = new OpenLayers.LonLat(gCenter.lng(), gCenter.lat());
|
||||
getOLLonLatFromGLatLng: function(gLatLng) {
|
||||
var olLonLat = null;
|
||||
if (gLatLng != null) {
|
||||
olLonLat = new OpenLayers.LonLat(gLatLng.lng(), gLatLng.lat());
|
||||
}
|
||||
return olCenter;
|
||||
return olLonLat;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} olLonLat
|
||||
*
|
||||
* @returns A GLatLng, translated from the passed in OpenLayers.LonLat
|
||||
* @type GLatLng
|
||||
*/
|
||||
getGLatLngFromOLLonLat: function(olLonLat) {
|
||||
var gLatLng = null;
|
||||
if (olLonLat != null) {
|
||||
gLatLng = new GLatLng(olLonLat.lat, olLonLat.lon);
|
||||
}
|
||||
return gLatLng;
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// TRANSLATION: GPoint <-> OpenLayers.Pixel
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {GPoint} gPoint
|
||||
*
|
||||
* @returns An OpenLayers.Pixel, translated from the passed in GPoint
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getOLPixelFromGPoint: function(gPoint) {
|
||||
var olPixel = null;
|
||||
if (gPoint != null) {
|
||||
olPixel = new OpenLayers.Pixel(gPoint.x, gPoint.y);
|
||||
}
|
||||
return olPixel;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} olPixel
|
||||
*
|
||||
* @returns A GPoint, translated from the passed in OpenLayers.Pixel
|
||||
* @type GPoint
|
||||
*/
|
||||
getGPointFromOLPixel: function(olPixel) {
|
||||
var gPoint = null;
|
||||
if (olPixel != null) {
|
||||
gPoint = new GPoint(olPixel.x, olPixel.y);
|
||||
}
|
||||
return gPoint;
|
||||
},
|
||||
|
||||
//
|
||||
// TRANSLATION: GLatLngBounds <-> OpenLayers.Bounds
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {GLatLngBounds} gLatLngBounds
|
||||
*
|
||||
* @returns An OpenLayers.Bounds, translated from gLatLngBounds
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getOLBoundsFromGLatLngBounds: function(gLatLngBounds) {
|
||||
var olBounds = null;
|
||||
if (gLatLngBounds != null) {
|
||||
var sw = gLatLngBounds.getSouthWest();
|
||||
var ne = gLatLngBounds.getNorthEast();
|
||||
olBounds = new OpenLayers.Bounds(sw.lng(),
|
||||
sw.lat(),
|
||||
ne.lng(),
|
||||
ne.lat() );
|
||||
}
|
||||
return olBounds;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} olBounds
|
||||
*
|
||||
* @returns A GLatLngBounds, translated from olBounds
|
||||
* @type GLatLngBounds
|
||||
*/
|
||||
getGLatLngBoundsFromOLBounds: function(olBounds) {
|
||||
var gLatLngBounds = null;
|
||||
if (olBounds != null) {
|
||||
var sw = new GLatLng(olBounds.bottom, olBounds.left);
|
||||
var ne = new GLatLng(olBounds.top, olBounds.right);
|
||||
gLatLngBounds = new GLatLngBounds(sw, ne);
|
||||
}
|
||||
return gLatLngBounds;
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
// @require: OpenLayers/Layer.js
|
||||
// @require: OpenLayers/Util.js
|
||||
OpenLayers.Layer.Grid = Class.create();
|
||||
OpenLayers.Layer.Grid.TILE_WIDTH = 256;
|
||||
OpenLayers.Layer.Grid.TILE_HEIGHT = 256;
|
||||
OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
// str: url
|
||||
@@ -25,17 +23,16 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
* @param {str} name
|
||||
* @param {str} url
|
||||
* @param {hash} params
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name, url, params) {
|
||||
initialize: function(name, url, params, options) {
|
||||
var newArguments = arguments;
|
||||
if (arguments.length > 0) {
|
||||
newArguments = [name];
|
||||
newArguments = [name, options];
|
||||
}
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, newArguments);
|
||||
this.url = url;
|
||||
this.params = params;
|
||||
this.tileSize = new OpenLayers.Size(OpenLayers.Layer.Grid.TILE_WIDTH,
|
||||
OpenLayers.Layer.Grid.TILE_HEIGHT);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -48,18 +45,33 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
OpenLayers.Layer.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/** When the layer is added to a map, then we can ask the map for
|
||||
* its default tile size
|
||||
*
|
||||
* @param {OpenLayers.Map} map
|
||||
*/
|
||||
setMap: function(map) {
|
||||
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
|
||||
if (this.tileSize == null) {
|
||||
this.tileSize = this.map.getTileSize();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated User should just set the 'tileSize' via options
|
||||
*/
|
||||
setTileSize: function (size) {
|
||||
this.tileSize = size.copyOf();
|
||||
},
|
||||
|
||||
/**
|
||||
* moveTo
|
||||
* moveTo is a function called whenever the map is moved. All the moving
|
||||
/** This function is called whenever the map is moved. All the moving
|
||||
* of actual 'tiles' is done by the map, but moveTo's role is to accept
|
||||
* a bounds and make sure the data that that bounds requires is pre-loaded.
|
||||
*
|
||||
* @param {OpenLayers.Bounds}
|
||||
* @param {Boolean} zoomChanged
|
||||
*/
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
moveTo:function(bounds, zoomChanged) {
|
||||
if (!this.getVisibility()) {
|
||||
if (zoomChanged) {
|
||||
this.grid = null;
|
||||
@@ -84,6 +96,8 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
getGridBounds:function() {
|
||||
var topLeftTile = this.grid[0][0];
|
||||
var bottomRightTile = this.grid[this.grid.length-1][this.grid[0].length-1];
|
||||
@@ -106,7 +120,7 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
var viewSize = this.map.getSize();
|
||||
var bounds = this.map.getExtent();
|
||||
var extent = this.map.getFullExtent();
|
||||
var extent = this.map.getMaxExtent();
|
||||
var resolution = this.map.getResolution();
|
||||
var tilelon = resolution*this.tileSize.w;
|
||||
var tilelat = resolution*this.tileSize.h;
|
||||
@@ -236,7 +250,7 @@ OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
*/
|
||||
getFullRequestString:function(params) {
|
||||
var requestString = "";
|
||||
this.params.SRS = this.map.projection;
|
||||
this.params.SRS = this.map.getProjection();
|
||||
// concat tile params with layer params and convert to string
|
||||
var allParams = Object.extend(this.params, params);
|
||||
var paramsString = OpenLayers.Util.getParameterString(allParams);
|
||||
|
||||
@@ -17,8 +17,9 @@ OpenLayers.Layer.Markers.prototype =
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name) {
|
||||
initialize: function(name, options) {
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
|
||||
this.markers = new Array();
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ OpenLayers.Layer.Text = Class.create();
|
||||
OpenLayers.Layer.Text.prototype =
|
||||
Object.extend( new OpenLayers.Layer.Markers(), {
|
||||
|
||||
/** store url of text file
|
||||
/** store url of text file - this should be specified in the "options" hash
|
||||
* @type str */
|
||||
location:null,
|
||||
|
||||
@@ -25,13 +25,15 @@ OpenLayers.Layer.Text.prototype =
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {String} location
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name, location) {
|
||||
OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
|
||||
this.location = location;
|
||||
initialize: function(name, options) {
|
||||
OpenLayers.Layer.Markers.prototype.initialize.apply(this, arguments);
|
||||
this.features = new Array();
|
||||
new Ajax.Request(location,
|
||||
if (this.location != null) {
|
||||
new Ajax.Request(this.location,
|
||||
{ method: 'get', onComplete:this.parseData.bind(this) } );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -43,7 +45,7 @@ OpenLayers.Layer.Text.prototype =
|
||||
OpenLayers.Layer.Markers.prototype.destroy.apply(this, arguments);
|
||||
},
|
||||
|
||||
/** WFS layer is never a base class.
|
||||
/** Text layer is never a base class.
|
||||
* @type Boolean
|
||||
*/
|
||||
isBaseLayer: function() {
|
||||
|
||||
@@ -15,7 +15,7 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
||||
Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
/** @type Boolean */
|
||||
viewPortLayer: true,
|
||||
isFixed: true,
|
||||
|
||||
/** @type VEMap */
|
||||
vemap: null,
|
||||
@@ -48,9 +48,9 @@ OpenLayers.Layer.VirtualEarth.prototype =
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
* @param {int} zoomChanged
|
||||
* @param {Boolean} zoomChanged
|
||||
*/
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
moveTo:function(bounds, zoomChanged) {
|
||||
|
||||
if (this.vemap != null) {
|
||||
var olCenter = this.map.getCenter();
|
||||
|
||||
@@ -11,7 +11,10 @@ OpenLayers.Layer.WFS.prototype =
|
||||
Object.extend(new OpenLayers.Layer.Grid(),
|
||||
Object.extend(new OpenLayers.Layer.Markers(), {
|
||||
|
||||
/** @type Object */
|
||||
/** Allow the user to specify a special class to use to display features.
|
||||
* This allows for easy-definition of feature behaviour. This property
|
||||
* should be set via the "options" parameter.
|
||||
* @type Object */
|
||||
featureClass: OpenLayers.Feature.WFS,
|
||||
|
||||
/** @final @type hash */
|
||||
@@ -27,16 +30,14 @@ OpenLayers.Layer.WFS.prototype =
|
||||
* @param {str} name
|
||||
* @param {str} url
|
||||
* @param {hash} params
|
||||
* @param {Object} featureClass
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name, url, params, featureClass) {
|
||||
if (featureClass != null) this.featureClass = featureClass;
|
||||
|
||||
initialize: function(name, url, params, options) {
|
||||
var newArguments = new Array();
|
||||
if (arguments.length > 0) {
|
||||
//uppercase params
|
||||
params = OpenLayers.Util.upperCaseObject(params);
|
||||
newArguments.push(name, url, params);
|
||||
newArguments.push(name, url, params, options);
|
||||
}
|
||||
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
||||
OpenLayers.Layer.Markers.prototype.initialize.apply(this, newArguments);
|
||||
|
||||
@@ -24,13 +24,14 @@ OpenLayers.Layer.WMS.prototype =
|
||||
* @param {str} name
|
||||
* @param {str} url
|
||||
* @param {hash} params
|
||||
* @param {Object} options Hash of extra options to tag onto the layer
|
||||
*/
|
||||
initialize: function(name, url, params) {
|
||||
initialize: function(name, url, params, options) {
|
||||
var newArguments = new Array();
|
||||
if (arguments.length > 0) {
|
||||
//uppercase params
|
||||
params = OpenLayers.Util.upperCaseObject(params);
|
||||
newArguments.push(name, url, params);
|
||||
newArguments.push(name, url, params, options);
|
||||
}
|
||||
OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
|
||||
|
||||
@@ -43,7 +44,7 @@ OpenLayers.Layer.WMS.prototype =
|
||||
},
|
||||
|
||||
|
||||
/** WFS layer is never a base class.
|
||||
/** WMS layer is never a base class.
|
||||
* @type Boolean
|
||||
*/
|
||||
isBaseLayer: function() {
|
||||
@@ -86,6 +87,49 @@ OpenLayers.Layer.WMS.prototype =
|
||||
url, this.tileSize);
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @returns Degrees per Pixel
|
||||
* @type float
|
||||
*/
|
||||
getResolution: function() {
|
||||
var maxRes = this.map.getMaxResolution();
|
||||
var zoom = this.map.getZoom();
|
||||
|
||||
return maxRes / Math.pow(2, zoom);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @return {int}
|
||||
*/
|
||||
getZoomForExtent: function (bounds) {
|
||||
|
||||
var maxRes = this.map.getMaxResolution();
|
||||
var viewSize = this.map.getSize();
|
||||
|
||||
var width = bounds.getWidth();
|
||||
var height = bounds.getHeight();
|
||||
|
||||
var degPerPixel = (width > height) ? width / viewSize.w
|
||||
: height / viewSize.h;
|
||||
|
||||
var zoom = Math.floor( (Math.log(maxRes/degPerPixel)) / Math.log(2) );
|
||||
|
||||
var maxZoomLevel = this.map.getMaxZoomLevel();
|
||||
var minZoomLevel = this.map.getMinZoomLevel();
|
||||
|
||||
//make sure zoom is within bounds
|
||||
zoom = Math.min( Math.max(zoom, minZoomLevel),
|
||||
maxZoomLevel );
|
||||
|
||||
return zoom;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/** @final @type String */
|
||||
CLASS_NAME: "OpenLayers.Layer.WMS"
|
||||
});
|
||||
|
||||
@@ -13,7 +13,7 @@ OpenLayers.Layer.Yahoo = Class.create();
|
||||
OpenLayers.Layer.Yahoo.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
/** @type Boolean */
|
||||
viewPortLayer: true,
|
||||
isFixed: true,
|
||||
|
||||
/** @type GMap2 gmap stores the Google Map element */
|
||||
ymap:null,
|
||||
@@ -49,9 +49,9 @@ OpenLayers.Layer.Yahoo.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
* @param {int} zoomChanged
|
||||
* @param {Boolean} zoomChanged
|
||||
*/
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
moveTo:function(bounds, zoomChanged) {
|
||||
|
||||
if ((this.ymap != null) && (!this.dragging)) {
|
||||
|
||||
|
||||
@@ -1,79 +1,119 @@
|
||||
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
||||
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
|
||||
* text of the license. */
|
||||
// @require: OpenLayers/Util.js
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
// @require: OpenLayers/Util.js
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
OpenLayers.Map = Class.create();
|
||||
OpenLayers.Map.TILE_WIDTH = 256;
|
||||
OpenLayers.Map.TILE_HEIGHT = 256;
|
||||
OpenLayers.Map.prototype = {
|
||||
// Hash: base z-indexes for different classes of thing
|
||||
|
||||
/** base z-indexes for different classes of thing
|
||||
*
|
||||
* @type Hash
|
||||
*/
|
||||
Z_INDEX_BASE: { Layer: 100, Popup: 200, Control: 1000 },
|
||||
|
||||
// Array: supported application event types
|
||||
/** supported application event types
|
||||
*
|
||||
* @type Array */
|
||||
EVENT_TYPES: [
|
||||
"addlayer", "removelayer", "movestart", "move", "moveend",
|
||||
"zoomend", "layerchanged", "popupopen", "popupclose",
|
||||
"addmarker", "removemarker", "clearmarkers", "mouseover",
|
||||
"mouseout", "mousemove", "dragstart", "drag", "dragend" ],
|
||||
"mouseout", "mousemove", "dragstart", "drag", "dragend",
|
||||
"changebaselayer"],
|
||||
|
||||
// int: zoom levels, used to draw zoom dragging control and limit zooming
|
||||
maxZoomLevel: 16,
|
||||
|
||||
// OpenLayers.Bounds
|
||||
maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
|
||||
|
||||
/* projection */
|
||||
projection: "EPSG:4326",
|
||||
|
||||
/** @type OpenLayers.Size */
|
||||
size: null,
|
||||
|
||||
// float
|
||||
maxResolution: 1.40625, // degrees per pixel
|
||||
// Default is whole world in 256 pixels, from GMaps
|
||||
|
||||
// DOMElement: the div that our map lives in
|
||||
div: null,
|
||||
|
||||
// HTMLDivElement: the map's view port
|
||||
viewPortDiv: null,
|
||||
|
||||
// HTMLDivElement: the map's layer container
|
||||
layerContainerDiv: null,
|
||||
|
||||
// Array(OpenLayers.Layer): ordered list of layers in the map
|
||||
layers: null,
|
||||
|
||||
// Array(OpenLayers.Control)
|
||||
controls: null,
|
||||
|
||||
// Array(OpenLayers.Popup)
|
||||
popups: null,
|
||||
|
||||
// OpenLayers.LonLat
|
||||
center: null,
|
||||
|
||||
// int
|
||||
zoom: null,
|
||||
|
||||
// OpenLayers.Events
|
||||
/** @type OpenLayers.Events */
|
||||
events: null,
|
||||
|
||||
// OpenLayers.Pixel
|
||||
mouseDragStart: null,
|
||||
/** the div that our map lives in
|
||||
*
|
||||
* @type DOMElement */
|
||||
div: null,
|
||||
|
||||
/** @type OpenLayers.Layer */
|
||||
/** Size of the main div (this.div)
|
||||
*
|
||||
* @type OpenLayers.Size */
|
||||
size: null,
|
||||
|
||||
/** @type HTMLDivElement */
|
||||
viewPortDiv: null,
|
||||
|
||||
/** The lonlat at which the later container was re-initialized (on-zoom)
|
||||
* @type OpenLayers.LonLat */
|
||||
layerContainerOrigin: null,
|
||||
|
||||
/** @type HTMLDivElement */
|
||||
layerContainerDiv: null,
|
||||
|
||||
/** ordered list of layers in the map
|
||||
*
|
||||
* @type Array(OpenLayers.Layer)
|
||||
*/
|
||||
layers: null,
|
||||
|
||||
/** @type Array(OpenLayers.Control) */
|
||||
controls: null,
|
||||
|
||||
/** @type Array(OpenLayers.Popup) */
|
||||
popups: null,
|
||||
|
||||
|
||||
|
||||
/** The currently selected base layer - this determines min/max zoom level,
|
||||
* projection, etc.
|
||||
*
|
||||
* @type OpenLayers.Layer */
|
||||
baseLayer: null,
|
||||
|
||||
/** @type OpenLayers.LonLat */
|
||||
center: null,
|
||||
|
||||
/** @type int */
|
||||
zoom: 0,
|
||||
|
||||
/** @type OpenLayers.Pixel */
|
||||
mouseDragStart: null,
|
||||
|
||||
|
||||
// Options
|
||||
|
||||
/** @type String */
|
||||
projection: "EPSG:4326",
|
||||
|
||||
/** @type OpenLayers.Bounds */
|
||||
maxExtent: null,
|
||||
|
||||
/** default max is 360 deg / 256 px, which corresponds to
|
||||
* zoom level 0 on gmaps
|
||||
*
|
||||
* @type float */
|
||||
maxResolution: 1.40625,
|
||||
|
||||
/** @type int */
|
||||
minZoomLevel: 0,
|
||||
|
||||
/** @type int */
|
||||
maxZoomLevel: 16,
|
||||
|
||||
/** @type OpenLayers.Size */
|
||||
tileSize: null,
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {DOMElement} div
|
||||
* @param {Object} options Hash of extra options to tag onto the map
|
||||
*/
|
||||
initialize: function (div, options) {
|
||||
Object.extend(this, options);
|
||||
|
||||
this.setOptions(options);
|
||||
|
||||
this.div = div = $(div);
|
||||
|
||||
@@ -94,12 +134,7 @@ OpenLayers.Map.prototype = {
|
||||
this.events = new OpenLayers.Events(this, div, this.EVENT_TYPES);
|
||||
|
||||
this.updateSize();
|
||||
// make the entire maxExtent fix in zoom level 0 by default
|
||||
if (this.maxResolution == null || this.maxResolution == "auto") {
|
||||
this.maxResolution = Math.max(
|
||||
this.maxExtent.getWidth() / this.size.w,
|
||||
this.maxExtent.getHeight() / this.size.h );
|
||||
}
|
||||
|
||||
// update the internal size register whenever the div is resized
|
||||
this.events.register("resize", this, this.updateSize);
|
||||
|
||||
@@ -114,7 +149,8 @@ OpenLayers.Map.prototype = {
|
||||
this.popups = new Array();
|
||||
|
||||
// always call map.destroy()
|
||||
Event.observe(window, 'unload',
|
||||
Event.observe(window,
|
||||
'unload',
|
||||
this.destroy.bindAsEventListener(this));
|
||||
},
|
||||
|
||||
@@ -136,6 +172,54 @@ OpenLayers.Map.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {Object} options Hash of options to tag to the map
|
||||
*/
|
||||
setOptions: function(options) {
|
||||
|
||||
// Simple-type defaults are set in class definition.
|
||||
// Now set complex-type defaults
|
||||
this.tileSize = new OpenLayers.Size(OpenLayers.Map.TILE_WIDTH,
|
||||
OpenLayers.Map.TILE_HEIGHT);
|
||||
|
||||
this.maxExtent = new OpenLayers.Bounds(-180, -90, 180, 90);
|
||||
|
||||
// now add the options declared by the user
|
||||
// (these will override defaults)
|
||||
Object.extend(this, options);
|
||||
|
||||
// if maxResolution is specified as "auto", calculate it
|
||||
// based on the maxExtent and the viewSize
|
||||
//
|
||||
if (this.maxResolution == "auto") {
|
||||
var maxExtent = this.getMaxExtent();
|
||||
var viewSize = this.map.getSize();
|
||||
this.maxResolution = Math.max(maxExtent.getWidth() / viewSize.w,
|
||||
maxExtent.getHeight() / viewSize.h );
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Size
|
||||
*/
|
||||
getTileSize: function() {
|
||||
return this.tileSize;
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Layers, Controls, Popup Functions */
|
||||
/* */
|
||||
/* The following functions deal with adding and */
|
||||
/* removing Layers, Controls, and Popups */
|
||||
/* to and from the Map */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Layer} layer
|
||||
*/
|
||||
@@ -144,23 +228,35 @@ OpenLayers.Map.prototype = {
|
||||
layer.div.style.overflow = "";
|
||||
layer.div.style.zIndex = this.Z_INDEX_BASE['Layer'] + this.layers.length;
|
||||
|
||||
if (layer.viewPortLayer) {
|
||||
if (layer.isFixed) {
|
||||
this.viewPortDiv.appendChild(layer.div);
|
||||
} else {
|
||||
this.layerContainerDiv.appendChild(layer.div);
|
||||
}
|
||||
this.layers.push(layer);
|
||||
|
||||
this.events.triggerEvent("addlayer");
|
||||
|
||||
// hack hack hack - until we add a more robust layer switcher,
|
||||
// which is able to determine which layers are base layers and
|
||||
// which are not (and put baselayers in a radiobutton group and
|
||||
// other layers in checkboxes) this seems to be the most straight-
|
||||
// forward way of dealing with this.
|
||||
//
|
||||
if (layer.isBaseLayer()) {
|
||||
if ( (this.baseLayer == null) && (layer.isBaseLayer()) ) {
|
||||
this.baseLayer = layer;
|
||||
this.events.triggerEvent("changebaselayer");
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array(OpenLayers.Layer)} layers
|
||||
*/
|
||||
addLayers: function (layers) {
|
||||
for (var i = 0; i < layers.length; i++) {
|
||||
this.addLayer(layers[i]);
|
||||
}
|
||||
this.events.triggerEvent("addlayer");
|
||||
},
|
||||
|
||||
/** Removes a layer from the map by removing its visual element (the
|
||||
@@ -194,15 +290,6 @@ OpenLayers.Map.prototype = {
|
||||
this.events.triggerEvent("removelayer");
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Array(OpenLayers.Layer)} layers
|
||||
*/
|
||||
addLayers: function (layers) {
|
||||
for (var i = 0; i < layers.length; i++) {
|
||||
this.addLayer(layers[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Control} control
|
||||
* @param {OpenLayers.Pixel} px
|
||||
@@ -243,20 +330,14 @@ OpenLayers.Map.prototype = {
|
||||
popup.map = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {float}
|
||||
*/
|
||||
getResolution: function () {
|
||||
// return degrees per pixel
|
||||
return this.maxResolution / Math.pow(2, this.zoom);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {int}
|
||||
*/
|
||||
getZoom: function () {
|
||||
return this.zoom;
|
||||
},
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Container Div Functions */
|
||||
/* */
|
||||
/* The following functions deal with the access to */
|
||||
/* and maintenance of the size of the container div */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @returns {OpenLayers.Size}
|
||||
@@ -284,6 +365,15 @@ OpenLayers.Map.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Zoom, Center, Pan Functions */
|
||||
/* */
|
||||
/* The following functions handle the validation, */
|
||||
/* getting and setting of the Zoom Level and Center */
|
||||
/* as well as the panning of the Map */
|
||||
/* */
|
||||
/********************************************************/
|
||||
/**
|
||||
* @return {OpenLayers.LonLat}
|
||||
*/
|
||||
@@ -291,134 +381,420 @@ OpenLayers.Map.prototype = {
|
||||
return this.center;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.Bounds}
|
||||
* @return {int}
|
||||
*/
|
||||
getExtent: function () {
|
||||
if (this.center) {
|
||||
var res = this.getResolution();
|
||||
var size = this.getSize();
|
||||
var w_deg = size.w * res;
|
||||
var h_deg = size.h * res;
|
||||
return new OpenLayers.Bounds(
|
||||
this.center.lon - w_deg / 2,
|
||||
this.center.lat - h_deg / 2,
|
||||
this.center.lon + w_deg / 2,
|
||||
this.center.lat + h_deg / 2);
|
||||
} else {
|
||||
return null;
|
||||
getZoom: function () {
|
||||
return this.zoom;
|
||||
},
|
||||
|
||||
/** Allows user to pan by a value of screen pixels
|
||||
*
|
||||
* @param {int} dx
|
||||
* @param {int} dy
|
||||
*/
|
||||
pan: function(dx, dy) {
|
||||
|
||||
// getCenter
|
||||
var centerPx = this.getViewPortPxFromLonLat(this.getCenter());
|
||||
|
||||
// adjust
|
||||
var newCenterPx = centerPx.add(dx, dy);
|
||||
|
||||
// only call setCenter if there has been a change
|
||||
if (!newCenterPx.equals(centerPx)) {
|
||||
var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
|
||||
this.setCenter(newCenterLonLat);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
* @param {int} zoom
|
||||
* @param {Boolean} minor Specifies whether or not to
|
||||
* trigger movestart/end events
|
||||
*/
|
||||
setCenter: function (lonlat, zoom, minor) {
|
||||
|
||||
var zoomChanged = (this.isValidZoomLevel(zoom)) &&
|
||||
(zoom != this.getZoom());
|
||||
|
||||
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
||||
(!lonlat.equals(this.center));
|
||||
|
||||
|
||||
// if neither center nor zoom will change, no need to do anything
|
||||
if (zoomChanged || centerChanged) {
|
||||
|
||||
if (!minor) { this.events.triggerEvent("movestart"); }
|
||||
|
||||
if (centerChanged) {
|
||||
if ((!zoomChanged) && (this.center)) {
|
||||
// if zoom hasnt changed, just slide layerContainer
|
||||
// (must be done before setting this.center to new value)
|
||||
this.centerLayerContainer(lonlat);
|
||||
}
|
||||
this.center = lonlat.copyOf();
|
||||
}
|
||||
|
||||
// (re)set the layerContainerDiv's location
|
||||
if ((zoomChanged) || (this.layerContainerOrigin == null)) {
|
||||
this.layerContainerOrigin = this.center.copyOf();
|
||||
this.layerContainerDiv.style.left = "0px";
|
||||
this.layerContainerDiv.style.top = "0px";
|
||||
}
|
||||
|
||||
if (zoomChanged) {
|
||||
this.zoom = zoom;
|
||||
|
||||
//redraw popups
|
||||
for (var i = 0; i < this.popups.length; i++) {
|
||||
this.popups[i].updatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
//send the move call to all the layers
|
||||
var bounds = this.getExtent();
|
||||
for (var i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].moveTo(bounds, zoomChanged);
|
||||
}
|
||||
|
||||
this.events.triggerEvent("move");
|
||||
|
||||
if (zoomChanged) { this.events.triggerEvent("zoomend"); }
|
||||
if (!minor) { this.events.triggerEvent("moveend"); }
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.Bounds}
|
||||
/** This function takes care to recenter the layerContainerDiv
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*/
|
||||
getFullExtent: function () {
|
||||
return this.maxExtent;
|
||||
centerLayerContainer: function (lonlat) {
|
||||
|
||||
var originPx = this.getViewPortPxFromLonLat(this.layerContainerOrigin);
|
||||
var newPx = this.getViewPortPxFromLonLat(lonlat);
|
||||
|
||||
this.layerContainerDiv.style.left = (originPx.x - newPx.x) + "px";
|
||||
this.layerContainerDiv.style.top = (originPx.y - newPx.y) + "px";
|
||||
},
|
||||
|
||||
getZoomLevels: function() {
|
||||
return this.maxZoomLevel;
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {int} zoomLevel
|
||||
*
|
||||
* @returns Whether or not the zoom level passed in is non-null and
|
||||
* within the min/max range of zoom levels.
|
||||
* @type Boolean
|
||||
*/
|
||||
isValidZoomLevel: function(zoomLevel) {
|
||||
return ( (zoomLevel != null) &&
|
||||
(zoomLevel >= this.getMinZoomLevel()) &&
|
||||
(zoomLevel <= this.getMaxZoomLevel()) );
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns Whether or not the lonlat passed in is non-null and within
|
||||
* the maxExtent bounds
|
||||
*
|
||||
* @type Boolean
|
||||
*/
|
||||
isValidLonLat: function(lonlat) {
|
||||
var valid = false;
|
||||
if (lonlat != null) {
|
||||
var maxExtent = this.getMaxExtent();
|
||||
valid = maxExtent.contains(lonlat.lon, lonlat.lat);
|
||||
}
|
||||
return valid;
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Layer Options */
|
||||
/* */
|
||||
/* Accessor functions to Layer Options parameters */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @returns The Projection of the base layer
|
||||
* @type String
|
||||
*/
|
||||
getProjection: function() {
|
||||
var projection = this.baseLayer.getProjection();
|
||||
|
||||
if (projection == null) {
|
||||
projection = this.projection;
|
||||
}
|
||||
|
||||
return projection;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The Map's Maximum Resolution
|
||||
* @type String
|
||||
*/
|
||||
getMaxResolution: function() {
|
||||
var maxResolution = this.baseLayer.getMaxResolution();
|
||||
|
||||
if (maxResolution == null) {
|
||||
maxResolution = this.maxResolution;
|
||||
}
|
||||
|
||||
return maxResolution;
|
||||
},
|
||||
|
||||
/**
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getMaxExtent: function () {
|
||||
var maxExtent = this.baseLayer.getMaxExtent();
|
||||
|
||||
if (maxExtent == null) {
|
||||
maxExtent = this.maxExtent;
|
||||
}
|
||||
|
||||
return maxExtent;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The maximum zoom level that can be reached in the map
|
||||
* @type int
|
||||
*/
|
||||
getMaxZoomLevel: function() {
|
||||
var maxZoomLevel = this.baseLayer.getMaxZoomLevel();
|
||||
if (maxZoomLevel == null) {
|
||||
maxZoomLevel = this.maxZoomLevel;
|
||||
}
|
||||
return maxZoomLevel;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns The minimum zoom level that can be reached in the map
|
||||
* @type int
|
||||
*/
|
||||
getMinZoomLevel: function() {
|
||||
var minZoomLevel = this.baseLayer.getMinZoomLevel();
|
||||
if (minZoomLevel == null) {
|
||||
minZoomLevel = this.minZoomLevel;
|
||||
}
|
||||
return minZoomLevel;
|
||||
},
|
||||
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Baselayer Functions */
|
||||
/* */
|
||||
/* The following functions, all publicly exposed */
|
||||
/* in the API?, are all merely wrappers to the */
|
||||
/* the same calls on whatever layer is set as */
|
||||
/* the current base layer */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/**
|
||||
* @returns A Bounds object which represents the lon/lat bounds of the
|
||||
* current viewPort.
|
||||
* @type OpenLayers.Bounds
|
||||
*/
|
||||
getExtent: function () {
|
||||
return this.baseLayer.getExtent();
|
||||
},
|
||||
|
||||
/**
|
||||
* @type float
|
||||
*/
|
||||
getResolution: function () {
|
||||
return this.baseLayer.getResolution();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @return {int}
|
||||
* @type int
|
||||
*/
|
||||
getZoomForExtent: function (bounds) {
|
||||
var size = this.getSize();
|
||||
var width = bounds.getWidth();
|
||||
var height = bounds.getHeight();
|
||||
var deg_per_pixel = (width > height ? width / size.w : height / size.h);
|
||||
var zoom = Math.log(this.maxResolution / deg_per_pixel) / Math.log(2);
|
||||
return Math.floor(Math.min(Math.max(zoom, 0), this.getZoomLevels()));
|
||||
return this.baseLayer.getZoomForExtent(bounds);
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Zooming Functions */
|
||||
/* */
|
||||
/* The following functions, all publicly exposed */
|
||||
/* in the API, are all merely wrappers to the */
|
||||
/* the setCenter() function */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
/** Zoom to a specific zoom level
|
||||
*
|
||||
* @param {int} zoom
|
||||
*/
|
||||
zoomTo: function(zoom) {
|
||||
this.setCenter(null, zoom);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} layerPx
|
||||
*
|
||||
* @returns px translated into view port pixel coordinates
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
* @param {int} zoom
|
||||
*/
|
||||
getViewPortPxFromLayerPx:function(layerPx) {
|
||||
var viewPortPx = layerPx.copyOf();
|
||||
|
||||
viewPortPx.x += parseInt(this.layerContainerDiv.style.left);
|
||||
viewPortPx.y += parseInt(this.layerContainerDiv.style.top);
|
||||
|
||||
return viewPortPx;
|
||||
zoomIn: function() {
|
||||
this.zoomTo(this.getZoom() + 1);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} viewPortPx
|
||||
*
|
||||
* @returns px translated into view port pixel coordinates
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
* @param {int} zoom
|
||||
*/
|
||||
getLayerPxFromViewPortPx:function(viewPortPx) {
|
||||
var layerPx = viewPortPx.copyOf();
|
||||
|
||||
layerPx.x -= parseInt(this.layerContainerDiv.style.left);
|
||||
layerPx.y -= parseInt(this.layerContainerDiv.style.top);
|
||||
|
||||
return layerPx;
|
||||
zoomOut: function() {
|
||||
this.zoomTo(this.getZoom() - 1);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} px
|
||||
/** Zoom to the passed in bounds, recenter
|
||||
*
|
||||
* @return {OpenLayers.LonLat}
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*/
|
||||
getLonLatFromLayerPx: function (px) {
|
||||
//adjust for displacement of layerContainerDiv
|
||||
px = this.getViewPortPxFromLayerPx(px);
|
||||
return this.getLonLatFromViewPortPx(px);
|
||||
zoomToExtent: function(bounds) {
|
||||
this.setCenter(bounds.getCenterLonLat(),
|
||||
this.getZoomForExtent(bounds));
|
||||
},
|
||||
|
||||
/** Zoom to the full extent and recenter.
|
||||
*/
|
||||
zoomToMaxExtent: function() {
|
||||
this.zoomToExtent(this.getMaxExtent());
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
/* */
|
||||
/* Translation Functions */
|
||||
/* */
|
||||
/* The following functions translate between */
|
||||
/* LonLat, LayerPx, and ViewPortPx */
|
||||
/* */
|
||||
/********************************************************/
|
||||
|
||||
//
|
||||
// TRANSLATION: LonLat <-> ViewPortPx
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} viewPortPx
|
||||
*
|
||||
* @returns An OpenLayers.LonLat which is the passed-in view port
|
||||
* OpenLayers.Pixel, translated into lon/lat given the
|
||||
* current extent and resolution
|
||||
* OpenLayers.Pixel, translated into lon/lat by the
|
||||
* current base layer
|
||||
* @type OpenLayers.LonLat
|
||||
* @private
|
||||
*/
|
||||
getLonLatFromViewPortPx: function (viewPortPx) {
|
||||
var center = this.getCenter(); //map center lon/lat
|
||||
var res = this.getResolution();
|
||||
var size = this.getSize();
|
||||
|
||||
var delta_x = viewPortPx.x - (size.w / 2);
|
||||
var delta_y = viewPortPx.y - (size.h / 2);
|
||||
|
||||
return new OpenLayers.LonLat(center.lon + delta_x * res ,
|
||||
center.lat - delta_y * res);
|
||||
return this.baseLayer.getLonLatFromViewPortPx(viewPortPx);
|
||||
},
|
||||
|
||||
// getLonLatFromPixel is a convenience function for the API
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into view port pixels by the
|
||||
* current base layer
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
*/
|
||||
getViewPortPxFromLonLat: function (lonlat) {
|
||||
return this.baseLayer.getViewPortPxFromLonLat(lonlat);
|
||||
},
|
||||
|
||||
|
||||
//
|
||||
// CONVENIENCE TRANSLATION FUNCTIONS FOR API
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} pixel
|
||||
*
|
||||
* @returns An OpenLayers.LonLat corresponding to the given
|
||||
* OpenLayers.Pixel, translated into lon/lat using the
|
||||
* current extent and resolution
|
||||
* OpenLayers.Pixel, translated into lon/lat by the
|
||||
* current base layer
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
getLonLatFromPixel: function (px) {
|
||||
return this.getLonLatFromViewPortPx(px);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel corresponding to the OpenLayers.LonLat
|
||||
* translated into view port pixels by the
|
||||
* current base layer
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getPixelFromLonLat: function (lonlat) {
|
||||
return this.getViewPortPxFromLonLat(lonlat);
|
||||
},
|
||||
|
||||
|
||||
|
||||
//
|
||||
// TRANSLATION: ViewPortPx <-> LayerPx
|
||||
//
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {OpenLayers.Pixel} layerPx
|
||||
*
|
||||
* @returns Layer Pixel translated into ViewPort Pixel coordinates
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getViewPortPxFromLayerPx:function(layerPx) {
|
||||
return layerPx.add(parseInt(this.layerContainerDiv.style.left),
|
||||
parseInt(this.layerContainerDiv.style.top) );
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {OpenLayers.Pixel} viewPortPx
|
||||
*
|
||||
* @returns ViewPort Pixel translated into Layer Pixel coordinates
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getLayerPxFromViewPortPx:function(viewPortPx) {
|
||||
return viewPortPx.add(-parseInt(this.layerContainerDiv.style.left),
|
||||
-parseInt(this.layerContainerDiv.style.top));
|
||||
},
|
||||
|
||||
//
|
||||
// TRANSLATION: LonLat <-> LayerPx
|
||||
//
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} px
|
||||
*
|
||||
* @type OpenLayers.LonLat
|
||||
*/
|
||||
getLonLatFromLayerPx: function (px) {
|
||||
//adjust for displacement of layerContainerDiv
|
||||
px = this.getViewPortPxFromLayerPx(px);
|
||||
return this.getLonLatFromViewPortPx(px);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into layer pixels given the current extent
|
||||
* and resolution
|
||||
* translated into layer pixels by the current base layer
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getLayerPxFromLonLat: function (lonlat) {
|
||||
@@ -427,154 +803,6 @@ OpenLayers.Map.prototype = {
|
||||
return this.getLayerPxFromViewPortPx(px);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
|
||||
* translated into view port pixels given the current extent
|
||||
* and resolution
|
||||
* @type OpenLayers.Pixel
|
||||
* @private
|
||||
*/
|
||||
getViewPortPxFromLonLat: function (lonlat) {
|
||||
var resolution = this.getResolution();
|
||||
var extent = this.getExtent();
|
||||
return new OpenLayers.Pixel(
|
||||
Math.round(1/resolution * (lonlat.lon - extent.left)),
|
||||
Math.round(1/resolution * (extent.top - lonlat.lat))
|
||||
);
|
||||
},
|
||||
|
||||
// getLonLatFromPixel is a convenience function for the API
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
*
|
||||
* @returns An OpenLayers.Pixel corresponding to the OpenLayers.LonLat
|
||||
* translated into view port pixels using the current extent
|
||||
* and resolution
|
||||
* @type OpenLayers.Pixel
|
||||
*/
|
||||
getPixelFromLonLat: function (lonlat) {
|
||||
return this.getViewPortPxFromLonLat(lonlat);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
* @param {int} zoom
|
||||
*/
|
||||
setCenter: function (lonlat, zoom, minor) {
|
||||
if (this.center) { // otherwise there's nothing to move yet
|
||||
this.moveLayerContainer(lonlat);
|
||||
}
|
||||
this.center = lonlat.copyOf();
|
||||
var zoomChanged = null;
|
||||
if (zoom != null && zoom != this.zoom
|
||||
&& zoom >= 0 && zoom <= this.getZoomLevels()) {
|
||||
zoomChanged = (this.zoom == null ? 0 : this.zoom);
|
||||
this.zoom = zoom;
|
||||
}
|
||||
|
||||
if (!minor) this.events.triggerEvent("movestart");
|
||||
this.moveToNewExtent(zoomChanged, minor);
|
||||
if (!minor) this.events.triggerEvent("moveend");
|
||||
},
|
||||
|
||||
/**
|
||||
* ZOOM TO BOUNDS FUNCTION
|
||||
* @private
|
||||
*/
|
||||
moveToNewExtent: function (zoomChanged, minor) {
|
||||
if (zoomChanged != null) { // reset the layerContainerDiv's location
|
||||
this.layerContainerDiv.style.left = "0px";
|
||||
this.layerContainerDiv.style.top = "0px";
|
||||
|
||||
//redraw popups
|
||||
for (var i = 0; i < this.popups.length; i++) {
|
||||
this.popups[i].updatePosition();
|
||||
}
|
||||
|
||||
}
|
||||
var bounds = this.getExtent();
|
||||
for (var i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].moveTo(bounds, (zoomChanged != null), minor);
|
||||
}
|
||||
this.events.triggerEvent("move");
|
||||
if (zoomChanged != null)
|
||||
this.events.triggerEvent("zoomend",
|
||||
{oldZoom: zoomChanged, newZoom: this.zoom});
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomIn
|
||||
* Increase zoom level by one.
|
||||
* @param {int} zoom
|
||||
*/
|
||||
zoomIn: function() {
|
||||
if (this.zoom != null && this.zoom <= this.getZoomLevels()) {
|
||||
this.zoomTo( this.zoom += 1 );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomTo
|
||||
* Set Zoom To int
|
||||
* @param {int} zoom
|
||||
*/
|
||||
zoomTo: function(zoom) {
|
||||
if (zoom >= 0 && zoom <= this.getZoomLevels()) {
|
||||
var oldZoom = this.zoom;
|
||||
this.zoom = zoom;
|
||||
this.moveToNewExtent(oldZoom);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomOut
|
||||
* Decrease zoom level by one.
|
||||
* @param {int} zoom
|
||||
*/
|
||||
zoomOut: function() {
|
||||
if (this.zoom != null && this.zoom > 0) {
|
||||
this.zoomTo( this.zoom - 1 );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomToFullExtent
|
||||
* Zoom to the full extent and recenter.
|
||||
*/
|
||||
zoomToFullExtent: function() {
|
||||
var fullExtent = this.getFullExtent();
|
||||
this.setCenter(fullExtent.getCenterLonLat(),
|
||||
this.getZoomForExtent(fullExtent)
|
||||
);
|
||||
},
|
||||
|
||||
zoomToExtent: function(bounds) {
|
||||
this.setCenter(
|
||||
new OpenLayers.LonLat((bounds.left+bounds.right)/2,
|
||||
(bounds.bottom+bounds.top)/2),
|
||||
this.getZoomForExtent(bounds)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LonLat} lonlat
|
||||
* @private
|
||||
*/
|
||||
moveLayerContainer: function (lonlat) {
|
||||
var container = this.layerContainerDiv;
|
||||
var resolution = this.getResolution();
|
||||
|
||||
var deltaX = Math.round((this.center.lon - lonlat.lon) / resolution);
|
||||
var deltaY = Math.round((this.center.lat - lonlat.lat) / resolution);
|
||||
|
||||
var offsetLeft = parseInt(container.style.left);
|
||||
var offsetTop = parseInt(container.style.top);
|
||||
|
||||
container.style.left = (offsetLeft + deltaX) + "px";
|
||||
container.style.top = (offsetTop - deltaY) + "px";
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Map"
|
||||
};
|
||||
@@ -30,25 +30,35 @@
|
||||
t.plan( 7 );
|
||||
var evt = {which: 1}; // control expects left-click
|
||||
map = new OpenLayers.Map('map');
|
||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(layer);
|
||||
|
||||
control = new OpenLayers.Control.PanZoom();
|
||||
map.addControl(control,
|
||||
new OpenLayers.Pixel(20,20));
|
||||
map.setCenter(new OpenLayers.LonLat(0,0), 4);
|
||||
var res = map.getResolution();
|
||||
map.addControl(control, new OpenLayers.Pixel(20,20));
|
||||
|
||||
var centerLL = new OpenLayers.LonLat(0,0);
|
||||
map.setCenter(centerLL, 5);
|
||||
|
||||
control.buttons[0].onmousedown(evt);
|
||||
t.eq( map.getCenter().lat, res*50, "Pan up works correctly" );
|
||||
t.ok( map.getCenter().lat > centerLL.lat, "Pan up works correctly" );
|
||||
|
||||
control.buttons[1].onmousedown(evt);
|
||||
t.eq( map.getCenter().lon, res*-50, "Pan left works correctly" );
|
||||
t.ok( map.getCenter().lon < centerLL.lon, "Pan left works correctly" );
|
||||
|
||||
control.buttons[2].onmousedown(evt);
|
||||
t.eq( map.getCenter().lon, 0, "Pan right works correctly" );
|
||||
t.ok( map.getCenter().lon == centerLL.lon, "Pan right works correctly" );
|
||||
|
||||
control.buttons[3].onmousedown(evt);
|
||||
t.eq( map.getCenter().lat, 0, "Pan down works correctly" );
|
||||
control.buttons[4].onmousedown(evt);
|
||||
t.ok( map.getCenter().lat == centerLL.lat, "Pan down works correctly" );
|
||||
|
||||
control.buttons[4].onmousedown(evt);
|
||||
t.eq( map.getZoom(), 6, "zoomin works correctly" );
|
||||
|
||||
control.buttons[6].onmousedown(evt);
|
||||
t.eq( map.getZoom(), 5, "zoomout works correctly" );
|
||||
control.buttons[4].onmousedown(evt);
|
||||
|
||||
control.buttons[5].onmousedown(evt);
|
||||
t.eq( map.getZoom(), 2, "zoomworld works correctly" );
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
function test_02_Control_PanZoomBar_addControl (t) {
|
||||
t.plan( 8 );
|
||||
map = new OpenLayers.Map('map', {controls:[]});
|
||||
var layer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(layer);
|
||||
control = new OpenLayers.Control.PanZoomBar();
|
||||
t.ok( control instanceof OpenLayers.Control.PanZoomBar, "new OpenLayers.Control.PanZoomBar returns object" );
|
||||
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map creates map" );
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
function test_01_Layer_Text_constructor (t) {
|
||||
t.plan( 6 );
|
||||
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', 'data_Layer_Text_textfile.txt');
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
|
||||
t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
|
||||
t.eq( layer.location, "data_Layer_Text_textfile.txt", "layer.location is correct" );
|
||||
var markers;
|
||||
@@ -22,11 +22,15 @@
|
||||
function test_02_Layer_Text_draw (t) {
|
||||
// t.plan(5);
|
||||
t.plan( 2 );
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', 'data_Layer_Text_textfile.txt');
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
|
||||
t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
|
||||
var map = new OpenLayers.Map('map');
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
map.addLayer(layer);
|
||||
t.eq( map.layers[0].name, layer.name, "Layer added to map okay" );
|
||||
t.eq( map.layers[1].name, layer.name, "Layer added to map okay" );
|
||||
t.delay_call( 1, function() {
|
||||
map.setCenter(new OpenLayers.LonLat(0,0),0);
|
||||
|
||||
@@ -43,8 +47,12 @@
|
||||
}
|
||||
function test_03_Layer_Text_events (t) {
|
||||
t.plan( 4 );
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', 'data_Layer_Text_textfile.txt');
|
||||
layer = new OpenLayers.Layer.Text('Test Layer', { location: 'data_Layer_Text_textfile.txt'});
|
||||
var map = new OpenLayers.Map('map');
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0,0),0);
|
||||
var event = {};
|
||||
|
||||
@@ -5,9 +5,14 @@
|
||||
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||
var map;
|
||||
function test_01_Map_constructor (t) {
|
||||
t.plan( 10 );
|
||||
t.plan( 9 );
|
||||
|
||||
map = new OpenLayers.Map('map'); // no longer need to call $(), constructor does it
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
|
||||
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map returns object" );
|
||||
if (!isMozilla) {
|
||||
t.ok( true, "skipping element test outside of Mozilla");
|
||||
@@ -21,17 +26,19 @@
|
||||
t.ok( map.layers instanceof Array, "map.layers is an Array" );
|
||||
t.ok( map.controls instanceof Array, "map.controls is an Array" );
|
||||
t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );
|
||||
t.ok( map.maxExtent instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
|
||||
t.ok( map.maxZoomLevel > 0, "map.maxZoomLevel is set" );
|
||||
t.ok( map.maxResolution > 0, "map.maxResolution is set" );
|
||||
t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );
|
||||
t.ok( map.getMaxZoomLevel() > 0, "map.maxZoomLevel is set" );
|
||||
}
|
||||
function test_02_Map_center(t) {
|
||||
t.plan(5);
|
||||
t.plan(4);
|
||||
map = new OpenLayers.Map($('map'));
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
map.setCenter(new OpenLayers.LonLat(2,1), 0);
|
||||
t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat");
|
||||
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter");
|
||||
t.eq( map.getResolution(), map.maxResolution, "map.getResolution() == map.maxResolution");
|
||||
t.eq( map.getCenter().lon, 2, "map center lon is correct after calling setCenter");
|
||||
t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter");
|
||||
}
|
||||
@@ -59,8 +66,12 @@
|
||||
t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hash" );
|
||||
}
|
||||
function test_05_Map_center(t) {
|
||||
t.plan(7);
|
||||
t.plan(5);
|
||||
map = new OpenLayers.Map($('map'));
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"} );
|
||||
map.addLayer(baseLayer);
|
||||
map.setCenter(new OpenLayers.LonLat(2, 1), 0);
|
||||
map.zoomIn();
|
||||
t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in");
|
||||
@@ -68,18 +79,26 @@
|
||||
t.eq( map.getCenter().lat, 1, "map center lat is correct after calling setCenter,zoom in");
|
||||
map.zoomOut();
|
||||
t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out");
|
||||
|
||||
map.zoomTo(5);
|
||||
t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" );
|
||||
map.zoomToFullExtent();
|
||||
/**
|
||||
map.zoomToMaxExtent();
|
||||
t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToFullExtent" );
|
||||
var lonlat = map.getCenter();
|
||||
var zero = new OpenLayers.LonLat(0, 0);
|
||||
t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" );
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
function test_06_Map_zoomend_event (t) {
|
||||
t.plan(3);
|
||||
t.plan(2);
|
||||
map = new OpenLayers.Map('map');
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
map.events.register("zoomend", {count: 0}, function() {
|
||||
this.count++;
|
||||
t.ok(true, "zoomend event was triggered " + this.count + " times");
|
||||
@@ -93,6 +112,10 @@
|
||||
t.plan(4);
|
||||
|
||||
map = new OpenLayers.Map('map');
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
|
||||
var popup = new OpenLayers.Popup("chicken",
|
||||
new OpenLayers.LonLat(0,0),
|
||||
@@ -127,9 +150,16 @@
|
||||
t.ok(!found, "popup.div successfully removed from the map's viewPort");
|
||||
}
|
||||
|
||||
/*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.
|
||||
* Also, it won't work until we figure out the viewSize bug
|
||||
|
||||
function test_08_Map_px_lonlat_translation (t) {
|
||||
t.plan( 6 );
|
||||
map = new OpenLayers.Map($('map'));
|
||||
var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv?",
|
||||
{map: "/mapdata/vmap_wms.map", layers: "basic"});
|
||||
map.addLayer(baseLayer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
|
||||
var pixel = new OpenLayers.Pixel(50,150);
|
||||
@@ -153,6 +183,20 @@
|
||||
|
||||
t.ok( newPixel.equals(pixel), "2nd translation to pixel and back to lonlat is consistent");
|
||||
}
|
||||
*/
|
||||
function test_09_Map_isValidLonLat(t) {
|
||||
t.plan( 3 );
|
||||
map = new OpenLayers.Map($('map'));
|
||||
layer = new OpenLayers.Layer.WMS('Test Layer',
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv",
|
||||
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},
|
||||
{maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );
|
||||
map.addLayer(layer);
|
||||
|
||||
t.ok( !map.isValidLonLat(null), "null lonlat is not valid" );
|
||||
t.ok( map.isValidLonLat(new OpenLayers.LonLat(33862, 717606)), "lonlat outside max extent is valid" );
|
||||
t.ok( !map.isValidLonLat(new OpenLayers.LonLat(10, 10)), "lonlat outside max extent is not valid" );
|
||||
}
|
||||
|
||||
function test_99_Map_destroy (t) {
|
||||
t.plan( 2 );
|
||||
|
||||
Reference in New Issue
Block a user