[OpenLayers-Users] OpenLayers.Layer.Text and Vector layer above. How to pass events to open Text layer popups?

lissabon at online.de lissabon at online.de
Wed Oct 26 08:20:13 EDT 2011


An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20111026/3e8e7f47/attachment.html
-------------- next part --------------

Hi users-list,

I've not found a solution to this by searching the web yet,:

My problem concernes OpenLayers.Layer.Text layer below an OpenLayers.Layer.Vector layer, trying to trigger the click events on the markers of the Text layer (to be able to open their popups) without deactivating the Vector overlay layer. I've read an article about Vector layer absorbing click events without a good solution IMO.

How can I solve this issue?

I've prepared an example:
There should be 2 files attached.

Alternatively you could proceed with following to achieve the same like the attached files:
Taking the Click event example from here http://openlayers.org/dev/examples/click.html
and replace the complete contents of the script tag with this (don't forget to link to the online version of the OpenLayers.js in the head-tag!):

 var projMercator = new OpenLayers.Projection("EPSG:900913");
 var map = new OpenLayers.Map("map");

 OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
 defaultHandlerOptions: {
 'single': true,
 'double': false,
 'pixelTolerance': 0,
 'stopSingle': false,
 'stopDouble': false
 },

 initialize: function(options) {
 this.handlerOptions = OpenLayers.Util.extend(
 {}, this.defaultHandlerOptions
 );
 OpenLayers.Control.prototype.initialize.apply(
 this, arguments
 ); 
 this.handler = new OpenLayers.Handler.Click(
 this, {
 'click': this.trigger
 }, this.handlerOptions
 );
 }, 

 trigger: function(e) {
 var lonlat = map.getLonLatFromViewPortPx(e.xy);
 alert("You clicked near " + lonlat.lat + " N, " +
 + lonlat.lon + " E");
 }

 });


 function init(){
 map.addControl(new OpenLayers.Control.LayerSwitcher());

 // click handler
 var click = new OpenLayers.Control.Click();
 map.addControl(click);
 click.activate();

 // 1st layer
 map.addLayer(new OpenLayers.Layer.OSM());

 // 2nd layer
 var pois = new OpenLayers.Layer.Text( "My Points",
 {
 location:"./textfile.txt",
 projection: map.displayProjection
 });
 map.addLayer(pois);


 // 3rd layer (vector layer)
 var layerGeometry = new OpenLayers.Layer.Vector(
 "Gebiete",
 {
 strategies: [new OpenLayers.Strategy.Fixed()],
 protocol: new OpenLayers.Protocol.HTTP({
 url: "geom.json",
 format: new OpenLayers.Format.GeoJSON()
 }),
 projection: projMercator
 }
 );
 map.addLayer(layerGeometry);


 var lonLat = new OpenLayers.LonLat( 9.5788, 48.9773 )
 .transform(
 new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
 map.getProjectionObject() // to Spherical Mercator Projection
 );
 var zoom=11;
 map.setCenter (lonLat, zoom); 
 }






Thanks
João



More information about the Users mailing list