User Tools

Site Tools


thinkgeo_desktop_for_wpf_all_samples

Wpf Samples

# Quickstart Sample for WPF

### Description This Quickstart Sample will guide you through the process of creating a sample application and will help you become familiar with creating maps with ThinkGeo UI. This sample project supports ThinkGeo UI 12.0.0.0 and higher and will show you how to create a WPF application using the ThinkGeo UI Desktop for WPF control.

Quick Start Video: - [ThinkGeo UI WPF Quick Start in VS Code - Part 1 - Basemap](https://youtu.be/1PkOsPyXeUM) - [ThinkGeo UI WPF Quick Start in VS Code - Part 2 - Adding a ShapeFile](https://youtu.be/7U31kP1E_fs)

Please refer to our [Wiki](https://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for more details.

![Screenshot](https://github.com/ThinkGeo/QuickstartSample-forWpf.NetCore/blob/master/Screenshot.png)

### About the Code ```csharp ShapeFileFeatureLayer capitalLabelLayer = new ShapeFileFeatureLayer(@“../../Data/WorldCapitals.shp”); GeoFont font = new GeoFont(“Arial”, 9, DrawingFontStyles.Bold); GeoSolidBrush txtBrush = new GeoSolidBrush(GeoColor.StandardColors.Maroon); TextStyle textStyle = new TextStyle(“CITY_NAME”, font, txtBrush); textStyle.XOffsetInPixel = 0; textStyle.YOffsetInPixel = -6; capitalLabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(“CITY_NAME”, “Arial”, 8, DrawingFontStyles.Italic, GeoColor.StandardColors.Black, 3, 3); capitalLabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level05;

capitalLabelLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = textStyle; ``` ### Getting Help

[ThinkGeo UI Desktop for WPF: Wiki Resources](https://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[ThinkGeo UI Desktop for WPF: Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Forums](https://community.thinkgeo.com/)

[ThinkGeo Website](https://thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense. # Image Style Sample for Wpf

### Description As you probably already know, using the Map Suite API, you can easily display a point-based feature as an image. But how do you do the same thing for a line or a polygon-based feature? In this WPF project, we show you how to create custom Image Styles for both line and polygon features. With the new ImageAreaStyle, you can display a polygon feature that uses an image as its fill. You can see how an image for forest and water is used in the sample project. And with the new ImageLineStyle, you can do the same thing with line features. You'll see how an image of a pavement texture is used to represent streets.

Please refer to [Wiki](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/ImageStyleSample-ForWpf.NETCore/blob/master/Screenshot.png)

### About the Code ```csharp [Serializable] class ImageAreaStyle : Style {

  private GeoImage geoImage = null;
  public ImageAreaStyle(GeoImage geoImage)
  {
      this.geoImage = geoImage;
  }
  protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, 
            Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
  {
      // Loop through all of the features being passed in to draw.
      foreach (Feature feature in features)
      {
          WellKnownType shapeWellKnownType = feature.GetWellKnownType();
          if (shapeWellKnownType == WellKnownType.Polygon)
          {
              PolygonShape polygonShape = new PolygonShape(feature.GetWellKnownBinary());
              canvas.DrawArea(polygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
          }
          else if (shapeWellKnownType == WellKnownType.Multipolygon)
          {
              MultipolygonShape multiPolygonShape = new MultipolygonShape(feature.GetWellKnownBinary());
              canvas.DrawArea(multiPolygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
          }
      }
  }

} ``` ### Getting Help

[Map Suite Desktop for Wpf Wiki Resources](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[Map Suite Desktop for Wpf Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

# Print Preview Sample for Wpf

### Description In this sample we show you how to add robust printing support to your Map Suite applications for the WPF. Using the code in this sample, you'll be able to build a Print Preview interface that lets your users interactively arrange items (such as a map, scale line, labels, data grid or image) on a virtual page before printing the result to a printer, exporting to a bitmap image. Maps are printed using vector graphics so you can be sure the output will look great on anything.

Please refer to [Wiki](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/PrintPreviewSample-ForWpf.NETCore/blob/master/Screenshot.png)

### About the Code ```csharp Map1.ZoomLevelSet = new PrinterZoomLevelSet(Map1.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit));

PrinterInteractiveOverlay printerOverlay = new PrinterInteractiveOverlay();

Map1.InteractiveOverlays.Add(“PrintPreviewOverlay”, printerOverlay); Map1.InteractiveOverlays.MoveToBottom(“PrintPreviewOverlay”);

PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait); pagePrinterLayer.Open(); printerOverlay.PrinterLayers.Add(“PageLayer”, pagePrinterLayer); ``` ### Getting Help

[Map Suite Desktop for Wpf Wiki Resources](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[Map Suite Desktop for Wpf Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

# MBTiles Extractor Sample for WPF

### Description

The MBTiles Extractor allows you to create new smaller subsets from the MBTiles database. You simply specify the bounding box by tracking a rectangle shape on the map for the new area, then it will create a new SQLite database for that regions.

*.MBTile format can be supported in all of the Map Suite controls such as Wpf, Web, MVC, WebApi, Android and iOS.

Please refer to [Wiki](https://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/MBTilesExtractorSample-ForWpf.NETCore/blob/master/Screenshot.gif)

### About the Code The sample can extract MBTiles from source database to target database. One thing needs to be aware of: there are three tables (“map”,“images”,“metadata”) need to be copied from source database to target database. ```csharp ThinkGeoMBTilesLayer.CreateDatabase(targetFilePath); var targetDBConnection = new SqliteConnection($“Data Source={targetFilePath}”); var targetMap = new Map(targetDBConnection); var targetImages = new Images(targetDBConnection); var targetMetadata = new Metadata(targetDBConnection);

var sourceDBConnection = new SqliteConnection(“Data Source=Data/tiles_Frisco.mbtiles”); var sourceMap = new Map(sourceDBConnection); var sourceImages = new Images(sourceDBConnection); var sourceMetadata = new Metadata(sourceDBConnection);

sourceMetadata.NextPage(); foreach (MetadataEntry entry in sourceMetadata.Entries) {

  if (entry.Name.Equals("center"))
  {
      PointShape centerPoint = projection.ConvertToExternalProjection(bbox).GetCenterPoint();
      entry.Value = $"{centerPoint.X},{centerPoint.Y},{maxZoom}";
  }

} targetMetadata.Insert(sourceMetadata.Entries);

int recordLimit = 1000; foreach (var tileRange in tileRanges) {

  long offset = 0;
  bool isEnd = false;
  while (!isEnd)
  {
      string querySql = $"SELECT * FROM {sourceMap.TableName} WHERE " + ConvetToSqlString(tileRange) 
                          + $" LIMIT {offset},{recordLimit}";
      var entries = sourceMap.Query(querySql);
      targetMap.Insert(entries);
      if (entries.Count < recordLimit)
          isEnd = true;
      querySql = $"SELECT images.tile_data as tile_data, images.tile_id as tile_id FROM {sourceImages.TableName} "
                  + $WHERE images.tile_id IN ( SELECT {Map.TileIdColumnName} FROM {sourceMap.TableName} WHERE "
                  + ConvetToSqlString(tileRange) + $" LIMIT {offset},{recordLimit} )";
      entries = sourceImages.Query(querySql);
      targetImages.Insert(entries);
      offset = offset + recordLimit;
  }

} ``` ### Getting Help

[Map Suite UI Control for WPF Wiki Resources](https://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[Map Suite UI Control for WPF Product Description](https://thinkgeo.com/gis-ui-desktop#platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

# Earthquake Statistics Sample for Wpf

### Description The Earthquake Statistics sample template is a statistical report system for earthquakes that have occurred in the past few years across the United States. It can help you generate infographics and analyze the severely afflicted areas, or used as supporting evidence when recommending measures to minimize the damage in future quakes.

Please refer to [Wiki](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/EarthquakeStatisticsSample-ForWpf.NETCore/blob/master/Screenshot.gif)

### About the Code ```csharp GridInterpolationModel interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue); isoLineLayer = new DynamicIsoLineLayer(dataPoints, IsoLineLayer.GetIsoLineLevels(dataPoints.Values, 12),

                                     interpolationModel, IsoLineType.ClosedLinesAsPolygons);

IsoLineLayer.GetIsoLineLevels(dataPoints, 12);

levelClassBreakStyle = new ClassBreakStyle(isoLineLayer.DataValueColumnName); levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue,

                                   new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), 
                                   new GeoSolidBrush(new GeoColor(100, levelAreaColors[0])))));

