Composant Delphi / Google Maps / OpenStreetMap / Leaflet  / Mappilary / Native Maps 100% Delphi 0% WebBrowser 0% Javascript

TECShapeLine

you are here :TECNativeMap > Shapes

TECShapeLine allows you to plot a line consisting of a set of points on your card.

The lines are managed by an TECShapeLines list accessible through the property Lines of the TECShapes groups

Fig. 105 A polyline in edit mode

TECShapeline

This class descends from TECShape

It additionally has the following properties

function Add(const Lat, Lng: double; const Alt: double = _ErrorAltitude): integer;

Add a point with potentially altitude

procedure Insert(const index: integer; const Lat, Lng : double; const Alt: double = _ErrorAltitude);

function Add(const dLatLngs: array of double): integer;
Adds an array of points, consisting of a suite of latitudes and longitudes
line.add([lat1,lng1,lat2,lng2,...,latx,lngx]);

Unlike adding a simple point, you do need to manage the addition of your table by BeginUpdate / EndUpdate, is done automatically.

9
Inserts a point with potentially altitude
procedure Reverse
Reverse the direction of the line

property ShowDirection : boolean
Add arrows to each segment to show direction

Fig. 106 ShowDirection

procedure Slice(const StartIndex,EndIndex : integer;Line : TECShapeLine); overload;
Copy the part bounded by the StartIndex and EndIndex segments in Line

function Slice(const StartIndex,EndIndex:integer;GroupName:string=''):TECShapeLine; overload;
Returns a line composed of the portion bounded by the StartIndex and EndIndex segments

procedure Slice(const StartKm,EndKm : double;Line : TECShapeLine); overload;
Copy the part starting at the StartKM kilometre and ending at the EndKM kilometre in Line

function Slice(const StartKm,EndKm : double;GroupName:string=''):TECShapeLine; overload;
Returns a line consisting of the portion commencing at kilometre StartKM and ending at the EndKM kilometre

Fig. 107 slice - red color between 1.2 km and 3.8 kilometer

// red color between 1.2 km and 3.8 kilometer
line := map.shapes.lines[0].Slice(1.2,3.8);
line.Color := claRed;

procedure Clear;

Clears the points

procedure Delete(index: integer);

property Encoded: string ;

Encode / Decode the polyline by using the algorithm of google ( developers.google.com/maps/documentation/utilities/polylinealgorithm )
line.add([lat1,lng1,lat2,lng2,...,latx,lngx]);

property EncodePrecision: byte;

Accuracy of encoding, default 5 decimal places (180.00000 to -180.00000)
Removes a segment of the line

function Count: integer;

Indicates the number of segment

property Weight: byte read FWeight write setWeight;

property BorderSize : integer
Épaisseur de la bordure
property BorderColor : TColor
Couleur de la bordure
property HoverBorderColor : TColor
Couleur de la bordure au survol de la souris

Fig. 108 2 pixel black border

Line thickness

property PenStyle : TPenStyle

stroke type psSolid, psDash, psDot et psDashDot are available
property LineType : TECLineType
Type of line : ltStraight straight line between each point, ltBezier to draw bezier curves

Fig. 109 Penstyle := psDashDot - LineType := ltBezier

procedure getAltitudes(Event: TOnGetAltitude = nil);

Calculates the altitudes of the points, you can pass a procedure of type TOnGetAltitude to display a progress bar (see DemoNativeRoute)

// Delphi map component ECMap

// calcul altitude for all point of polyline 0
// you can pass nil if you don't show a progressbar
map.Shapes.Lines[0].GetAltitudes(doGetAltitude);
...
{*
event fired by getAltitudes

@param Sender TECShapeLine
@param Total number of altitude's point calculated
@cancel flag for abort calcul
}
procedure TFDemoRoute.doOnGetAltitude(Sender: TECShapeLine;const Total:integer;var cancel:boolean);
begin
ProgressAltitude.Position := total;
// cancel if press button
cancel := btAbortAlt.tag = -1;
end;

function getLatLngFromMeter(const SensStartEnd: boolean;
const lMeter: longint; var dLatitude, dLongitude: double;
var idPoint: integer; var Heading: integer; var bEnd: boolean): boolean;

Calculates the latitude and longitude of a point on the line/polygon based on its distance in metres, returns True if a point was found

SensStartEnd meaning of the course, true for departure -> arrival

lMeter the distance in metres

dLatitude,dLongitude variables of type double who will receive the latitude and longitude

idPoint a variable that will contain the index in the array Path where is located the point, the calculation returns an approximation because your polyline/polygon has all of the actual points

Heading a variable that will contain the angle of the point relative to the North (from 0 to 360 °)

bEnd indicates whether one has reached or exceeded the end of polyline/polygone(or early depending on the direction)

property HoverPoint: integer read FHOverSeg;

Index of the segment pointed by the mouse

property Path[index: integer]: TECPointLine

Array containing all the points of the line

function Distance : double;

Indicates the total distance (km) of the line

property Duration : integer;

If the row represents a route (route) indicates the duration of the trip.

property NorthEastLatitude: double

Latitude of the upper right corner of the box enclosing the line

property NorthEastLongitude: double

Longitude of the upper-right corner of the box enclosing the line

property SouthWestLatitude: double

Latitude of the lower left corner of the box enclosing the line

property SouthWestLongitude: double

