[OpenLayers-Users] Start edge and end edge from Popup

carlofrancesco gentuser at gmail.com
Fri Dec 11 08:00:36 EST 2009


Hi all. I'm new to this beautiful openLayer. What I am doing i simple: using
openlayer + pgrouting.
My question is this: I want to set over the map a Start Point and an End
Point to pass to pgrouting from a popup. I'll explain better.
I'm using the code shown here :
http://pgrouting.postlbs.org/wiki/Workshop-RoutingRequest

In detail iìll focus on:

var SinglePoint = OpenLayers.Class.create(); 
        SinglePoint.prototype =
OpenLayers.Class.inherit(OpenLayers.Handler.Point, { 
            createFeature: function(evt) { 
               
this.control.layer.removeFeatures(this.control.layer.features); 
                OpenLayers.Handler.Point.prototype.createFeature.apply(this,
arguments); 
            } 
        }); 

            // controls 
            controls = { 
              start: new OpenLayers.Control.DrawFeature(start, SinglePoint), 
              stop: new OpenLayers.Control.DrawFeature(stop, SinglePoint) 
            } 
            for (var key in controls) { 
                map.addControl(controls[key]); 
            } 
        } 

        function toggleControl(element) { 
            for (key in controls) { 
                if (element.value == key && element.checked) { 
                    controls[key].activate(); 
                } else { 
                    controls[key].deactivate(); 
                } 
            } 
        } 



This code works very well, i put start point and end point, i click on
compute and it trace the path. All perfect.

But now i want to create a search form like google map, clicking on one
result and create a popup that show me name of the street and "start from
here" , and "arrive here", same of google map.

So i wrote this code: 

function displayViaOnMap(response){
		 if (response && response.responseXML) {
		 via_selezionata.removeFeatures(via_selezionata.features);
		 // parse the features
                edges = response.responseXML.getElementsByTagName('edge');
                var features = [];	

                for (var i = 0; i < edges.length; i++) {
                    var gid,street,fromleft, toleft, fromright, toright;
                       
gid=edges[i].getElementsByTagName('id')[0].textContent;
                       
street=edges[i].getElementsByTagName('street')[0].textContent;
                       
comune=edges[i].getElementsByTagName('comune')[0].textContent;
                       
/*fromleft=edges[i].getElementsByTagName('fromleft')[0].textContent;
                       
toleft=edges[i].getElementsByTagName('toleft')[0].textContent;
                       
fromright=edges[i].getElementsByTagName('fromright')[0].textContent;
                       
toright=edges[i].getElementsByTagName('toright')[0].textContent;    */                    
                        var g =
parser.read(edges[i].getElementsByTagName('wkt')[0].textContent);

                        // non va bene features.push(new
OpenLayers.Feature.Vector(g));
                        features.push(g);		
                } 
		//questo inserisce all'interno del vettore via le features appena trovate
		 via_selezionata.addFeatures(features);
		 createPopup(features[0],street,comune);
		
            }
	}
	
function createPopup(feature,street,comune) {
	
	//rimuovo gli altri popup
       if(map.popups.length>0){rimuoviPopups();}
	var center= feature.geometry.getBounds().getCenterLonLat();	
	var popup_info =  "" + street +
                        "<br>Comune: " + comune +
                        "<br>a href='javascript:setStart("+center+")' >Parti
da qui /a" +
                        "<br>a href='javascript:setStop("+center+")' >Arriva
qui /a" + 
                        "";

        popup = new OpenLayers.Popup.AnchoredBubble("ViaInfo",
                                        center,
                                        new OpenLayers.Size(200,100),
                                        popup_info,
                                        null,
                                        true);
                                      
        popup.setBackgroundColor("#bcd2ee");            
        popup.setOpacity(.85);
        map.addPopup(popup);   
        //mi centro la mappa sulla mia nuvolletta
        map.setCenter(center, zoomz+1);    

}


 function rimuoviPopups() {   
     while( map.popups.length ) {
        map.removePopup(map.popups[0]);
     }

  }
function setStart(x,y){

}
function setStop(x,y){

}


Now i need an help to create function setStart and setStop point.  How i can
Initialize SinglePoint defined as an Handler Point to a Point on the map
like

	var point = new OpenLayers.Geometry.Point(x,y);
where x,y is coordinate of  feature.geometry.getBounds().getCenterLonLat();
Thanks for any advice !! 
-- 
View this message in context: http://n2.nabble.com/Start-edge-and-end-edge-from-Popup-tp4151122p4151122.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list