Problem Shapes with Images (GPX base map) no databases in Delphi XE3 version 4.9.3.1

Jan 8, 2015 at 3:05 PM
Edited Jan 8, 2015 at 3:30 PM
My idea is create icons clickables into map at a coordenate.
First load a gpx file into Map component (hangs in Windows XP). The stretch draws correctly. All right,
Now I have a TImageList (component with a lot of images loaded), 2 TClientDataSet (midas for access sql remote data) and I am going populating the stretch with icons, images, labels, etc.
But.... anything shows in the map!.
I've created Categories, IconManager, in many ways.
I need help for corroborate I am doing all right

Ex.:
procedure GeneratePoint(path: String; Elem, Detail: TClientDataSet);
var mapHandle, shapeHandle: integer;
      point: Ipoint;
      sf: IShapeFile;
      shape: IShape;
      index: integer;
begin
  Map1.LockWindow(lmLock);
  Map1.RemoveAllLayers;
  mapHandler := Map1.AddLayerFromFilename(path, fosAutodetect, True);  //a gpx file. Hangs in XP
  Map1.LayerName[mapHandle] := path;
  Map1.LayerVisible[mapHandle] := True;
  // It's all right at here. The map appear.
  point := CoPoint.Create;
  sf := CoShapefile.Create;
  sf.CreateNew('', SHP_POINT);
  sf.DefaultDrawingOptions.AlignPictureByBottom := false;
  CreateCategories(sf, Elem);  

  Detail.First;
  while not Detail.Eof do begin
      Elem.Locate('ID_', Detail['ELEM_ID'],[]);
      index   := 0;
      point.x := Detail['X'];
      point.y := Detail['Y'];
      shape := CoShape.Create;
      if not shape.Create(SHP_POINT) then
        ShowMessage(shape.ErrorMsg[shape.LastErrorCode]);
      if not shape.InsertPoint(point, index)then
        ShowMessage(shape.ErrorMsg[shape.LastErrorCode]);
      if not sf.EditInsertShape(shape, index) then
        ShowMessage(sf.ErrorMsg[sf.LastErrorCode]);
      sf.ShapeCategory[sf.NumShapes] := Elem['ID_']-1;  //Fails. Assign -1
      sf.DefaultDrawingOptions.SetDefaultPointSymbol(dpsFlag);
      sf.CollisionMode := AllowCollisions;

      if sf.GenerateLabels(0, lpCentroid, True) > 0 then
        sf.Labels.Label_[0, 0].Text := 'some text';

      Detail.Next;
    end;
  shapeHandle := Map1.AddLayer(sf, true);
  if shapeHandle = -1 then
     ShowMessage(Map1.ErrorMsg[Map1.LastErrorCode]);
  Map1.LockWindow(lmUnlock);
  Map1.CursorMode := cmNone;
  Map1.MapCursor  := crsrArrow;
  Map1.Redraw;
  Map1.ZoomToLayer(mapHandle);
end;

procedure CreateCategories(var sf: IShapeFile, Elem: TClientDataSet)
var i: TMapIconType;
    category: IShapefileCategory;
begin
  for I := 1 to 20 do begin
    Elem.Locate('ID_', I,[]);
    category := sf.Categories.Add(Elem['NAME']);
    category.DrawingOptions.PointType := ptSymbolPicture;
    category.DrawingOptions.Picture   := IconManager.getIcon(I-1);
   //IconManager is a class with 20 bmp loaded in a IImage collection
  end;
end
Developer
Jan 9, 2015 at 6:49 AM
Hi, you are right about the hangings on WinXP after all. I tested gpx format on VM and it hangs indeed. I already committed a fix. We shall release a new installer with the fix soon. Thanks for reporting this.

Regarding the code, I see a problem in this line:
sf.ShapeCategory[sf.NumShapes] := Elem['ID_']-1;  //Fails. Assign -1
The last shape in shapefile always has an index sf.NumShapes -1, since the the indices are 0-based. You can also use index variable from sf.EditInsertShape(shape, index) call. It's passed by reference and will hold the correct index for the inserted shape.