``` ### Getting Help

[Map Suite Desktop for Wpf Wiki Resources](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[Map Suite Desktop for Wpf Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

# Weather Line Style Sample for Wpf

### Description

In this WPF sample, we learn how to extend LineStyle class to create a style for representing weather fronts, such as cold front, warm front, or occluded front for your weather maps. To achieve that styling a regular LineStyle is used for the front line itself. For symbolizing the type of front an icon is used.

Notice the two handy properties to give you more control: Spacing property to adjust the distance in screen coordinate between each symbol on the line, and Side property to control on what side of the line front the symbols should appear. Of course, as you zoom in and out on the map the spacing between each symbol remain the same as it is set in screen coordinate.

Please refer to [Wiki](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/WeatherLineStyleSample-ForWpf.NETCore/blob/master/ScreenShot.png)

### About the Code ```csharp class customGeoImageLineStyle : LineStyle {

  protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, 
           System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer,
           System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
  {
     PointStyle pointStyle = new PointStyle(geoImage);
     foreach (Feature feature in features)
      {
          LineShape lineShape = (LineShape)feature.GetShape();
          lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers);
          double totalDist = 0;
          for (int i = 0; i < lineShape.Vertices.Count - 1; i++)
          {
              PointShape pointShape1 = new PointShape(lineShape.Vertices[i]);
              PointShape pointShape2 = new PointShape(lineShape.Vertices[i + 1]);
              LineShape tempLineShape = new LineShape();
              tempLineShape.Vertices.Add(lineShape.Vertices[i]);
              tempLineShape.Vertices.Add(lineShape.Vertices[i + 1]);
              double angle = GetAngleFromTwoVertices(lineShape.Vertices[i], lineShape.Vertices[i + 1]);
              if (side == SymbolSide.Left)
                  if (angle >= 270) { angle = angle - 180; }
              else
                  if (angle <= 90) { angle = angle + 180; }
              
              pointStyle.RotationAngle = (float)angle;
              float screenDist = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(
                          canvas.CurrentWorldExtent,pointShape1, pointShape2, canvas.Width, canvas.Height);
              double currentDist = Math.Round(pointShape1.GetDistanceTo(pointShape2, canvas.MapUnit,
                                                                        DistanceUnit.Meter), 2);
              double worldInterval = (currentDist * spacing) / screenDist;
              while (totalDist <= currentDist)
              {
                  PointShape tempPointShape = tempLineShape.GetPointOnALine(StartingPoint.FirstPoint,
                                                            totalDist, canvas.MapUnit, DistanceUnit.Meter);
                  pointStyle.Draw(new BaseShape[] { tempPointShape }, canvas,
                                                                     labelsInThisLayer, labelsInAllLayers);
                  totalDist = totalDist + worldInterval;
              }
              totalDist = totalDist - currentDist;
           }
      }
  }

} ``` ### Getting Help

[Map Suite Desktop for Wpf Wiki Resources](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[Map Suite Desktop for Wpf Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

# Use Custom Font Symbol With PointStyle for Wpf

### Description In this sample we show you how to use custom font symbol with pointStyle to your Map Suite applications for the WPF environment. The UseCustomFontSymbolWithPointStyle-ForWpf.NETCore sample supports ThinkGeo UI for Wpf 12.0 and higher.

Please refer to [Wiki](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf) for the details.

![Screenshot](https://github.com/ThinkGeo/UseCustomFontSymbolWithPointStyle-ForWpf.NETCore/blob/master/Screenshot.gif)

### About the Code ```csharp ShapeFileFeatureLayer citiesLayer = new ShapeFileFeatureLayer(“AppData/MajorCities_3857.shp”); citiesLayer.Name = “MajorCities”; citiesLayer.ZoomLevelSet.ZoomLevel04.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 20, DrawingFontStyles.Regular),
                                  "\ue0b5",new GeoSolidBrush(GeoColors.Red));

