[OpenLayers-Users] center crosshairs?

Mike Quentel mquentel at rim.com
Tue Sep 9 15:28:55 EDT 2008


OpenLayers.Control.Crosshairs = OpenLayers.Class.create();
OpenLayers.Control.Crosshairs.X = 320;
OpenLayers.Control.Crosshairs.Y = 240;
OpenLayers.Control.Crosshairs.prototype = 
  OpenLayers.Class.inherit( OpenLayers.Control, {
    element: null,
    position: null,
    
    initialize: function(element) {
        this.position = new
OpenLayers.Pixel(OpenLayers.Control.Crosshairs.X,
 
OpenLayers.Control.Crosshairs.Y);
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
        this.element = OpenLayers.Util.getElement(element);        
    },
  
    draw: function() {
        OpenLayers.Control.prototype.draw.apply(this, arguments);
        px = this.position.clone();
        var sz = new OpenLayers.Size(21,21);
        var centred = new OpenLayers.Pixel(px.x - (sz.w / 2), px.y);
        this.buttons = new Array();
        var imgLocation = OpenLayers.Util.getImagesLocation() +
"crosshairs.png";
        return
OpenLayers.Util.createAlphaImageDiv("OpenLayers_Control_Crosshairs_" +
"crosshairs", centred, sz, imgLocation, "absolute");
    },
    
    CLASS_NAME: "OpenLayers.Control.Crosshairs"
}); 


Regards,
 
Mike Quentel


-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of geoman
Sent: Tuesday, 09 September 2008 14:21
To: users at openlayers.org
Subject: [OpenLayers-Users] center crosshairs?


Hello,

I am trying to add a icon that is fixed at the center of a map, to show
where the center is when people are zooming. I didn't see a way to add
an icon to a map directly, and it looks like if I put the icon in a
marker and then add that to a layer on the map then the icon will move
with the map. 

My solution was to add the icon through the DOM (using Prototype:)
				var centerIcon = new Element("img");
				centerIcon.src = "img/center5.gif";
				centerIcon.id = "mapCenter";

				centerImg.setStyle({
					left:
((document.viewport.getWidth() / 2) - (centerImg.getWidth() / 2))
+ 'px',
					top:
((document.viewport.getHeight() / 2) - (centerImg.getHeight() /
2)) + 'px'
				});
	
$('map_OpenLayers_ViewPort').insert(centerIcon);

Here is the styling I used for this element:
  img#mapCenter {
  	position: absolute;
  	z-index: 10000;
  }


Is there a way to do this using the OpenLayers API? If not, can you
offer any solutions with a couple major problems I see with the above
approach:
1. The icon isn't always at the center of the map; it is always close,
but when I zoom in I can tell it is slightly high and to the left. I'm
not sure why it is usually dead-center and sometimes off-center.
2. Markers under the icon no longer receive mouse events. I tried to set
the z-index of the icon so it would be under my marker layer, but my
map_OpenLayers_Container has a z-index of 749 and my marker layer has a
z-index of 350, and I can't set the z-index both above 749 (so the icon
is visible over the map tiles) and below 350 (so the markers will
receive input events). 

Thanks in advance,
Craig


-- 
View this message in context:
http://www.nabble.com/center-crosshairs--tp19398206p19398206.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.



More information about the Users mailing list