Longitude Latitude from the lower left of the box enclosing the line

// Delphi map component ECMap

line := map.Shapes.Lines[0];

// show the entire line
map.fitBounds(line.NorthEastLatitude,line.NorthEastLongitude,line.SouthWestLatitude,line.SouthWestLongitude);

property ShowText : boolean
If the row represents a road displays the intermediate points

property Editable : boolean

property Shapes : TECShapes

If the row represents a road provides access to the forms that indicate the steps

The departure and arrival points are represented by TECShapePOI, the other intermediate points are TECShapeMarker

The example below enables to change the display of the points of departure and arrival.

// Delphi map component ECMap
// change default poi start and finish of route
var line : TECShapeLine;
...
line := map.shapes.lines[0];

if line.shapes.Pois.count>1 then
begin
i := line.shapes.markers.add(line.shapes.pois[0].latitude,line.shapes.pois[ 0].longitude);
line.shapes.markers[i].filename := 'http://www.helpandweb.com/flag_blue.png';
line.shapes.markers[i].hint := line.shapes.pois[0].hint;

i := line.shapes.markers.add(line.shapes.pois[line.shapes.Pois.count- 1].latitude,line.shapes.pois[line.shapes.Pois.count- 1].longitude);
line.shapes.markers[i].XAnchor := 0;
line.shapes.markers[i].filename := 'http://www.helpandweb.com/checkered_flag.png';

line.shapes.markers[i].hint := line.shapes.pois[line.shapes.Pois.count-1].hint;

// hide default start and finish
line.shapes.pois[0].visible := false;
line.shapes.pois[line.shapes.Pois.count-1].visible := false;
end;

Fig. 110 Adding flags for the departure and arrival

property Editable : boolean
Makes it editable line, removes it a double click on a point, a double click on a segment adds a point, the points are Draggable mouse

This allows that straight paths, to modify a route it takes just 2-3 lines of additional code.

91

By default the selection points are represented by a black square to the starting point, a white square to the end point and a white circle for the intermediate points.

Fig. 111 Edit line

Use the properties FilenameStartEditLine, FilenameEndEditLine, FilenamePointEditLine of your map to change the bitmaps

// Reverse the point of departure and arrival
s := map.FilenameStartEditLine;
map.FilenameStartEditLine := map.FilenameEndEditLine;
map.FilenameEndEditLine := s;

You can change the creation of the selection points using the property OnCreateShapeLinePoint

line := map.add(nsLine,Lat,Lng);

// change défault point
line.OnCreateShapeLinePoint := doCreateShapeLinePointEditable;


procedure TForm1.doCreateShapeLinePointEditable(sender: TObject; const Group:TECShapes;
var ShapeLinePoint: TECShape;
const Lat,Lng:double;const index:integer);
var i:integer;
poi:TECShapePOI;
begin

i := Group.Pois.add(lat,Lng);
Poi := Group.Pois[i];

ShapeLinePoint := poi;

poi.Width := 10;
poi.Height:= 10;

poi.POIShape := poiRect;

poi.Color := claWhite;
poi.HoverColor := claWhite;
poi.BorderColor := claBlack;
poi.HoverBorderColor:= claBlack;

end;



Fig. 112 Changing the appearance of a TECShapeLine points

property OnShapePathChange : TNotifyEvent

To be informed when the line changes.

Save moving

The purpose of this example is to save its movement in a TECShapeLine, a triangle pointing in the direction of the displacement will indicate the current position.

var MyLocationShape : TECShapePOI;
MyLocationLine : TECShapeLine;

procedure TForm1.FormCreate;
begin
// create triangle
MyLocationShape := map.AddPoi(0, 0);
MyLocationShape.POIShape := poiTriangle;
MyLocationShape.Width := 18;
MyLocationShape.height := 24;
MyLocationShape.YAnchor := 0 ;
MyLocationShape.visible := false;
end;

// Connect this to your TLocationSensor.OnLocationChanged
// save your location in a TECShapeLine
procedure TForm1.LocationSensorLocationChanged(Sender: TObject;
const OldLocation, NewLocation: TLocationCoord2D);

begin

map.beginupdate;

// create new line if not assigned
if not assigned(MyLocationLine) then
begin
MyLocationLine := map.AddLine(NewLocation.Latitude, NewLocation.Longitude,
'mylocations');
MyLocationLine.weight := 4;
MyLocationLine.Color := GetRandomColor;

// add border
MyLocationLine.BorderSize := 2;
MyLocationLine.BorderColor := GetShadowColorBy(MyLocationLine.Color, 32);

end

else

MyLocationLine.add(NewLocation.Latitude, NewLocation.Longitude);


MyLocationShape.SetDirection(NewLocation.Latitude, NewLocation.Longitude);

MyLocationShape.visible := true;

// center on your position
map.setCenter(NewLocation.Latitude, NewLocation.Longitude);

map.endupdate;

end;

Weather

By using the services of OpenWeatherMap.org you can view the weather along your TECShapeLine.

Fig. 113 Weather on the road

You first need to get a key to use the api of OpenWeatherMap

map.OpenWeather.Key := your_key;

// Get the weather along a TECShapeLine
Line.ShowWeather := true;

See the RouteWeather demo for more information on how to use the api of OpenWeatherMap.

go to page
© 2016 ESCOT-SEP Christophe - Made width Help&Web - RSS - Google+