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:
euzuro
2006-06-27 23:16:26 +00:00
parent 63bd624827
commit ff0e83d0a0
24 changed files with 1262 additions and 467 deletions

View File

@@ -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'} );

View File

@@ -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>

View File

@@ -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());

View File

@@ -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());

View File

@@ -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
View 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>

View File

@@ -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 */

View File

@@ -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);
},

View File

@@ -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";
},

View File

@@ -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);
},
/**

View File

@@ -13,17 +13,43 @@ OpenLayers.Layer.prototype = {
/** @type DOMElement */
div: null,
/** This variable is set in map.addLayer, not within the layer itself
* @type OpenLayers.Map */
/** 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.
//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"
};

View File

@@ -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();
var gZoom = this.gmap.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;
},

View File

@@ -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);

View File

@@ -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();
},

View File

@@ -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,16 +25,18 @@ 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,
{ method: 'get', onComplete:this.parseData.bind(this) } );
if (this.location != null) {
new Ajax.Request(this.location,
{ method: 'get', onComplete:this.parseData.bind(this) } );
}
},
/**
/**
*
*/
destroy: function() {
@@ -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() {

View File

@@ -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();

View File

@@ -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);

View File

@@ -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"
});

View File

@@ -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)) {

File diff suppressed because it is too large Load Diff

View File

@@ -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" );

View File

@@ -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" );

View File

@@ -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 = {};

View File

@@ -5,10 +5,15 @@
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
t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map returns object" );
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");
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 );