Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Contributor
Posts: 44
Registered: ‎10-27-2015

Coordinate readout on mouse click

Hi All,

 

 

does anybody knows how can I get current coordinates on mouse click using Portal API?

Any other way than this?

 

$(".wc_map_coords").find("input")[0].value

$(".wc_map_coords").find("input")[1].value

 

Any help is much appreciated

 

var cursorX;
var cursorY;

$GP.ready("v1.0", function () {
	document.addEventListener('mousemove', function(e){ 
	cursorX = e.pageX;
        cursorY = e.pageY;
	});

 	$GP.ui.toolbar.add({
		categoryIndex: 0,
		xtype: "tbbutton",
		text: "Coordinate Readout",
		handler: function (a) {
			$GP.map.draw({
				"type": "Point" 
			}, function (r) {
				showToolTip();
				$GP.map.draw.clear();
			}); 
		}
	}); 
)};

function showToolTip () {
	lat = ParseDMS($(".wc_map_coords").find("input")[0].value);
	lon = ParseDMS($(".wc_map_coords").find("input")[1].value);
	$GP.crs.transform(
		{   sourceCrsId: $GP.crs.getCurrent(), 
			targetCrsId: "EPSG:27700",
			points:[{x: lat, y:lon}]
		},
		function (result) {
			easting = result.points[0].x;
			northing = result.points[0].y;
			tooltipText = '<table>'+
			       '<tr><td>Latitude: '+lat+'</td></tr>'+
				   '<tr><td>Longitude: '+lon+'</td></tr>'+
				   '<tr><td>Easting: '+easting+'</td></tr>'+
				   '<tr><td>Northing: '+northing+'</td></tr>'+
				   '</table>';
			tooltip = new Ext.Tip({
				target: $(".map"),
				html: tooltipText,
				autoShow: true,
				autoScroll: true,
				focusOnToFront: true,
				autoHide: true,
				closable: true
			});
			tooltip.showAt([cursorX, cursorY]);
		}
	);	
}

 

Thank you in advance.

Denis

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.