Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

WebGmaps Polygon.Center and Show label in Polygon

 Post Reply Post Reply
Author
Pinarbasi Berk View Drop Down
New Member
New Member
Avatar

Joined: 12 Oct 2018
Posts: 12
Post Options Post Options   Quote Pinarbasi Berk Quote  Post ReplyReply Direct Link To This Post Topic: WebGmaps Polygon.Center and Show label in Polygon
    Posted: 12 Oct 2018 at 9:48am
Hi,
version: 2.9.9.0

I create polygon(ptPath) with this code.
var
  Circle: TMapPolygon;
  PolygonItem: TPolygonItem;
begin
  PolygonItem := WebGMaps1.Polygons.Add;
  Circle := PolygonItem.Polygon;
  Circle.PolygonType := ptPath;
  Circle.Clickable := False;
  Circle.TagString := '888';
  Circle.Path.Add(39.9651599353384,32.7510797299922);
  Circle.Path.Add(39.965073594233,32.7520292319834);
  Circle.Path.Add(39.9644650919221,32.7519809522212);
  Circle.Path.Add(39.9645596568259,32.7509402551234);
  Circle.BackgroundOpacity := 40;
  Circle.BorderWidth := 2;
  WebGMaps1.CreateMapPolygon(Circle);
  
  
 Question 1)
I want to write a text center of this polygon. TagString is shown only mouse enter the polygon and it has to "Circle.Clickable := True".
But I use it mobile platforms and want to see TagString(or any text) in center of polygon for everytime, not only mouse action.
How can I do this?
 Question 2
I tried to run time create a label in polygon in WebGmaps. But it doesnt appear in WebGmaps.
Is it possible to create an object in WebGmaps?
 Question 3
When I use Polygon.Center paramater, it goes different location.
WebGMaps1.MapPanTo(WebGMaps1.Polygons[0].Polygon.Center.Latitude,WebGMaps1.Polygons[0].Polygon.Center.Longitude);
You can test this code with my polygon create codes.
Back to Top
Bart Holvoet View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2051
Post Options Post Options   Quote Bart Holvoet Quote  Post ReplyReply Direct Link To This Post Posted: 15 Oct 2018 at 11:41am
Hi,

1) Note that it's currently not supported to display a text on the map for a Polygon object.
As an alternative you can add a marker at the location you wan the text to be displayed and use the MapLabel.Text property of the marker.

2) It's not supported to create custom objects inside the WebGMaps control.

3) Please note that the Center property only applies to Polygon objects of type ptCiricle. The Center value is not used for Polygon objects of type ptPath.
Back to Top
Pinarbasi Berk View Drop Down
New Member
New Member
Avatar

Joined: 12 Oct 2018
Posts: 12
Post Options Post Options   Quote Pinarbasi Berk Quote  Post ReplyReply Direct Link To This Post Posted: 16 Oct 2018 at 1:47am
Thanks for your answers.

1) Its a good idea but displayed text is in a popup window. It can cause problems working in confined space. 

2) I found a solution about this question. Yes, we can not create FMX object but we can add JS object.
https://github.com/googlemaps/js-map-label  -> Here is  a small code for drawing a text.
I add  
'<script src="http://botnetsystem.com/seha/maplabel.js"></script>'  + #13 +
in FMX.TMSWebGMapsConst.pas and here are my codes
S := 'var mapLabel = new MapLabel({' + #13 +
          'text: ''Test'',   ' + #13 +
          'position: new google.maps.LatLng(40.1298497154071, 32.3969666080478),  ' + #13 +
          'map: map,' + #13 +
          'minZoom: 14,' + #13 +// when zoom upper 14, it shows
          'fontSize: 35,' + #13 +
          'align: ''right''' + #13 +
        '});' + #13 +
        'mapLabel.set(''position'', new google.maps.LatLng(40.1298497154071, 32.3969666080478));'   ;
 

  WebGMaps1.ExecJScript(s);
Until here, everything is OK, but I dont know how i can remove created label.

3) Sad news. Thanks.
Back to Top
Bart Holvoet View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2051
Post Options Post Options   Quote Bart Holvoet Quote  Post ReplyReply Direct Link To This Post Posted: 16 Oct 2018 at 8:39am
1) Please note that the when using the MapLabel.Text property the text is displayed in a label on the map rather than a popup.

3) If you need the center coordinate of a Polygon you can use the GetPolygonCenter call.
Back to Top
Pinarbasi Berk View Drop Down
New Member
New Member
Avatar

Joined: 12 Oct 2018
Posts: 12
Post Options Post Options   Quote Pinarbasi Berk Quote  Post ReplyReply Direct Link To This Post Posted: 17 Oct 2018 at 10:48pm
When I use it
procedure TForm1.WebGMaps1PolygonClick(Sender: TObject; IdPolygon: Integer);
tmpLat,tmpLon:Double;
begin
ShowMessage(WebGMaps1.GetPolygonCenter(IdPolygon,tmpLat,tmpLon));
end;

I get error(implement invoke script) and app crash.
Back to Top
Bart Holvoet View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2051
Post Options Post Options   Quote Bart Holvoet Quote  Post ReplyReply Direct Link To This Post Posted: 18 Oct 2018 at 8:51am
Sorry for the confusion.
Unfortunately the GetPolygonCenter call is currently only supported for TMS VCL WebGMaps.
We'll have to investigate if this can be supported in a future version of of TMS FMX WebGMaps.


Edited by Bart Holvoet - 18 Oct 2018 at 8:51am
Back to Top
Pinarbasi Berk View Drop Down
New Member
New Member
Avatar

Joined: 12 Oct 2018
Posts: 12
Post Options Post Options   Quote Pinarbasi Berk Quote  Post ReplyReply Direct Link To This Post Posted: 18 Oct 2018 at 1:31pm
Again sad news.

If I use WebGMaps1.XYToLonLat, I can calculate center of polygon by Delphi code. But, it seen impossible, now.

Without these functions- XYToLonLat, LotLatToXY, GetPolygonCenter - component is not effective.
Back to Top
Pinarbasi Berk View Drop Down
New Member
New Member
Avatar

Joined: 12 Oct 2018
Posts: 12
Post Options Post Options   Quote Pinarbasi Berk Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jan 2019 at 5:55pm
I created a helper unit for polygon center and label.

Here is unit 
and you have to add in "WebGMaps1InitHTML"

  html := HTML +'<script type="text/javascript" src="http://sehacbs.com/seha/maplabel.js"></script>' + #13 +
                '<script type="text/javascript" src="http://sehacbs.com/seha/leaflet.js"></script>';
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down