citiesLayer.ZoomLevelSet.ZoomLevel05.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 25, DrawingFontStyles.Regular),
                                  "\ue05c",new GeoSolidBrush(GeoColors.Orange));

citiesLayer.ZoomLevelSet.ZoomLevel06.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 28, DrawingFontStyles.Regular),
                                  "\ue078",new GeoSolidBrush(GeoColors.Green));

citiesLayer.ZoomLevelSet.ZoomLevel07.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 30, DrawingFontStyles.Regular), 
                                  "\ue035",new GeoSolidBrush(GeoColors.DarkBlue));

citiesLayer.ZoomLevelSet.ZoomLevel08.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 34, DrawingFontStyles.Regular),
                                  "\ue02e",new GeoSolidBrush(GeoColors.Blue));

citiesLayer.ZoomLevelSet.ZoomLevel09.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 36, DrawingFontStyles.Regular), 
                                  "\ue06f",new GeoSolidBrush(GeoColors.Purple));

citiesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(

                                  new GeoFont("AppData/vectormap-icons.ttf", 40, DrawingFontStyles.Regular),
                                  "\ue084", new GeoSolidBrush(GeoColors.Red));

``` ### Getting Help

[ThinkGeo Desktop for Wpf Wiki Resources](http://wiki.thinkgeo.com/wiki/thinkgeo_desktop_for_wpf)

[ThinkGeo Desktop for Wpf Product Description](https://thinkgeo.com/ui-controls#desktop-platforms)

[ThinkGeo Community Site](http://community.thinkgeo.com/)

[ThinkGeo Web Site](http://www.thinkgeo.com)

### About ThinkGeo ThinkGeo is a GIS (Geographic Information Systems) company founded in 2004 and located in Frisco, TX. Our clients are in more than 40 industries including agriculture, energy, transportation, government, engineering, software development, and defense.

thinkgeo_desktop_for_wpf_all_samples.txt · Last modified: 2020/03/08 06:47 (external edit)