Product: MapX
Version: 3.x\4.x
Platform: Not Platform Related
Category: Delphi Code Examples
Summary:
Add points to the map using Delphi.
Question:
How to add points to a map in Delphi?
Answer:
Here is a brief look at how to put points on the map as a layer:
private
VarNewWellLayer, { this will hold a single layer object }
VarNewPoint, { this will hold a feature object }
VarNewTablePoint : Variant; { this will hold reference to the layer.addfeature }
const
samplefile = 'mytest.DBF'; { name of ODBC table }
{
*******************************************
****** function Ex3Click Example 3
****** purpose : Create a layer, create a
****** feature. Will attach itself
****** to the map object, and call
****** fillpoints to create points.
****** Then will set the style.
******
*******************************************
}
procedure TMapView.Ex3Click(Sender: TObject);
begin
OpenMapQry; { a function to get values from a TQuery }
VarNewWellLayer := MyMap.oleobject.layers.CreateLayer('618Wells2',, , 15); { new layer : with a layer name }
VarNewPoint := CreateOLEObject('MapX.Feature.3'); { new feature object }
VarNewPoint.Attach(MyMap.oleobject); { attach it to the map object }
FillPoints; { call the create points function }
VarNewPoint.Type := miFeatureTypeSymbol; { set the symbol for the feature }
VarNewPoint.Style := MyMap.DefaultStyle; { set as default style }
MapQry.Close; { close the query }
end;
{
*******************************************
****** function OpenMapQry
****** purpose : to open the ODBC table and
****** set the pointer to the 1st
****** value
*******************************************
}
procedure TMapView.OpenMapQry;
begin
MapQry.SQL.add('Select * from '+samplefile+''); { build the SQL statement }
MapQry.Open; { Open the query }
MapQry.First; { set the pointer }
end;
{
*******************************************
****** function FillPoints
****** purpose : to create points , using the
****** query as the looping mechanism
******
*******************************************
}
procedure TMapView.FillPoints;
begin
While not MapQry.EOF do begin { until end of table }
VarNewWellLayer.KeyField := 'GEONAME'; { Using this keyfield }
VarNewPoint.Point.Set(MapQry.fieldbyname('Lat').AsFloat,MapQry.Fieldbyname('Lon').AsFloat); { assign lon/lat }
VarNewTablePoint := VarNewWellLayer.AddFeature(VarNewPoint); { Add the feature }
VarNewTablePoint.KeyValue := MapQry.fieldbyname('LOCATION').AsString; { Assign the column in ODBC table }
VarNewTablePoint.Update;
MapQry.Next; { get the next row in ODBC table }
end;
end;
Last Modified: 09/07/2001 08:11:22 AM
|