[OpenLayers-Users] RE Getfeature info without click

adityakumar529 adityakumar529 at gmail.com
Thu May 23 06:04:38 PDT 2013


HI Steve,
I tried bit could not make it.
Following is the code I am using
 function codeAddress() {
	geocoder = new google.maps.Geocoder();
	var address = document.getElementById("address").value;    
	geocoder.geocode({ 'address': address }, function (results, status) {
	    if (status == google.maps.GeocoderStatus.OK){    
		lonlat = results[0].geometry.location;    
		//alert(latlong);	
		var roadidPicker = new OpenLayers.Control.WMSGetFeatureInfo({
		    url: 'http://localhost:8080/geoserver/aditya/wms',		
		    title: 'identify features on click',
		    queryVisible: true,
		});
		roadidPicker.infoFormat = 'application/vnd.ogc.gml';
		roadidPicker.events.register("getfeatureinfo", this, pickRoadid);
		map.addControl(roadidPicker);
		roadidPicker.activate();
		//map.setCenter(lonlat, 5);
		var lat = results[0].geometry.location.lat();
		alert(lat);
		var lng = results[0].geometry.location.lng();
		alert(lng);
		vectorLayer.removeAllFeatures();		
		var proj = new OpenLayers.Projection("EPSG:4326");
		var point = new OpenLayers.LonLat(lonlat);
		point.transform(proj,  map.getProjectionObject());	
		markers.clearMarkers();
		var size = new OpenLayers.Size(21,25);
		var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
		var icon = new
OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png',size,offset);                            
		markers.addMarker(new OpenLayers.Marker(new
OpenLayers.LonLat(lng,lat).transform(WGS84, WGS84_google_mercator),icon));					  
		map.setCenter(new OpenLayers.LonLat(lng,lat).transform(WGS84,
WGS84_google_mercator), 20);
		var point1 = new OpenLayers.Geometry.Point(lng,lat).transform(WGS84,
WGS84_google_mercator);
		var feature1 =  new OpenLayers.Feature.Vector(point1);
		vectorLayer.addFeatures([feature1]);
		console.log(results[0].geometry.location);
		
		
	    }
	    else {
		console.log("Geocoding failed: " + status);                            
	    }
	});
    }
    // search ends
</script>

<script type="text/javascript">
    function pickRoadid(e) {	
	var val = e.features[0].attributes.ward_name;
	alert('pickRoadid');
	alert(val);
	//alert('ward_namehihi: '+val);
	if (e.features && e.features.length) {
	    var ward_no = e.features[0].attributes.ward_no;
	    alert(ward_no);
	    return ward_no;
	}
	return val;
    }



-----
GIS Developer
India Urban Space Foundation
--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Getfeature-info-without-click-tp5055234p5055252.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.


More information about the Users mailing list