Importing OpenLayers "newAPI" branch.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@2 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
41
example.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<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;
|
||||
background-color: red;
|
||||
}
|
||||
</style>
|
||||
<!--
|
||||
<script src="js/3rd/prototype.js" ></script>
|
||||
<script src="js/3rd/logger.js" ></script>
|
||||
<script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAmQ3udCHPQVB_9T_edFZ7YRTcPsh3Vei3pvv-O2gjJ-8oYrRtdhQUNNh-FlqSqbWQTvBoeGLmUYa5EQ" type="text/javascript"></script>
|
||||
-->
|
||||
<script src="js/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var lat = 40;
|
||||
var lon = 5;
|
||||
var zoom = 5;
|
||||
var map, layer;
|
||||
|
||||
function init(){
|
||||
map = new OpenLayers.Map( $('map') );
|
||||
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://octo.metacarta.com/cgi-bin/mapserv",
|
||||
{map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'} );
|
||||
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LatLon(lat, lon), zoom);
|
||||
}
|
||||
-->
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1>OpenLayers Example</h1>
|
||||
<div id="map"></div>
|
||||
</body>
|
||||
</html>
|
||||
BIN
img/east-mini.png
Normal file
|
After Width: | Height: | Size: 451 B |
BIN
img/north-mini.png
Normal file
|
After Width: | Height: | Size: 484 B |
BIN
img/south-mini.png
Normal file
|
After Width: | Height: | Size: 481 B |
BIN
img/west-mini.png
Normal file
|
After Width: | Height: | Size: 453 B |
BIN
img/zoom-minus-mini.png
Normal file
|
After Width: | Height: | Size: 359 B |
BIN
img/zoom-plus-mini.png
Normal file
|
After Width: | Height: | Size: 489 B |
BIN
img/zoom-world-mini.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
65
js/OpenLayers.js
Normal file
@@ -0,0 +1,65 @@
|
||||
// @requires core/application.js
|
||||
|
||||
////
|
||||
/// This blob sucks in all the files in uncompressed form for ease of use
|
||||
///
|
||||
|
||||
/** HACK HACK HACK
|
||||
* this function is basically duplicated in api.js
|
||||
*
|
||||
* @return {str}
|
||||
*/
|
||||
|
||||
OpenLayers = new Object();
|
||||
OpenLayers._scriptName = "js/OpenLayers.js";
|
||||
OpenLayers._getScriptLocation = function () {
|
||||
var scriptLocation = "";
|
||||
var SCRIPT_NAME = OpenLayers._scriptName;
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
var src = scripts[i].getAttribute('src');
|
||||
if (src) {
|
||||
var index = src.lastIndexOf(SCRIPT_NAME);
|
||||
// is it found, at the end of the URL?
|
||||
if ((index > -1) && (index + SCRIPT_NAME.length == src.length)) {
|
||||
scriptLocation = src.slice(0, -SCRIPT_NAME.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scriptLocation;
|
||||
}
|
||||
|
||||
try{new OpenLayers.Map();}
|
||||
catch(e){
|
||||
var jsfiles=new Array(
|
||||
"Prototype.js",
|
||||
"OpenLayers/Util.js",
|
||||
"OpenLayers/Events.js",
|
||||
"OpenLayers/Map.js",
|
||||
"OpenLayers/Layer.js",
|
||||
"OpenLayers/Tile.js",
|
||||
"OpenLayers/Tile/Image.js",
|
||||
"OpenLayers/Layer/Grid.js",
|
||||
"OpenLayers/Layer/WMS.js",
|
||||
"OpenLayers/Control.js",
|
||||
"OpenLayers/Control/PanZoom.js"
|
||||
); // etc.
|
||||
|
||||
var allScriptTags = "";
|
||||
var host = OpenLayers._getScriptLocation() + "js/";
|
||||
|
||||
// check to see if prototype.js was already loaded
|
||||
// if so, skip the first dynamic include
|
||||
//
|
||||
var start=1;
|
||||
try { x = Prototype; }
|
||||
catch (e) { start=0; }
|
||||
|
||||
for (var i = start; i < jsfiles.length; i++) {
|
||||
var currentScriptTag = "<script src='" + host + jsfiles[i] + "'></script>";
|
||||
allScriptTags += currentScriptTag;
|
||||
}
|
||||
document.write(allScriptTags);
|
||||
};
|
||||
22
js/OpenLayers/Control.js
Normal file
@@ -0,0 +1,22 @@
|
||||
OpenLayers.Control = Class.create();
|
||||
OpenLayers.Control.prototype = {
|
||||
// OpenLayers.Map
|
||||
map: null,
|
||||
|
||||
// HTMLDivElement
|
||||
div: null,
|
||||
|
||||
initialize: function () {},
|
||||
|
||||
draw: function () {
|
||||
if (this.div == null) {
|
||||
this.div = OpenLayers.Util.createDiv();
|
||||
}
|
||||
return this.div;
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
// eliminate circular references
|
||||
this.map = null;
|
||||
}
|
||||
};
|
||||
107
js/OpenLayers/Control/PanZoom.js
Normal file
@@ -0,0 +1,107 @@
|
||||
// @require: core/util.js
|
||||
// @require: core/alphaImage.js
|
||||
|
||||
//
|
||||
// default zoom/pan controls
|
||||
//
|
||||
OpenLayers.Control.PanZoom = Class.create();
|
||||
OpenLayers.Control.PanZoom.prototype =
|
||||
Object.extend( new OpenLayers.Control(), {
|
||||
// Array(...)
|
||||
buttons: null,
|
||||
|
||||
initialize: function() {
|
||||
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
draw: function() {
|
||||
// initialize our internal div
|
||||
OpenLayers.Control.prototype.draw.apply(this);
|
||||
|
||||
// place the controls
|
||||
this.buttons = new Array();
|
||||
|
||||
var sz = new OpenLayers.Size(18,18);
|
||||
var xy = new OpenLayers.Point(4,4);
|
||||
var centered = new OpenLayers.Point(xy.x+sz.w/2, xy.y);
|
||||
|
||||
this._addButton("panup", "north-mini.png", centered, sz);
|
||||
xy.y = centered.y+sz.h;
|
||||
this._addButton("panleft", "west-mini.png", xy, sz);
|
||||
this._addButton("panright", "east-mini.png", xy.addX(sz.w), sz);
|
||||
this._addButton("pandown", "south-mini.png", centered.addY(sz.h*2), sz);
|
||||
this._addButton("zoomin", "zoom-plus-mini.png", centered.addY(sz.h*3), sz);
|
||||
this._addButton("zoomextents", "zoom-world-mini.png", centered.addY(sz.h*4), sz);
|
||||
this._addButton("zoomout", "zoom-minus-mini.png", centered.addY(sz.h*5), sz);
|
||||
return this.div;
|
||||
},
|
||||
|
||||
_addButton:function(id, img, xy, sz) {
|
||||
var imgLocation = OpenLayers.Util.getImagesLocation() + img;
|
||||
// var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz);
|
||||
var btn = OpenLayers.Util.createImage(
|
||||
imgLocation, sz, xy, "absolute",
|
||||
"OpenLayers_Control_PanZoom_" + id );
|
||||
|
||||
//we want to add the outer div
|
||||
this.div.appendChild(btn);
|
||||
|
||||
btn.onmousedown = this.buttonDown.bindAsEventListener(btn);
|
||||
btn.ondblclick = this.doubleClick.bindAsEventListener(btn);
|
||||
btn.action = id;
|
||||
btn.map = this.map;
|
||||
|
||||
//we want to remember/reference the outer div
|
||||
this.buttons.push(btn);
|
||||
return btn;
|
||||
},
|
||||
|
||||
doubleClick: function (evt) {
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
buttonDown: function (evt) {
|
||||
switch (this.action) {
|
||||
case "panup":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat + (reslution * 50),
|
||||
center.lon
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "pandown":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat - (reslution * 50),
|
||||
center.lon
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "panleft":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat,
|
||||
center.lon - (resolution * 50)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "panright":
|
||||
var resolution = this.map.getResolution();
|
||||
var center = this.map.getCenter();
|
||||
this.map.setCenter(
|
||||
new OpenLayers.LatLon(center.lat,
|
||||
center.lon + (resolution * 50)
|
||||
)
|
||||
);
|
||||
break;
|
||||
case "zoomin": this.map.zoomIn(); break;
|
||||
case "zoomout": this.map.zoomOut(); break;
|
||||
case "zoomextents": this.map.zoomExtent(); break;
|
||||
}
|
||||
Event.stop(evt);
|
||||
}
|
||||
});
|
||||
65
js/OpenLayers/Events.js
Normal file
@@ -0,0 +1,65 @@
|
||||
OpenLayers.Events = Class.create();
|
||||
|
||||
OpenLayers.Events.prototype = {
|
||||
// hash of Array(Function)
|
||||
listeners: null,
|
||||
|
||||
// OpenLayers.Map
|
||||
map: null,
|
||||
|
||||
// DOMElement
|
||||
div: null,
|
||||
|
||||
// supported events
|
||||
BROWSER_EVENTS: [
|
||||
"mouseover", "mouseout",
|
||||
"mousedown", "mouseup", "mousemove",
|
||||
"click", "dblclick"
|
||||
],
|
||||
MAP_EVENTS: [
|
||||
"mouseover", "mouseout",
|
||||
"mousedown", "mouseup", "mousemove",
|
||||
"click", "dblclick"
|
||||
],
|
||||
|
||||
initialize: function (map, div) {
|
||||
this.listeners = {};
|
||||
this.map = map;
|
||||
this.div = div;
|
||||
for (var i = 0; i < this.MAP_EVENTS.length; i++) {
|
||||
this.listeners[ this.MAP_EVENTS[i] ] = [];
|
||||
}
|
||||
for (var i = 0; i < this.BROWSER_EVENTS.length; i++) {
|
||||
var eventName = this.BROWSER_EVENTS[i];
|
||||
Event.observe(div, eventName,
|
||||
this.handleBrowserEvent.bindAsEventListener(this));
|
||||
}
|
||||
},
|
||||
|
||||
register: function (eventName, obj, func) {
|
||||
var listeners = this.listeners[eventName];
|
||||
listeners.push( func.bindAsEventListener(obj) );
|
||||
},
|
||||
|
||||
handleBrowserEvent: function (evt) {
|
||||
evt.xy = this.getMousePosition(evt);
|
||||
this.triggerMapEvent(evt.type, evt)
|
||||
},
|
||||
|
||||
getMousePosition: function (evt) {
|
||||
var offsets = Position.page(this.div);
|
||||
return new OpenLayers.Point(
|
||||
evt.clientX - offsets[0],
|
||||
evt.clientY - offsets[1]);
|
||||
},
|
||||
|
||||
triggerMapEvent: function (type, evt) {
|
||||
evt.map = this.map;
|
||||
|
||||
var listeners = this.listeners[type];
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
var callback = listeners[i];
|
||||
callback(evt);
|
||||
}
|
||||
}
|
||||
};
|
||||
36
js/OpenLayers/Layer.js
Normal file
@@ -0,0 +1,36 @@
|
||||
OpenLayers.Layer = Class.create();
|
||||
|
||||
OpenLayers.Layer.prototype = {
|
||||
// str: name
|
||||
name: null,
|
||||
|
||||
// DOMElement: div
|
||||
div: null,
|
||||
|
||||
// OpenLayers.Map
|
||||
map: null,
|
||||
|
||||
/**
|
||||
* @param {str} name
|
||||
*/
|
||||
initialize: function(name) {
|
||||
this.name = name;
|
||||
},
|
||||
|
||||
/**
|
||||
* Destroy is a destructor: this is to alleviate cyclic references which
|
||||
* the Javascript garbage cleaner can not take care of on its own.
|
||||
*/
|
||||
destroy: function() {
|
||||
this.map = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @params {OpenLayers.Bounds} bound
|
||||
* @params {bool} 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;
|
||||
}
|
||||
};
|
||||
216
js/OpenLayers/Layer/Grid.js
Normal file
@@ -0,0 +1,216 @@
|
||||
OpenLayers.Layer.Grid = Class.create();
|
||||
OpenLayers.Layer.Grid.prototype = Object.extend( new OpenLayers.Layer(), {
|
||||
|
||||
// str: url
|
||||
url: null,
|
||||
|
||||
// hash: params
|
||||
params: null,
|
||||
|
||||
// tileSize: OpenLayers.Size
|
||||
tileSize: null,
|
||||
|
||||
// grid: Array(Array())
|
||||
// this is an array of rows, each row is an array of tiles
|
||||
grid: null,
|
||||
|
||||
DEFAULT_TILE_SIZE: new OpenLayers.Size(256,256),
|
||||
|
||||
/**
|
||||
* @param {str} name
|
||||
* @param {str} url
|
||||
* @param {hash} params
|
||||
*/
|
||||
initialize: function(name, url, params) {
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, [name]);
|
||||
this.url = url;
|
||||
this.params = params;
|
||||
this.tileSize = this.DEFAULT_TILE_SIZE;
|
||||
},
|
||||
/**
|
||||
* moveTo
|
||||
* moveTo is a function 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}
|
||||
*/
|
||||
moveTo:function(bounds,zoomChanged) {
|
||||
if (!this.grid || zoomChanged) {
|
||||
this._initTiles();
|
||||
} else {
|
||||
var i = 0;
|
||||
while (this.getGridBounds().minlat > bounds.minlat) {
|
||||
this.insertRow(false);
|
||||
}
|
||||
while (this.getGridBounds().minlon > bounds.minlon) {
|
||||
this.insertColumn(true);
|
||||
}
|
||||
while (this.getGridBounds().maxlat < bounds.maxlat) {
|
||||
this.insertRow(true);
|
||||
}
|
||||
while (this.getGridBounds().maxlon < bounds.maxlon) {
|
||||
this.insertColumn(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
getGridBounds:function() {
|
||||
var topLeftTile = this.grid[0][0];
|
||||
var bottomRightTile = this.grid[this.grid.length-1][this.grid[0].length-1];
|
||||
return new OpenLayers.Bounds(bottomRightTile.bounds.minlat, topLeftTile.bounds.minlon,
|
||||
topLeftTile.bounds.maxlat, bottomRightTile.bounds.maxlon);
|
||||
},
|
||||
_initTiles:function() {
|
||||
var viewSize = this.map.getSize();
|
||||
var bounds = this.map.getExtent();
|
||||
var extent = this.map.getFullExtent();
|
||||
var resolution = this.map.getResolution();
|
||||
var tilelon = resolution*this.tileSize.w;
|
||||
var tilelat = resolution*this.tileSize.h;
|
||||
|
||||
var offsetlon = bounds.minlon - extent.minlon;
|
||||
var tilecol = Math.floor(offsetlon/tilelon);
|
||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
||||
var tileoffsetlon = extent.minlon + tilecol * tilelon;
|
||||
|
||||
var offsetlat = bounds.maxlat - (extent.minlat + tilelat);
|
||||
var tilerow = Math.ceil(offsetlat/tilelat);
|
||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
||||
var tileoffsety = -tilerowremain * this.tileSize.h;
|
||||
var tileoffsetlat = extent.minlat + tilerow * tilelat;
|
||||
|
||||
tileoffsetx = Math.round(tileoffsetx); // heaven help us
|
||||
tileoffsety = Math.round(tileoffsety);
|
||||
|
||||
this.origin = new OpenLayers.Point(tileoffsetx,tileoffsety);
|
||||
this.grid = new Array();
|
||||
|
||||
var startX = tileoffsetx;
|
||||
var startLon = tileoffsetlon;
|
||||
|
||||
do {
|
||||
var row = new Array();
|
||||
this.grid.append(row);
|
||||
tileoffsetlon = startLon;
|
||||
tileoffsetx = startX;
|
||||
do {
|
||||
var tileBounds = new OpenLayers.Bounds(
|
||||
tileoffsetlat,
|
||||
tileoffsetlon,
|
||||
tileoffsetlat+tilelat,
|
||||
tileoffsetlon+tilelon
|
||||
);
|
||||
var tile = this.addTile(tileBounds,
|
||||
new OpenLayers.Point(tileoffsetx,
|
||||
tileoffsety
|
||||
)
|
||||
);
|
||||
row.append(tile);
|
||||
|
||||
tileoffsetlon += tilelon;
|
||||
tileoffsetx += this.tileSize.w;
|
||||
} while (tileoffsetlon < bounds.maxlon)
|
||||
|
||||
tileoffsetlat -= tilelat;
|
||||
tileoffsety += this.tileSize.h;
|
||||
} while(tileoffsetlat > bounds.minlat - tilelat)
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {bool} prepend - if true, prepend to beginning.
|
||||
* if false, then append to end
|
||||
*/
|
||||
insertRow:function(prepend) {
|
||||
var modelRowIndex = (prepend) ? 0 : (this.grid.length - 1);
|
||||
var modelRow = this.grid[modelRowIndex];
|
||||
|
||||
var newRow = new Array();
|
||||
|
||||
var resolution = this.map.getResolution();
|
||||
var deltaY = (prepend) ? -this.tileSize.h : this.tileSize.h;
|
||||
var deltaLat = resolution * -deltaY;
|
||||
|
||||
for (var i=0; i < modelRow.length; i++) {
|
||||
var modelTile = modelRow[i];
|
||||
var bounds = modelTile.bounds.copyOf();
|
||||
var position = modelTile.position.copyOf();
|
||||
bounds.minlat = bounds.minlat + deltaLat;
|
||||
bounds.maxlat = bounds.maxlat + deltaLat;
|
||||
position.y = position.y + deltaY;
|
||||
var newTile = this.addTile(bounds, position);
|
||||
newRow.append(newTile);
|
||||
}
|
||||
|
||||
if (newRow.length>0){
|
||||
if (prepend) {
|
||||
this.grid.prepend(newRow);
|
||||
} else {
|
||||
this.grid.append(newRow);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {bool} prepend - if true, prepend to beginning.
|
||||
* if false, then append to end
|
||||
*/
|
||||
insertColumn:function(prepend) {
|
||||
var modelCellIndex;
|
||||
var deltaX = (prepend) ? -this.tileSize.w : this.tileSize.w;
|
||||
var resolution = this.map.getResolution();
|
||||
var deltaLon = resolution * deltaX;
|
||||
|
||||
for (var i=0; i<this.grid.length; i++) {
|
||||
var row = this.grid[i];
|
||||
modelTileIndex = (prepend) ? 0 : (row.length - 1);
|
||||
var modelTile = row[modelTileIndex];
|
||||
|
||||
var bounds = modelTile.bounds.copyOf();
|
||||
var position = modelTile.position.copyOf();
|
||||
bounds.minlon = bounds.minlon + deltaLon;
|
||||
bounds.maxlon = bounds.maxlon + deltaLon;
|
||||
position.x = position.x + deltaX;
|
||||
var newTile = this.addTile(bounds, position);
|
||||
|
||||
if (prepend) {
|
||||
row = row.prepend(newTile);
|
||||
} else {
|
||||
row = row.append(newTile);
|
||||
}
|
||||
}
|
||||
},
|
||||
/** combine the ds's serverPath with its params and the tile's params.
|
||||
*
|
||||
* does checking on the serverPath variable, allowing for cases when it
|
||||
* is supplied with trailing ? or &, as well as cases where not.
|
||||
*
|
||||
* return in formatted string like this:
|
||||
* "server?key1=value1&key2=value2&key3=value3"
|
||||
*
|
||||
* @return {str}
|
||||
*/
|
||||
getFullRequestString:function(params) {
|
||||
var requestString = "";
|
||||
|
||||
// concat tile params with layer params and convert to string
|
||||
var allParams = Object.extend(params, this.params);
|
||||
var paramsString = OpenLayers.getParameterString(allParams);
|
||||
|
||||
var server = this.url;
|
||||
var lastServerChar = server.charAt(server.length - 1);
|
||||
|
||||
if ((lastServerChar == "&") || (lastServerChar == "?")) {
|
||||
requestString = server + paramsString;
|
||||
} else {
|
||||
if (server.indexOf('?') == -1) {
|
||||
//serverPath has no ? -- add one
|
||||
requestString = server + '?' + paramsString;
|
||||
} else {
|
||||
//serverPath contains ?, so must already have paramsString at the end
|
||||
requestString = server + '&' + paramsString;
|
||||
}
|
||||
}
|
||||
return requestString;
|
||||
}
|
||||
});
|
||||
46
js/OpenLayers/Layer/WMS.js
Normal file
@@ -0,0 +1,46 @@
|
||||
OpenLayers.Layer.WMS = Class.create();
|
||||
OpenLayers.Layer.WMS.prototype =
|
||||
Object.extend( new OpenLayers.Layer.Grid(), {
|
||||
|
||||
// hash
|
||||
DEFAULT_PARAMS: {
|
||||
service: "WMS",
|
||||
version: "1.1.1",
|
||||
request: "GetMap",
|
||||
srs: "EPSG:4326",
|
||||
exceptions: "application/vnd.ogc.se_inimage"
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {str} name
|
||||
* @param {str} url
|
||||
* @param {hash} params
|
||||
*/
|
||||
initialize: function(name, url, params) {
|
||||
OpenLayers.Layer.Grid.prototype.initialize.apply(this, arguments);
|
||||
Object.extend(this.params, this.DEFAULT_PARAMS);
|
||||
},
|
||||
|
||||
/**
|
||||
* addTile creates a tile, initializes it (via 'draw' in this case), and
|
||||
* adds it to the layer div. THe tile itself is then returned so that info
|
||||
* about it can be stored for later reuse.
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*/
|
||||
addTile:function(bounds,position) {
|
||||
url = this.getFullRequestString(
|
||||
{bbox:bounds.toBBOX(),
|
||||
width:this.tileSize.w,
|
||||
height:this.tileSize.h});
|
||||
var tile = new OpenLayers.Tile.Image(bounds, url, this.tileSize);
|
||||
tile.draw();
|
||||
tile.setPosition(position);
|
||||
this.div.appendChild(tile.img);
|
||||
return tile;
|
||||
},
|
||||
|
||||
_initTiles: function () {
|
||||
this.div.innerHTML="";
|
||||
OpenLayers.Layer.Grid.prototype._initTiles.apply(this, arguments);
|
||||
},
|
||||
});
|
||||
325
js/OpenLayers/Map.js
Normal file
@@ -0,0 +1,325 @@
|
||||
/**
|
||||
* @class
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
OpenLayers.Map = Class.create();
|
||||
OpenLayers.Map.prototype = {
|
||||
|
||||
// OpenLayers.Bounds
|
||||
DEFAULT_FULL_EXTENT: new OpenLayers.Bounds(-90, -180, 90, 180),
|
||||
|
||||
/* maxScale was determined empirically by finding the resolution
|
||||
of GMaps in degrees per pixel at zoom level 0. */
|
||||
// float
|
||||
RESOLUTION_AT_ZOOM_LEVEL_0: .3515625, // degrees per pixel
|
||||
|
||||
// Hash: base z-indexes for different classes of thing
|
||||
Z_INDEX_BASE: { Layer: 100, Popup: 200, Control: 250 },
|
||||
|
||||
// DOMElement: the div that our map lives in
|
||||
div: null,
|
||||
|
||||
// HTMLDivElement: the map's control layer
|
||||
controlDiv: 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,
|
||||
|
||||
// OpenLayers.LatLon
|
||||
center: null,
|
||||
|
||||
// int
|
||||
zoom: null,
|
||||
|
||||
// OpenLayers.Events
|
||||
events: null,
|
||||
|
||||
// OpenLayers.Point
|
||||
mouseDragStart: null,
|
||||
|
||||
/**
|
||||
* @param {DOMElement} div
|
||||
*/
|
||||
initialize: function (div) {
|
||||
this.div = div;
|
||||
|
||||
this.viewPortDiv = OpenLayers.Util.createDiv(
|
||||
div.id + "_OpenLayers_ViewPort" );
|
||||
this.viewPortDiv.style.width = "100%";
|
||||
this.viewPortDiv.style.height = "100%";
|
||||
this.viewPortDiv.style.overflow = "hidden";
|
||||
this.viewPortDiv.style.position = "relative";
|
||||
this.div.appendChild(this.viewPortDiv);
|
||||
|
||||
this.controlDiv = OpenLayers.Util.createDiv(
|
||||
div.id + "_OpenLayers_Control" );
|
||||
this.controlDiv.style.zIndex = this.Z_INDEX_BASE["Control"];
|
||||
this.viewPortDiv.appendChild(this.controlDiv);
|
||||
|
||||
this.layerContainerDiv = OpenLayers.Util.createDiv(
|
||||
div.id + "_OpenLayers_Container" );
|
||||
this.viewPortDiv.appendChild(this.layerContainerDiv);
|
||||
|
||||
this.layers = [];
|
||||
|
||||
this.controls = [];
|
||||
this.addControl( new OpenLayers.Control.PanZoom() );
|
||||
|
||||
this.events = new OpenLayers.Events(this, div);
|
||||
this.events.register( "dblclick", this, this.defaultDblClick );
|
||||
this.events.register( "mousedown", this, this.defaultMouseDown );
|
||||
this.events.register( "mouseup", this, this.defaultMouseUp );
|
||||
this.events.register( "mousemove", this, this.defaultMouseMove );
|
||||
|
||||
// always call map.destroy()
|
||||
Event.observe(window, 'unload',
|
||||
this.destroy.bindAsEventListener(this));
|
||||
},
|
||||
|
||||
/**
|
||||
*/
|
||||
destroy:function() {
|
||||
for(var i=0; i< this.layers.length; i++) {
|
||||
this.layers[i].destroy();
|
||||
}
|
||||
this.layers = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Layer} layer
|
||||
*/
|
||||
addLayer: function (layer) {
|
||||
layer.map = this;
|
||||
layer.div = OpenLayers.Util.createDiv();
|
||||
//layer.div.style.overflow = "hidden";
|
||||
layer.div.style.zIndex = this.Z_INDEX_BASE['Layer'] + this.layers.length;
|
||||
this.layerContainerDiv.appendChild(layer.div);
|
||||
this.layers.push(layer);
|
||||
},
|
||||
|
||||
addControl: function (control) {
|
||||
control.map = this;
|
||||
this.controls.push(control);
|
||||
this.controlDiv.appendChild( control.draw() );
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {float}
|
||||
*/
|
||||
getResolution: function () {
|
||||
// return degrees per pixel
|
||||
return this.RESOLUTION_AT_ZOOM_LEVEL_0 / Math.pow(2, this.zoom);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {int}
|
||||
*/
|
||||
getZoom: function () {
|
||||
return this.zoom;
|
||||
},
|
||||
|
||||
/**
|
||||
* @returns {OpenLayers.Size}
|
||||
*/
|
||||
getSize: function () {
|
||||
// should this be cached?
|
||||
return new OpenLayers.Size(
|
||||
this.div.clientWidth, this.div.clientHeight);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.LatLon}
|
||||
*/
|
||||
getCenter: function () {
|
||||
return this.center;
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.Bounds}
|
||||
*/
|
||||
getExtent: function () {
|
||||
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.lat - h_deg / 2,
|
||||
this.center.lon - w_deg / 2,
|
||||
this.center.lat + h_deg / 2,
|
||||
this.center.lon + w_deg / 2);
|
||||
},
|
||||
|
||||
/**
|
||||
* @return {OpenLayers.Bounds}
|
||||
*/
|
||||
getFullExtent: function () {
|
||||
return this.DEFAULT_FULL_EXTENT;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Bounds} bounds
|
||||
*
|
||||
* @return {int}
|
||||
*/
|
||||
getZoomForExtent: function (bounds) {
|
||||
var size = this.getSize();
|
||||
var deg_per_pixel = bounds.width / size.w;
|
||||
var zoom = Math.log( deg_per_pixel / this.RESOLUTION_AT_ZOOM_LEVEL_0)
|
||||
/ Math.log(2);
|
||||
return Math.floor(Math.max(zoom, 0));
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Point} point
|
||||
*
|
||||
* @return {OpenLayers.LatLon}
|
||||
*/
|
||||
getLatLonFromPoint: function (point) {
|
||||
var center = this.getCenter(); //map center lat/lon
|
||||
var res = this.getResolution();
|
||||
var size = this.getSize();
|
||||
|
||||
var delta_x = point.x - (size.w / 2);
|
||||
var delta_y = point.y - (size.h / 2);
|
||||
|
||||
return new OpenLayers.LatLon(
|
||||
center.lat - delta_y * res,
|
||||
center.lon + delta_x * res );
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} latlon
|
||||
* @param {int} zoom
|
||||
*/
|
||||
setCenter: function (latlon, zoom) {
|
||||
if (this.center) { // otherwise there's nothing to move yet
|
||||
this.moveLayerContainer(latlon);
|
||||
}
|
||||
this.center = latlon.copyOf();
|
||||
var zoomChanged = false;
|
||||
if (zoom != null) {
|
||||
if (this.zoom && zoom != this.zoom)
|
||||
zoomChanged = true;
|
||||
this.zoom = zoom;
|
||||
}
|
||||
|
||||
this.moveToNewExtent();
|
||||
},
|
||||
|
||||
moveToNewExtent: function (zoomChanged) {
|
||||
if (zoomChanged) {
|
||||
this.layerContainerDiv.style.left = "0px";
|
||||
this.layerContainerDiv.style.top = "0px";
|
||||
}
|
||||
var bounds = this.getExtent();
|
||||
for (var i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].moveTo(bounds, zoomChanged);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomIn
|
||||
* Increase zoom level by one.
|
||||
*/
|
||||
zoomIn: function() {
|
||||
if (this.zoom != null) {
|
||||
this.zoom += 1;
|
||||
this.moveToNewExtent(true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* zoomOut
|
||||
* Decrease zoom level by one.
|
||||
*/
|
||||
zoomOut: function() {
|
||||
if (this.zoom != null && this.zoom > 0) {
|
||||
this.zoom -= 1;
|
||||
this.moveToNewExtent(true);
|
||||
}
|
||||
},
|
||||
|
||||
zoomExtent: function() {
|
||||
var fullExtent = this.getFullExtent();
|
||||
|
||||
this.zoom = this.getZoomForExtent( fullExtent );
|
||||
this.setCenter(
|
||||
new OpenLayers.LatLon(
|
||||
(fullExtent.minlat+fullExtent.maxlat)/2,
|
||||
(fullExtent.minlon+fullExtent.maxlon)/2
|
||||
)
|
||||
);
|
||||
this.moveToNewExtent(true);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.LatLon} latlon
|
||||
*/
|
||||
moveLayerContainer: function (latlon) {
|
||||
var container = this.layerContainerDiv;
|
||||
var resolution = this.getResolution();
|
||||
|
||||
var deltaX = Math.round((this.center.lon - latlon.lon) / resolution);
|
||||
var deltaY = Math.round((this.center.lat - latlon.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";
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultDblClick: function (evt) {
|
||||
var newCenter = this.getLatLonFromPoint( evt.xy );
|
||||
this.setCenter(newCenter);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultMouseDown: function (evt) {
|
||||
this.mouseDragStart = evt.xy.copyOf();
|
||||
this.div.style.cursor = "move";
|
||||
Event.stop(evt);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultMouseMove: function (evt) {
|
||||
if (this.mouseDragStart != null) {
|
||||
var deltaX = this.mouseDragStart.x - evt.xy.x;
|
||||
var deltaY = this.mouseDragStart.y - evt.xy.y
|
||||
var size = this.getSize();
|
||||
var newXY = new OpenLayers.Point(size.w / 2 + deltaX,
|
||||
size.h / 2 + deltaY);
|
||||
var newCenter = this.getLatLonFromPoint( newXY );
|
||||
this.setCenter(newCenter);
|
||||
this.mouseDragStart = evt.xy.copyOf();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} evt
|
||||
*/
|
||||
defaultMouseUp: function (evt) {
|
||||
this.mouseDragStart = null;
|
||||
this.div.style.cursor = "default";
|
||||
},
|
||||
};
|
||||
77
js/OpenLayers/Tile.js
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* OpenLayers.Tile is a class designed to designate a single tile, however
|
||||
* it is explicitly designed to do relatively little. Tiles store information
|
||||
* about themselves -- such as the URL that they are related to, and their
|
||||
* size - but do not add themselves to the layer div automatically, for
|
||||
* example.
|
||||
*/
|
||||
OpenLayers.Tile = Class.create();
|
||||
OpenLayers.Tile.prototype = {
|
||||
|
||||
// str - url of the request
|
||||
url:null,
|
||||
|
||||
// OpenLayers.Bounds
|
||||
bounds:null,
|
||||
|
||||
// OpenLayers.Size
|
||||
size:null,
|
||||
|
||||
// OpenLayers.Point Bottom Left pixel of the tile
|
||||
position:null,
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Layer} layer
|
||||
* @param {OpenLayers.LatLon} coord
|
||||
*/
|
||||
initialize: function(bounds,url,size) {
|
||||
if (arguments.length > 0) {
|
||||
this.url = url;
|
||||
this.bounds = bounds;
|
||||
this.size = size;
|
||||
}
|
||||
},
|
||||
|
||||
/** get the full request string from the ds and the tile params
|
||||
* and call the AJAX loadURL().
|
||||
*
|
||||
* input are function pointers for what to do on success and failure.
|
||||
*
|
||||
* @param {function} success
|
||||
* @param {function} failure
|
||||
*/
|
||||
loadFeaturesForRegion:function(success, failure) {
|
||||
|
||||
if (!this.loaded) {
|
||||
|
||||
var server = this.ds.serverPath;
|
||||
|
||||
if (server != "") {
|
||||
|
||||
var queryString = this.getFullRequestString();
|
||||
// TODO: Hmmm, this stops multiple loads of the data when a
|
||||
// result isn't immediately retrieved, but it's hacky.
|
||||
// Do it better.
|
||||
this.loaded = true;
|
||||
OpenLayers.Application.loadURL(queryString, null, this,
|
||||
success, failure);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
draw:function() {
|
||||
},
|
||||
|
||||
/** remove this tile from the ds
|
||||
*/
|
||||
remove:function() {
|
||||
},
|
||||
|
||||
|
||||
////////////////////
|
||||
who:function(){return "tiled.js";} // last!
|
||||
};
|
||||
|
||||
30
js/OpenLayers/Tile/Image.js
Normal file
@@ -0,0 +1,30 @@
|
||||
OpenLayers.Tile.Image = Class.create();
|
||||
OpenLayers.Tile.Image.prototype =
|
||||
Object.extend( new OpenLayers.Tile(), {
|
||||
|
||||
// {DOMElement} img
|
||||
img:null,
|
||||
|
||||
initialize: function(bounds,url,size) {
|
||||
OpenLayers.Tile.prototype.initialize.apply(this,arguments);
|
||||
},
|
||||
|
||||
draw:function() {
|
||||
OpenLayers.Tile.prototype.draw.apply(this, arguments);
|
||||
this.img = OpenLayers.Util.createImage(this.url,
|
||||
this.size);
|
||||
},
|
||||
/*
|
||||
* @param OpenLayers.Point
|
||||
*/
|
||||
setPosition:function(point) {
|
||||
this.img.style.top = point.y+"px";
|
||||
this.img.style.left = point.x+"px";
|
||||
this.img.style.position = "absolute";
|
||||
this.position = point;
|
||||
},
|
||||
getPosition: function() {
|
||||
return this.position;
|
||||
}
|
||||
}
|
||||
);
|
||||
388
js/OpenLayers/Util.js
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* Convert degrees to radians
|
||||
*/
|
||||
OpenLayers.Util=new Object();
|
||||
|
||||
OpenLayers.Point = Class.create();
|
||||
OpenLayers.Point.prototype = {
|
||||
initialize: function(x,y) {
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
},
|
||||
toString:function(){
|
||||
return ("x="+this.x+",y="+this.y);
|
||||
},
|
||||
copyOf:function() {
|
||||
return new OpenLayers.Point(this.x, this.y);
|
||||
},
|
||||
diff:function(pt){ // subtract pt from this
|
||||
return new OpenLayers.Size(this.x - pt.x, this.y - pt.y);
|
||||
},
|
||||
absDiff:function(pt){ // subtract pt from this
|
||||
return new OpenLayers.Size(Math.abs(this.x - pt.x), Math.abs(this.y - pt.y));
|
||||
},
|
||||
diffPt:function(pt){
|
||||
sz=this.diff(pt);
|
||||
return new OpenLayers.Point(sz.w,sz.h);
|
||||
},
|
||||
equal:function(pt){
|
||||
d = this.diff(pt);
|
||||
return (d.w==0&&d.h==0);
|
||||
},
|
||||
addSize:function(sz){
|
||||
return new OpenLayers.Point(this.x+sz.w, this.y+sz.h);
|
||||
},
|
||||
addX:function(w){
|
||||
return new OpenLayers.Point(this.x+w, this.y);
|
||||
},
|
||||
addY:function(h){
|
||||
return new OpenLayers.Point(this.x, this.y+h);
|
||||
},
|
||||
samePT:function(pt){
|
||||
return (this.x==pt.x && this.y==pt.y);
|
||||
}
|
||||
};
|
||||
OpenLayers.Size = Class.create();
|
||||
OpenLayers.Size.prototype = {
|
||||
initialize: function(w,h) {
|
||||
this.w=w;
|
||||
this.h=h;
|
||||
},
|
||||
toString:function(){
|
||||
return ("w="+this.w+",h="+this.h);
|
||||
},
|
||||
copyOf:function(){
|
||||
return new OpenLayers.Size(this.w, this.h);
|
||||
},
|
||||
sameSize:function(pt){
|
||||
return (this.w==pt.w && this.h==pt.h);
|
||||
}
|
||||
};
|
||||
|
||||
OpenLayers.LatLon = Class.create();
|
||||
OpenLayers.LatLon.prototype = {
|
||||
initialize: function(lat,lon) {
|
||||
this.lat=lat;
|
||||
this.lon=lon;
|
||||
},
|
||||
toString:function(){
|
||||
return ("lat="+this.lat+",lon="+this.lon);
|
||||
},
|
||||
copyOf:function(){
|
||||
return new OpenLayers.LatLon(this.lat, this.lon);
|
||||
},
|
||||
toShortString:function(){
|
||||
return (this.lat+", "+this.lon);
|
||||
},
|
||||
diff:function(pt){ // subtract pt from this
|
||||
return new OpenLayers.LatLon(this.lat - pt.lat,this.lon - pt.lon);
|
||||
},
|
||||
samePT:function(pt){
|
||||
return (this.lat==pt.lat && this.lon==pt.lon);
|
||||
}
|
||||
};
|
||||
OpenLayers.LatLon.fromString=function(str){
|
||||
var pairs=str.split(",");
|
||||
return new OpenLayers.LatLon(pairs[1],pairs[0]);
|
||||
};
|
||||
OpenLayers.Bounds = Class.create();
|
||||
OpenLayers.Bounds.prototype = {
|
||||
initialize: function(minlat,minlon,maxlat,maxlon){
|
||||
this.minlat=minlat;
|
||||
this.minlon=minlon;
|
||||
this.maxlat=maxlat;
|
||||
this.maxlon=maxlon;
|
||||
this.width = Math.abs(this.maxlon - this.minlon);
|
||||
this.height = Math.abs(this.maxlat - this.minlat);
|
||||
},
|
||||
toString:function(){
|
||||
return ("Min lat/lon=" + this.minlat +"/"+ this.minlon
|
||||
+ " Max lat/lon=" + this.maxlat +"/"+ this.maxlon
|
||||
+ " width:" + this.width + " height:" + this.height);
|
||||
},
|
||||
copyOf:function(){
|
||||
return new OpenLayers.Bounds(this.minlat, this.minlon,
|
||||
this.maxlat, this.maxlon);
|
||||
},
|
||||
toBBOX:function(){
|
||||
return (this.minlon+","+this.minlat+","+this.maxlon+","+this.maxlat);
|
||||
},
|
||||
contains:function(pt){
|
||||
return (pt.lon >=this.minlon && pt.lon <=this.maxlon
|
||||
&& pt.lat >=this.minlat && pt.lat <= this.maxlat)
|
||||
}
|
||||
|
||||
};
|
||||
/** Create bounds from coordinates in a string:-180.000000,-90.000000 180.000000,90.000000
|
||||
*/
|
||||
OpenLayers.Bounds.fromString=function(str){
|
||||
var pairs=str.split(" ");
|
||||
var min=pairs[0];
|
||||
var max=pairs[1];
|
||||
|
||||
var latlon = min.split(",");
|
||||
var latlon2 = max.split(",");
|
||||
return new OpenLayers.Bounds(latlon[1],latlon[0],latlon2[1],latlon2[0]);
|
||||
};
|
||||
|
||||
OpenLayers.Box = Class.create();
|
||||
OpenLayers.Box.prototype = {
|
||||
initialize: function(x,y,w,h){
|
||||
this.xy=new OpenLayers.Point(x,y);
|
||||
this.sz=new OpenLayers.Size(w,h);
|
||||
this.c = new OpenLayers.Point(x+(w/2), y+(h/2));
|
||||
this.br = new OpenLayers.Point(x+w-1,y+h-1);
|
||||
},
|
||||
|
||||
/* offset box by df
|
||||
* @df(OpenLayers.Size)
|
||||
*/
|
||||
offset:function(df){
|
||||
this.xy=new OpenLayers.Point(this.xy.x+df.w,this.xy.y+df.h);
|
||||
this.c = new OpenLayers.Point(this.xy.x+(this.sz.w/2), this.xy.y+(this.sz.h/2));
|
||||
var x=this.xy.x;
|
||||
var y=this.xy.y;
|
||||
var w=this.sz.w;
|
||||
var h=this.sz.h;
|
||||
this.br = new OpenLayers.Point(x+w-1,y+h-1);
|
||||
},
|
||||
|
||||
getOrigin:function(){return this.xy;},
|
||||
getSize:function(){return this.sz;},
|
||||
getCenter:function(){return this.c;},
|
||||
getBotRight:function(){return this.br;},
|
||||
getWidth:function(){return this.sz.w;},
|
||||
getHeight:function(){return this.sz.h;},
|
||||
getSize:function(){return this.sz;},
|
||||
|
||||
toString:function(){
|
||||
return (this.xy.toString() + " " + this.sz.toString());
|
||||
},
|
||||
copyOf:function(){
|
||||
return new OpenLayers.Box(this.xy.x, this.xy.y, this.sz.w, this.sz.h);
|
||||
},
|
||||
toCoordsString:function(){
|
||||
var x1 = this.xy.x;
|
||||
var x2 = this.xy.x+this.sz.w-1;
|
||||
var y1 = this.xy.y;
|
||||
var y2 = this.xy.y+this.sz.h-1;
|
||||
return (x1+","+y1+","+x2+","+y2);
|
||||
},
|
||||
contains:function(pt){
|
||||
var returnVal = false;
|
||||
|
||||
var lx=this.xy.x;
|
||||
var ly=this.xy.y;
|
||||
var rx=lx+this.sz.w-1;
|
||||
var ry=ly+this.sz.h-1;
|
||||
|
||||
if (pt != null) {
|
||||
//upper left in
|
||||
returnVal = (pt.x >=lx && pt.x <=rx && pt.y >=ly && pt.y <= ry);
|
||||
}
|
||||
return returnVal;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {ol.Box} box
|
||||
* @param {bool} partial - if true, returns whether any part of the passed
|
||||
* in box is within the calling box. otherwise box
|
||||
* must contain entire box to return true.
|
||||
*
|
||||
* @return {bool}
|
||||
*/
|
||||
containsBox:function(box, partial) {
|
||||
var contains = false;
|
||||
|
||||
var mainTop = this.xy.y;
|
||||
var mainLeft = this.xy.x;
|
||||
var mainBottom = this.xy.y + this.sz.h;
|
||||
var mainRight = this.xy.x + this.sz.w;
|
||||
|
||||
var top = box.xy.y;
|
||||
var left = box.xy.x;
|
||||
var bottom = box.xy.y + box.sz.h;
|
||||
var right = box.xy.x + box.sz.w;
|
||||
|
||||
var inTop = (top >= mainTop) && (top <= mainBottom);
|
||||
var inLeft = (left >= mainLeft) && (left <= mainRight);
|
||||
var inBottom = (bottom >= mainTop) && (bottom <= mainBottom);
|
||||
var inRight= (right >= mainLeft) && (right <= mainRight);
|
||||
|
||||
if (partial) {
|
||||
contains = (inTop || inBottom) && (inLeft || inRight );
|
||||
} else {
|
||||
contains = (inTop && inLeft && inBottom && inRight);
|
||||
}
|
||||
|
||||
return contains;
|
||||
},
|
||||
|
||||
// is this point the center of the box, +-2 pixels (@todo fix that number!)
|
||||
isCenter:function(pt){
|
||||
var size = this.c.absDiff(pt);
|
||||
return (size.w <= 2 && size.h <= 2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Some other helpful things
|
||||
String.prototype.startsWith = function(sStart){
|
||||
return (this.substr(0,sStart.length)==sStart);
|
||||
};
|
||||
String.prototype.trim = function() {
|
||||
var b=0,e=this.length -1;
|
||||
while(this.substr(b,1) == " ") {b++;}
|
||||
while(this.substr(e,1) == " ") {e--;}
|
||||
return this.substring(b,e+1);
|
||||
};
|
||||
Array.prototype.remove = function(rem) {
|
||||
for(var i=0; i<this.length; i++) {
|
||||
if(this[i]==rem) {
|
||||
this.splice(i,1);
|
||||
//break;more than once??
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
Array.prototype.copy = function() {
|
||||
var copy = new Array();
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
copy[i] = this[i];
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
|
||||
Array.prototype.prepend = function(the_item) {
|
||||
this.splice(0,0,the_item);
|
||||
};
|
||||
Array.prototype.append=function(the_item){
|
||||
this[this.length]=the_item;
|
||||
};
|
||||
Array.prototype.clear=function() {this.length=0;};
|
||||
|
||||
/** Create a child element (a div currently) that
|
||||
* is a proper child of the supplied parent, is invisible,
|
||||
* positioned as requested within the parent, etc
|
||||
*
|
||||
* zIndex is NOT set
|
||||
*
|
||||
* @param {str} id - HTML ID of new element, if empty something is made up
|
||||
* @param {OpenLayers.Point} pt - x,y point if missing 0,0 is used
|
||||
* @param {OpenLayers.Size} sz - size else size of parent is used
|
||||
* @param {str} overflow - behavior of clipped/overflow content
|
||||
* @param {str} img - background image url
|
||||
* @param {str} position - relative or absolute?
|
||||
*
|
||||
* @return {DOM}
|
||||
*/
|
||||
OpenLayers.Util.createDiv = function(id, pt, sz, overflow, img, position) {
|
||||
var x,y,w,h;
|
||||
|
||||
if (pt){
|
||||
x = pt.x;
|
||||
y = pt.y;
|
||||
} else {
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
if (!position){
|
||||
position = "absolute";
|
||||
}
|
||||
|
||||
if (!id){
|
||||
id = "OpenLayersDiv" + (Math.random()*10000%10000);
|
||||
}
|
||||
|
||||
var dom = document.createElement('div');
|
||||
dom.id = id;
|
||||
if (overflow){
|
||||
dom.style.overflow = overflow;
|
||||
}
|
||||
if (sz) {
|
||||
dom.style.width = sz.w+"px";
|
||||
dom.style.height = sz.h+"px";
|
||||
}
|
||||
dom.style.position = position;
|
||||
dom.style.top = y;
|
||||
dom.style.left = x;
|
||||
dom.style.padding = "0";
|
||||
dom.style.margin = "0";
|
||||
dom.style.cursor = "inherit";
|
||||
|
||||
if (img){
|
||||
dom.style.backgroundImage = 'url(' + img + ')';
|
||||
}
|
||||
|
||||
return dom;
|
||||
};
|
||||
|
||||
|
||||
OpenLayers.Util.ImageHTML=function(img,sz,alt){
|
||||
return "<img src='" + img + "' padding='0' border='0' alt='" + alt + "' width=" + sz.w + "px height=" + sz.h + "px/>";
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {str} img - src URL
|
||||
* @param {OpenLayers.Size} sz
|
||||
* @param {OpenLayers.Point} xy
|
||||
* @param {str} position
|
||||
* @param {str} id
|
||||
* @param {int} border
|
||||
*/
|
||||
OpenLayers.Util.createImage = function(img, sz, xy, position, id, border) {
|
||||
image = document.createElement("img");
|
||||
if (id) {
|
||||
image.id = id;
|
||||
image.style.alt = id;
|
||||
}
|
||||
if (xy) {
|
||||
image.style.left = xy.x;
|
||||
image.style.top = xy.y;
|
||||
}
|
||||
if (sz) {
|
||||
image.style.width = sz.w;
|
||||
image.style.height = sz.h;
|
||||
}
|
||||
if (position) {
|
||||
image.style.position = position;
|
||||
} else {
|
||||
image.style.position = "relative";
|
||||
}
|
||||
if (border) {
|
||||
image.style.border = border + "px solid";
|
||||
} else {
|
||||
image.style.border = 0;
|
||||
}
|
||||
image.style.cursor = "inherit";
|
||||
image.src = img;
|
||||
return image;
|
||||
};
|
||||
|
||||
|
||||
/** returns a concatenation of the properties of an object in
|
||||
* http parameter notation. ex:
|
||||
*
|
||||
* "key1=value1&key2=value2&key3=value3"
|
||||
*
|
||||
* @param {Object} params
|
||||
*
|
||||
* @return {str}
|
||||
*/
|
||||
OpenLayers.getParameterString = function(params) {
|
||||
paramsArray = new Array();
|
||||
|
||||
for (var key in params) {
|
||||
var value = params[key];
|
||||
//skip functions
|
||||
if (typeof value == 'function') continue;
|
||||
|
||||
paramsArray.push(key + "=" + value);
|
||||
}
|
||||
|
||||
return paramsArray.join("&");
|
||||
};
|
||||
|
||||
OpenLayers.Util.getImagesLocation = function () {
|
||||
return "img/";
|
||||
};
|
||||
1781
js/Prototype.js
Normal file
4
svn-commit.2.tmp
Normal file
@@ -0,0 +1,4 @@
|
||||
Created new trunk.
|
||||
--This line, and those below, will be ignored--
|
||||
|
||||
A http://svn.openlayers.org/trunk
|
||||
4
svn-commit.tmp
Normal file
@@ -0,0 +1,4 @@
|
||||
Created new trunk directory.
|
||||
--This line, and those below, will be ignored--
|
||||
|
||||
A http://svn.openlayers.org/trunk
|
||||