Redo Yahoo class to work under EventPane.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1387 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-08-26 20:37:00 +00:00
parent 8be2cfbc71
commit 0c1caaf717
3 changed files with 311 additions and 141 deletions
+1
View File
@@ -8,6 +8,7 @@
border: 1px solid black; border: 1px solid black;
} }
</style> </style>
<script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>
<script src="../lib/OpenLayers.js"></script> <script src="../lib/OpenLayers.js"></script>
<script type="text/javascript"> <script type="text/javascript">
<!-- <!--
+1 -1
View File
@@ -70,7 +70,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
"OpenLayers/Layer/FixedZoomLevels.js", "OpenLayers/Layer/FixedZoomLevels.js",
"OpenLayers/Layer/Google.js", "OpenLayers/Layer/Google.js",
"OpenLayers/Layer/VirtualEarth.js", "OpenLayers/Layer/VirtualEarth.js",
// "OpenLayers/Layer/Yahoo.js", "OpenLayers/Layer/Yahoo.js",
"OpenLayers/Layer/HTTPRequest.js", "OpenLayers/Layer/HTTPRequest.js",
"OpenLayers/Layer/Grid.js", "OpenLayers/Layer/Grid.js",
"OpenLayers/Layer/KaMap.js", "OpenLayers/Layer/KaMap.js",
+309 -140
View File
@@ -2,149 +2,318 @@
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
* text of the license. */ * text of the license. */
// load Yahoo map control script /**
document.write("<script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>"); * @class
/**
* @class
* *
* @requires OpenLayers/Layer.js * @requires OpenLayers/Layer/EventPane.js
*/ */
OpenLayers.Layer.Yahoo = Class.create(); OpenLayers.Layer.Yahoo = Class.create();
OpenLayers.Layer.Yahoo.prototype = Object.extend( new OpenLayers.Layer(), { OpenLayers.Layer.Yahoo.prototype =
Object.extend( new OpenLayers.Layer.EventPane(), {
/** Yahoo layer is always a base layer.
* /** @type YMap */
* @type Boolean yahoomap: null,
*/
isBaseLayer: true,
/** @type Boolean */ /** @type int */
isFixed: true, minZoomLevel: 0,
/** @type GMap2 gmap stores the Google Map element */ /** @type int */
ymap:null, maxZoomLevel: 15,
/** @type Boolean */ /**
dragging:false, * @constructor
*
/** * @param {String} name
* @constructor */
* initialize:function(name) {
* @param {String} name OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
*/
initialize: function(name) { this.numZoomLevels = this.maxZoomLevel - this.minZoomLevel + 1;
OpenLayers.Layer.prototype.initialize.apply(this, [name]); },
},
/**
/** * @param {OpenLayers.Map} map
* @param {OpenLayers.Map} map */
*/ setMap:function(map) {
setMap:function(map) { OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
OpenLayers.Layer.prototype.setMap.apply(this, arguments);
// once our layer has been added to the map, we can load the yahoomap
// once our layer has been added to the map, we can create the vemap this.loadYMap();
this.map.events.register("addlayer", this, this.loadYMap); },
},
/**
/** * @param {OpenLayers.Bounds} bounds
* @param {OpenLayers.Bounds} bounds
* @param {Boolean} zoomChanged * @param {Boolean} zoomChanged
* @param {Boolean} minor * @param {Boolean} minor
*/ */
moveTo:function(bounds, zoomChanged, minor) { moveTo:function(bounds, zoomChanged, minor) {
if ((this.ymap != null) && (!this.dragging)) { if (this.yahoomap != null) {
var olCenter = this.map.getCenter();
var olCenter = this.map.getCenter(); var mmCenter = this.getYLatLongFromOLLonLat(olCenter);
var yCenter = this.getYMapCenter();
if (zoomChanged) {
var olZoom = this.map.getZoom(); var olZoom = this.map.getZoom();
var yZoom = this.ymap.getZoomLevel(); var mmZoom = this.getYZoomFromOLZoom(olZoom);
this.yahoomap.setZoomLevel(mmZoom);
if ((!olCenter.equals(yCenter)) || (( 16 - olZoom) != yZoom)) { }
this.ymap.drawZoomAndCenter(new YGeoPoint(olCenter.lat, olCenter.lon), this.yahoomap.drawZoomAndCenter(mmCenter, mmZoom);
16 - olZoom);
} }
} },
},
/** /**
* *
*/ */
loadYMap:function() { loadYMap:function() {
// create div and set to same size as map this.yahoomap = new YMap(this.div);
var yDiv = OpenLayers.Util.createDiv(this.name);
var sz = this.map.getSize();
yDiv.style.width = sz.w; if (this.yahoomap == null) {
yDiv.style.height = sz.h; this.loadWarningMessage();
this.div.appendChild(yDiv); }
// create GMap, hide nav controls },
this.ymap = new YMap(this.div);
/** If we can't load the yahoomap, then display an error message to the
// catch pans and zooms from GMap * user and tell them where to go for help.
YEvent.Capture(this.ymap, *
EventsList.endPan, * @private
this.catchPanZoom, *
this); */
loadWarningMessage:function() {
// catch pans and zooms from GMap
YEvent.Capture(this.ymap, this.div.style.backgroundColor = "darkblue";
EventsList.endAutoPan,
this.catchPanZoom, var html = "";
this); html += "The Y Layer was unable to load correctly.<br>";
html += "<br>";
html += "To get rid of this message, click on the Y Layer's "
// attach to the drag start and end and we´ll set a flag so that html += "tab in the layer switcher in the upper-right corner.<br>";
// we dont get recursivity. this is because the events fall through html += "<br>";
// the gmaps div and into the main layer div html += "Most likely, this is because the Y library";
YEvent.Capture(this.ymap, html += " script was either not correctly included.<br>";
EventsList.startPan, html += "<br>";
this.dragStart, html += "Demmlopers: For help getting this working correctly, ";
this); html += "<a href='http://trac.openlayers.org/wiki/YahooLayer' "
html += "target='_blank'>";
}, html += "click here";
html += "</a>";
/**
* @private var viewSize = this.map.getSize();
*/
dragStart: function() { msgW = Math.min(viewSize.w, 300);
this.dragging = true; msgH = Math.min(viewSize.h, 200);
}, var size = new OpenLayers.Size(msgW, msgH);
/** var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2);
* @private
* var topLeft = centerPx.add(-size.w/2, -size.h/2);
* @param {Event} e
*/ var div = OpenLayers.Util.createDiv("mmWarning",
catchPanZoom: function(e) { topLeft,
this.dragging = false; size,
null,
var olCenter = this.getYMapCenter(); null,
var yZoom = this.ymap.getZoomLevel(); null,
"auto");
this.map.setCenter(olCenter, 16 - yZoom);
div.style.padding = "7px";
}, div.style.backgroundColor = "yellow";
/** div.innerHTML = html;
* @private this.div.appendChild(div);
* },
* @returns An OpenLayers.LonLat with the center of the ymap, or null if
* the YMap has not been centered yet
* @type OpenLayers.LonLat /********************************************************/
*/ /* */
getYMapCenter:function() { /* Baselayer Functions */
var olCenter = null; /* */
var yCenter = this.ymap.getCenterLatLon(); /********************************************************/
if (yCenter != null) {
olCenter = new OpenLayers.LonLat(yCenter.Lon, yCenter.Lat); /**
} * @param {OpenLayers.Pixel} viewPortPx
return olCenter; *
}, * @returns An OpenLayers.LonLat which is the passed-in view port
* OpenLayers.Pixel, translated into lon/lat by Y
* If yahoomap is not loaded, returns null.
/** @final @type String */ * @type OpenLayers.LonLat
CLASS_NAME: "OpenLayers.Layer.Yahoo" */
}); getLonLatFromViewPortPx: function (viewPortPx) {
var lonlat = null;
if (this.yahoomap != null) {
var pixel = this.getPixelFromOLPixel(viewPortPx);
var mmLatLong = this.yahoomap.convertXYLatLon(pixel);
lonlat = this.getOLLonLatFromYLatLong(mmLatLong);
}
return lonlat;
},
/**
* @param {OpenLayers.LonLat} lonlat
*
* @returns An OpenLayers.Pixel which is the passed-in OpenLayers.LonLat,
* translated into view port pixels BY Y
* If yahoomap is not loaded, returns null.
* @type OpenLayers.Pixel
*/
getViewPortPxFromLonLat: function (lonlat) {
var viewPortPx = null;
if (this.yahoomap != null) {
var mmLatLong = this.getYLatLongFromOLLonLat(lonlat);
var pixel = this.yahoomap.convertLatLonXY(mmLatLong);
viewPortPx = this.getOLPixelFromPixel(pixel);
}
return viewPortPx;
},
/**
* @param {OpenLayers.Bounds} bounds
*
* @returns Corresponding zoom lemml for a specified Bounds.
* If yahoomap is not loaded, returns null.
* @type int
*/
getZoomForExtent: function (bounds) {
var zoom = null;
if (this.yahoomap != null) {
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 mmZoom = Math.floor( (Math.log(maxRes/degPerPixel)) /
Math.log(2) );
//make sure zoom is within bounds
var mmZoom = Math.min(Math.max(mmZoom, this.minZoomLevel),
this.maxZoomLevel);
zoom = this.getOLZoomFromYZoom(mmZoom);
}
return zoom;
},
/********************************************************/
/* */
/* Translation Functions */
/* */
/* The following functions translate GMaps and OL */
/* formats for Pixel, LonLat, Bounds, and Zoom */
/* */
/********************************************************/
//
// TRANSLATION: GZoom <-> OpenLayers Zoom
//
/**
* @param {int} mmZoom
*
* @returns An OpenLayers Zoom lemml, translated from the passed in mmZoom
* Returns null if null value is passed in
* @type int
*/
getOLZoomFromYZoom: function(mmZoom) {
return 18 - mmZoom;
},
/**
* @param {int} olZoom
*
* @returns A YZoom lemml, translated from the passed in olZoom
* Returns null if null value is passed in
* @type int
*/
getYZoomFromOLZoom: function(olZoom) {
return 18 - olZoom;
},
//
// TRANSLATION: YLatLong <-> LonLat
//
/**
* @param {YLatLong} mmLatLong
*
* @returns An OpenLayers.LonLat, translated from the passed in YLatLong
* Returns null if null value is passed in
* @type OpenLayers.LonLat
*/
getOLLonLatFromYLatLong: function(mmLatLong) {
var olLonLat = null;
if (mmLatLong != null) {
olLonLat = new OpenLayers.LonLat(mmLatLong.Lon,
mmLatLong.Lat);
}
return olLonLat;
},
/**
* @param {OpenLayers.LonLat} olLonLat
*
* @returns A YLatLong, translated from the passed in OpenLayers.LonLat
* Returns null if null value is passed in
* @type YLatLong
*/
getYLatLongFromOLLonLat: function(olLonLat) {
var mmLatLong = null;
if (olLonLat != null) {
mmLatLong = new YGeoPoint(olLonLat.lat, olLonLat.lon);
}
return mmLatLong;
},
//
// TRANSLATION: Pixel <-> OpenLayers.Pixel
//
/**
* @param {Pixel} pixel
*
* @returns An OpenLayers.Pixel, translated from the passed in Pixel
* Returns null if null value is passed in
* @type OpenLayers.Pixel
*/
getOLPixelFromPixel: function(pixel) {
var olPixel = null;
if (pixel != null) {
olPixel = new OpenLayers.Pixel(pixel.x, pixel.y);
}
return olPixel;
},
/**
* @param {OpenLayers.Pixel} olPixel
*
* @returns A Pixel, translated from the passed in OpenLayers.Pixel
* Returns null if null value is passed in
*
* As it turns out, the only specifications we can see for the
* Y-compatible Pixel is an x & y property, which emmry
* OpenLayers.Pixel has by default. So just leamm it as-is.
*
* @type Pixel
*/
getPixelFromOLPixel: function(olPixel) {
var pixel = null;
if (olPixel != null) {
pixel = new YCoordPoint(olPixel.x, olPixel.y);
}
return pixel;
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Layer.Yahoo"
});