This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
thinkgeo_web_for_api_quick_start_guide [2019/10/21 01:22] tgwikiupdate [Initialize Layer] |
thinkgeo_web_for_api_quick_start_guide [2019/10/21 10:56] (current) tgwikiupdate [Download the Sample] |
||
---|---|---|---|
Line 2: | Line 2: | ||
<div msgbox> | <div msgbox> | ||
- | The ThinkGeo UI Web for API Quickstart Guide will guide you through the process of creating a WebAPI application and will help you become familiar with ThinkGeo Products. The Quickstart Guide supports ThinkGeo UI Web for WebAPI 12.0 and higher and will show you how to create an ASP.NET Core WebAPI application. | + | The ThinkGeo UI for WebApi Quickstart Guide will guide you through the process of creating a WebAPI application and will help you become familiar with ThinkGeo Products. The Quickstart Guide supports ThinkGeo UI for WebAPI 12.0 and higher and will show you how to create an ASP.NET Core WebAPI application. |
</div> | </div> | ||
- | ThinkGeo UI Web for API makes it easy for any Microsoft .NET developer to add mapping functionality to a ASP.NET Core RESTful application quickly and efficiently. Using the intuitive object model, even developers inexperienced in Geographic Information Systems (GIS) can have fully functional maps working in minutes. | + | ThinkGeo UI for WebApi makes it easy for any Microsoft .NET developer to add mapping functionality to a ASP.NET Core RESTful application quickly and efficiently. Using the intuitive object model, even developers inexperienced in Geographic Information Systems (GIS) can have fully functional maps working in minutes. |
===== Download the Sample ===== | ===== Download the Sample ===== | ||
- | <faicon fa fa-download fa-lg> {{https://github.com/ThinkGeo/QuickstartSample-ForWebApi|Download Sample Code From GitHub}} | + | <faicon fa fa-download fa-lg> {{https://github.com/ThinkGeo/QuickstartSample-ForWebApi.NetCore|Download Sample Code From GitHub}} |
===== Setting up the Environment ===== | ===== Setting up the Environment ===== | ||
- | To get started with ThinkGeo UI Web for WebAPI, you first need to install the [[https://dotnet.microsoft.com/download/dotnet-core/3.0|.NET Core 3.0 SDK]]. You'll also want an IDE, such as [[https://visualstudio.microsoft.com/vs/|Visual Studio 2019 (version 16.3 or newer)]] or [[https://code.visualstudio.com/download|Visual Studio Code]]. For this quick start guide, we'll be using Visual Studio Code. | + | To get started with ThinkGeo UI for WebAPI, you first need to install the [[https://dotnet.microsoft.com/download/dotnet-core/3.0|.NET Core 3.0 SDK]]. You'll also want an IDE, such as [[https://visualstudio.microsoft.com/vs/|Visual Studio 2019 (version 16.3 or newer)]] or [[https://code.visualstudio.com/download|Visual Studio Code]]. For this quick start guide, we'll be using Visual Studio Code. |
Line 48: | Line 48: | ||
// Create the LayerOverlay for displaying the map. | // Create the LayerOverlay for displaying the map. | ||
var countriesLayer = new ShapeFileFeatureLayer(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "AppData", "Countries.shp")); | var countriesLayer = new ShapeFileFeatureLayer(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "AppData", "Countries.shp")); | ||
+ | | ||
+ | // Set the style for ZoomLevels. | ||
countriesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle | countriesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle | ||
{ | { | ||
Line 53: | Line 55: | ||
OutlinePen = new GeoPen(GeoColors.Gray, 1) | OutlinePen = new GeoPen(GeoColors.Gray, 1) | ||
}; | }; | ||
+ | | ||
+ | // Apply the zoom level's style to zoom level 20. | ||
countriesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | countriesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | ||
+ | // Apply ProjectionConverter. The source is in DecimalDegree and needs to be convert to Mercator Projection. | ||
countriesLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857); | countriesLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857); | ||
+ | | ||
+ | // Initialize a LayerOverlay. | ||
var layerOverlay = new LayerOverlay(); | var layerOverlay = new LayerOverlay(); | ||
layerOverlay.Layers.Add(countriesLayer); | layerOverlay.Layers.Add(countriesLayer); | ||
Line 63: | Line 70: | ||
private IActionResult DrawTileImage(LayerOverlay layerOverlay, int z, long x, long y) | private IActionResult DrawTileImage(LayerOverlay layerOverlay, int z, long x, long y) | ||
{ | { | ||
+ | // Create a new GeoImage | ||
using (GeoImage image = new GeoImage(256, 256)) | using (GeoImage image = new GeoImage(256, 256)) | ||
{ | { | ||
var geoCanvas = GeoCanvas.CreateDefaultGeoCanvas(); | var geoCanvas = GeoCanvas.CreateDefaultGeoCanvas(); | ||
+ | | ||
+ | // Get the BoundingBox for the specified x, y, z. | ||
RectangleShape boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter); | RectangleShape boundingBox = WebApiExtentHelper.GetBoundingBoxForXyz(x, y, z, GeographyUnit.Meter); | ||
geoCanvas.BeginDrawing(image, boundingBox, GeographyUnit.Meter); | geoCanvas.BeginDrawing(image, boundingBox, GeographyUnit.Meter); | ||
Line 83: | Line 93: | ||
===== Understanding what is going on ===== | ===== Understanding what is going on ===== | ||
- | You need to know 2 things: | + | You need to know the following things: |
- Layer | - Layer | ||
- Overlay | - Overlay | ||
Line 124: | Line 134: | ||
</code> | </code> | ||
===== Consuming the API ===== | ===== Consuming the API ===== | ||
- | We need to create a client sample to render the map tiles returning from the API. In this sample, I use OpenLayers v6.0.1 for doing that. | + | We need to create a client sample to render the map tiles returning from the API. In this sample, we use OpenLayers v6.0.1 for doing that. |
<code html> | <code html> | ||
<!DOCTYPE html> | <!DOCTYPE html> | ||
Line 166: | Line 176: | ||
</code> | </code> | ||
- | Run the app by pressing F5. If you have not set up a developer license, the Map Suite Product Center will pop up. You will need to activate your developer license, either by starting a free evaluation of ThinkGeo UI Web for Blazor, or by purchasing the full edition of the product. For more details, please refer to our [[map_suite_developer_license_guide|developer license guide]]. | + | Run the app by pressing F5. If you have not set up a developer license, the Map Suite Product Center will pop up. You will need to activate your developer license, either by starting a free evaluation of ThinkGeo UI for WebAPI, or by purchasing the full edition of the product. For more details, please refer to our [[map_suite_developer_license_guide|developer license guide]]. |
Once your developer license is ready, run the application. Your map should look like the one below: | Once your developer license is ready, run the application. Your map should look like the one below: |