Regards,
Sergei
Jan 9, 2015 at 10:34 AM
Edited Jan 9, 2015 at 10:51 AM
Hi Sergei.
And I realized.... about the zero-index.
I'm resolving slow.
1.- IShapeFileCategory.DrawingOptions.Picture doesn't support bmp files. With png works!
2.- In the code above, only shows the last shape added to shapefile.... Is there any property hidden when a shape is added, previous are set invisibles?
3.- IshapeFile.GenerateLabels doesn´t create de Labels collection. How can I add labels at image bottom's? ... because de AddLabel method from Labels collection demand or request x and y coordenates, unknowed when painting the image...
4.- When zoom (in or out) the points added and images disappear. Must be rebuilt all layers?
5.- How detect OnMouseWheel?
Developer
Jan 9, 2015 at 3:00 PM
Edited Jan 9, 2015 at 3:15 PM
1 - bmp icons are working for me; however it's possible that there may be problems with particular files; perhaps resaving with another bitmap editor may help;
2 - you are creating a point outside cycle;
3- you haven't added any fields to shapefile as far as I can tell; see labels samples here;
4 - no, you shouldn't rebuild your layer after each zooming; try to handle map.ExtentsChanged and check that your shapefile is still there (map.get_Shapefile(shapeHandle)) and shapes are visible (Shapefile.ShapeVisible);
5 - there is no such event, you can either handle map.ExtentsChanged (wheeling usually changes extents) or intercept windows message in your form.
Coordinator
Jan 10, 2015 at 12:19 PM
The new release Sergei is talking about is downloadable for a short while at http://www.mapwindow.org/tmp/MapWinGIS-only-v4.9.3.3-Win32.exe
Please test it and let us know if it solves your problems with gpx on WinXP.
If you can confirm I'll publish the new version.

And try to create a new post for new questions. As a guideline: if the title of the post does not match your question you should create a new post.

Thanks,

Paul
Jan 10, 2015 at 1:30 PM
Edited Jan 10, 2015 at 1:31 PM
Hi Paul.

I've installated new version and works fine in XP for loading GPX file with AddLayerFromFilename method..... but, now draws points and not the trace ....
                                                                                                     .
                                                                                                    .
                                                                                                 .
                                                                                            . . .
                                                                                        . .
                                                                               . .    .
                                                                             .
                                                                         . . 
                                                                              .
                                                                                  . .
                                                                                      .
The lyne not appear.... (¿?)
Jan 10, 2015 at 1:41 PM
Hi Seriozha.
(2) I'm drawing points in the cycle.
Each new point is showed with its image whe it's the last one.
When a new point is the last, it's showed, and all others are not painted... but their labels are shown.
(3) I don`t use any field, only draws over the map. No database ... or it requires alike to use fields?? fields from where?
Remember I am not using SHP, only GPX, without anymore data. All extra data writes my application over the map each time.
(4) putting ZoomToLayer resolve the problem. ZoomToMaxExtents eliminates all
(5) Ok. I caught OnMouseWheel from the form and trigger the zoomIn or zoomOut...
Developer
Jan 10, 2015 at 2:54 PM
Edited Jan 10, 2015 at 3:08 PM
2) point := CoPoint.Create; should be inside cycle, otherwise all your shapes are using the same point instance, and with each new iteration you overwrite old positions;
3) sf.GenerateLabels(0, lpCentroid, True) makes sense only if you have fields; it's ok to use sf.Labels.Label[].Text = "" but then GenerateLabels isn't necessary;
4) try to check what sf.Extents.ToDebugString() returns;
Developer
Jan 10, 2015 at 3:26 PM
Regarding missing trace: gpx file can have several layers. It seems that only the first layer is opened now. I tested new installer, and all layers are still opened for me. As a workaround try to use:
var ds = new OgrDatasource();
if (ds.Open(path))
{
    for (int i = 0; i < ds.LayerCount; i++)
    {
        var layer = ds.GetLayer(i);
        Map1.AddLayer(layer, true);
    }
}
Jan 10, 2015 at 3:26 PM
Thanks Serguei.

point was the problem.Resolved!
And about images.... each new image adds at 0 index of shapeFile.ShapeCategory, and not at end.... That's all!!.
Close post
Jan 10, 2015 at 3:29 PM
Ok. I must probate searching the appropiate layer ....
Coordinator
Jan 11, 2015 at 3:11 PM
I've just published v4.9.3.3 (https://mapwingis.codeplex.com/releases/view/541892) with the patch made by Sergei.

Please post new questions in a new post.

Thanks,

Paul
Marked as answer by pmeems on 1/11/2015 at 8:12 AM