home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


SpyGlassVector.sml

See other examples and scripts with DataTips and GraphTips ...


## SpyGlassVector.sml

# Sample Display Control Script for SpyGlass Vector GraphTip
#
# Group must have a raster object as the first layer.
# Script creates a circular GraphTip showing the matching
# area (centered on the mouse cursor) from a vector object in a 
# Project File.  The matching area is extracted from the vector
# object and added / removed as a layer in the group at each
# DataTip event to provide GraphTip behavior.

# Authors: 	Jeremy Johnson, Randy Smith
#				MicroImages, Inc.
#				10 December 2004

class VECTOR SourceVector, MaskVector, ExtractedVector;
class GRE_LAYER_RASTER F_layer;
class RASTER F;
numeric height, width;
numeric count = 0; 
class POINT2D LayerPoint, MapPoint, SourceMapPoint, SourceObjPoint;
class RVC_GEOREFERENCE SourceVecGeo, FGeo;
class TRANSPARM ScreenToLayer, FMapToSourceMap;
class TRANSPARM FObjToMap, SourceMapToObj;
class POLYLINE shape;
class GRE_GROUP global_group;
class GRE_LAYER VectLayer, TestLayer;

########################################################
#  Procedure to remove previous vector layer if it exists
########################################################
func RemoveVectorLayer () {
	local numeric removed = 0;
	if (VectLayer.Name != "") {
		TestLayer = global_group.FirstLayer;

		while (removed == 0) {
			if (TestLayer.Name == "") {
				removed = 1;
				continue;
			}
			if (TestLayer.Name == VectLayer.Name) {
				global_group.RemoveLayer(TestLayer);
				removed = 2;
			}
		TestLayer = TestLayer.NextLayer;
		}
	}
	return removed;
}


##########################################################################
#  Procedure called when view is created for the group.
#
#	Gets handle for the raster object in the group's first layer.
#	This raster (F) will be used for establising a translation between the 
#	coordinates of the mouse and the map coordinates of the desired location
#  to be displayed in the GraphTip's view circle. 
##########################################################################
proc OnGroupCreateView ( 
	class GRE_GROUP group
	) {
		global_group = group;
		F_layer = group.FirstLayer; 
 		DispGetRasterFromLayer(F, F_layer);
		# file with source vector object for GraphTip should be in same directory as control script
		OpenVector(SourceVector, _context.ScriptDir + "\\cb_soils.rvc", "CBSOILS");
}

##########################################################################
#  Function called when the mouse is left over a position.
#  This is the primary function for creating and displaying the GraphTip. 
##########################################################################
func OnViewDataTipShowRequest (
	class GRE_VIEW view,
	class POINT2D point,
	class TOOLTIP datatip
	) {

	# call procedure to remove previous vector layer if it exists
	local numeric removed = RemoveVectorLayer();
	if (removed == 2) then						# only redraw if a vector layer was actually removed
		view.RedrawDirect("NoBlankScreen");

	# get transparm from screen coordinates to raster layer coordinates
	ScreenToLayer = view.GetTransLayerToScreen(F_layer, 1);

	# transform cursor screen coordinates to object coordinates of raster that is first layer in group
	LayerPoint  = ScreenToLayer.ConvertPoint2DFwd(point); 

	if (!IsNull( F[LayerPoint.y, LayerPoint.x] )) {		# only show GraphTip when cursor is over non-null cell in raster

		CreateTempVector(MaskVector, "VectorToolkit,Polygonal"); # vector to draw circle in for extraction
		CopySubobjects(SourceVector, MaskVector, "GEOREF");
		CreateTempVector(ExtractedVector);


		###############################################
		# Set up projection transformations
		###############################################
		SourceVecGeo.OpenLastUsed(SourceVector);
		SourceVecGeo.GetTransparm(SourceMapToObj, 1, SourceVecGeo.GetCalibModel() );
		FMapToSourceMap.OutputCoordRefSys = SourceVecGeo.GetCoordRefSys();
		FGeo.OpenLastUsed(F);
		FGeo.GetTransparm(FObjToMap, 0, FGeo.GetCalibModel() );
		FMapToSourceMap.InputCoordRefSys = FGeo.GetCoordRefSys();

		MapPoint = TransPoint2D(LayerPoint, FObjToMap); # convert cursor position to map coordinates of displayed raster
		SourceMapPoint = FMapToSourceMap.ConvertPoint2dFwd(MapPoint); # convert raster map coordinates to map coordinates of source vector

		SourceObjPoint = TransPoint2D(SourceMapPoint, SourceMapToObj); # convert to object coordinates of source & mask vector

		###############################################
		# draw circular polygon to use as extraction area
		###############################################
		point =SourceObjPoint;
		shape.Clear();				# clear previous polyline

		local class POINT2D circlepoint;		# class instance for computed vertex position on circumference of circle
		local numeric x, y;
		local numeric radius = 200;			# radius of circle in source object coordinates
		local numeric r2 = radius * radius;

		# Create top half of circle and add to polyline
		for (x = -radius; x <= radius; x++) {
			y = sqrt((r2 - x*x) +0.5);
			circlepoint.x = point.x + x;
			circlepoint.y = point.y + y;
			shape.AppendVertex(circlepoint);

		} 
		# Create bottom of circle and add to polyline
		for (x = radius; x >= -radius; x--) {
			y = sqrt((r2 - x*x) +0.5);
			circlepoint.x = point.x +x;
			circlepoint.y = point.y -y;
			shape.AppendVertex(circlepoint);
		}

		# Close polyline and add it as element to the Mask Vector to use for extraction
		shape.SetClosed(1);
		VectorAddPolyLine(MaskVector, shape);

		# Extract circular area from source vector and add result as layer in group
		ExtractedVector = VectorExtract(MaskVector, SourceVector, "InsideClip");
		VectLayer = GroupQuickAddVectorVar(global_group, ExtractedVector);
		view.RedrawDirect("NoBlankScreen");
		return (1); 
		}
	}





Back Home ©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010   USA
Business & Sales: (402)477-9554  Support: (402)477-9562  Fax: (402)477-9559
Business info@microimages.com  Support support@microimages.com  Web webmaster@microimages.com

25 March 2009

page update: 26 May 11