This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
thinkgeo_cloud_.net_sdk_quick_start_guide [2018/12/29 10:18] tgwikiupdate |
thinkgeo_cloud_.net_sdk_quick_start_guide [2018/12/29 10:27] (current) tgwikiupdate |
||
---|---|---|---|
Line 90: | Line 90: | ||
//Figure 7. The normal map is rendered after the developer license file has been got.// | //Figure 7. The normal map is rendered after the developer license file has been got.// | ||
- | ==== Map Suite Desktop for Wpf "QuickstartSample" ==== | + | Now you can see the ThinkGeo.Cloud.Client had been installed also. Copy the code as below and paste it into Map_Loaded function, it can works. |
- | In creating our “QuickstartSample" application, our first step is to set references to the ThinkGeo.MapSuite.Layers, ThinkGeo.MapSuite.Styles and ThinkGeo.MapSuite.Wpf workspaces at the very top of our code, as we will use many classes within them. We do this so that we do not have to use the fully qualified name of the Map Suite classes throughout our code. Setting a reference to the Map Suite workspace can be done in the “code-behind” of the form by selecting the form and hitting the F7 function key. Set the reference like this: | + | |
<code csharp> | <code csharp> | ||
- | using ThinkGeo.MapSuite; | + | map.MapUnit = GeographyUnit.Meter; |
- | using ThinkGeo.MapSuite.Drawing; | + | map.ZoomLevelSet = ThinkGeoCloudMapsOverlay.GetZoomLevelSet(); |
- | using ThinkGeo.MapSuite.Layers; | + | |
- | using ThinkGeo.MapSuite.Shapes; | + | |
- | using ThinkGeo.MapSuite.Styles; | + | |
- | using ThinkGeo.MapSuite.Wpf; | + | |
- | </code> | + | |
- | Now let's look at a code sample to bring this concept to fruition. We'll look at Shapefiles relating to the entire world. In our example, we have one such Shapefile: | + | |
- | * The borders of every country in the world (Countries02.shp) | + | thinkGeoCloudMapsOverlay = new ThinkGeoCloudMapsOverlay(); |
+ | //thinkGeoCloudMapsOverlay = new ThinkGeoCloudMapsOverlay(clientId, clientSecret); | ||
- | (NOTE: The data used in this sample can be found in the attached sample above in the “\Data” folder) | + | // Tiles will be cached in the TEMP folder (%USERPROFILE%\AppData\Local\Temp\MapSuite\PersistentCaches) by default if the TileCache property is not set. |
+ | //thinkGeoCloudMapsOverlay.TileCache = new XyzFileBitmapTileCache("ThinkGeoCloudMapsTileCache"); | ||
+ | |||
+ | map.Overlays.Add(thinkGeoCloudMapsOverlay); | ||
- | Our next step is to define and add our Layers. All of the following code can be placed in the ''Map1_Loaded'' event of the form. Here is the code to use for our example. | + | map.CurrentExtent = new ThinkGeo.MapSuite.Shapes.RectangleShape(-13086298.60, 7339062.72, -8111177.75, 2853137.62); |
- | + | map.Refresh(); | |
- | <code csharp> | + | |
- | private void Map1_Loaded(object sender, RoutedEventArgs e) | + | |
- | { | + | |
- | // Set the Map Unit. The reason for setting it to DecimalDegrees is that is what the shapefile’s unit of measure is inherently in. | + | |
- | Map1.MapUnit = GeographyUnit.DecimalDegree; | + | |
- | // We create a new Layer and pass the path to a Shapefile into its constructor. | + | |
- | ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"../../Data/Countries02.shp"); | + | |
- | AreaStyle areaStyle = new AreaStyle(); | + | |
- | areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214)); | + | |
- | areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1); | + | |
- | areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid; | + | |
- | worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle; | + | |
- | // This setting will apply from ZoonLevel01 to ZoomLevel20, that means we can see the world the same style with ZoomLevel01 all the time no matter how far we zoom out/in. | + | |
- | worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | + | |
- | // Create a new Layer Overlay to hold the layer we just created | + | |
- | LayerOverlay layerOverlay = new LayerOverlay(); | + | |
- | // Add a background Layer | + | |
- | layerOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean))); | + | |
- | // Add the shapefile layer to the layer overlay | + | |
- | layerOverlay.Layers.Add(worldLayer); | + | |
- | // We need to add the layerOverlay to map. | + | |
- | Map1.Overlays.Add(layerOverlay); | + | |
- | // Set a proper extent for the Map. | + | |
- | Map1.CurrentExtent = new RectangleShape(-134, 70, -56, 7); | + | |
- | // We now need to call the Refresh() method of the Map control so that the Map can redraw based on the data that has been provided. | + | |
- | Map1.Refresh(); | + | |
- | } | + | |
</code> | </code> | ||
- | |||
- | You can get a normal map render (See Figure 8) | ||
- | |||
- | {{mapsuite10:wpf:Map_Suite_Wpf_QSG_ShowAreaStyle.png}} | ||
- | \\ | ||
- | //Figure 8 QuickstartSample Run Result.// | ||
- | |||
- | So what has occurred here? We have created a layer and added it to the Map and the Map has rendered according to its default style parameters. Also, we have used ZoomLevel to display the map the way that we want. | ||
- | |||
- | **NOTE:** It is important that the "MapUnit" property of a Map object be set using the "GeographyUnit" enumeration. This is because ShapeFiles only store binary vector coordinates, which can be in DecimalDegree, feet, meters, etc., and our map has no idea about what the unit of measurement is until we set it. This information is normally found somewhere in the documentation or within the supplemental data file as discussed in the section on ShapeFiles. | ||
- | |||
- | ==== Navigate the Map ==== | ||
- | With the above code, you can both display a map and navigate it. You can pan by dragging the map, zoom in by double-clicking, track zoom in by drawing a rectangle with your left mouse button mouse while holding the shift key, or zoom in and out by using the mouse wheel. Very powerful for just couple lines of code, isn't it? | ||
- | |||
- | That was an easy start! Now, let's add another Shapefile to the sample so that we will have a total of two layers: | ||
- | |||
- | -The borders of every country in the world ("Countries02.shp") | ||
- | -The capitals of the world countries ("WorldCapitals.shp") | ||
- | |||
- | <code csharp> | ||
- | private void Map1_Loaded(object sender, RoutedEventArgs e) | ||
- | { | ||
- | Map1.MapUnit = GeographyUnit.DecimalDegree; | ||
- | ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"../../Data/Countries02.shp"); | ||
- | AreaStyle areaStyle = new AreaStyle(); | ||
- | areaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214)); | ||
- | areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1); | ||
- | areaStyle.OutlinePen.DashStyle = LineDashStyle.Solid; | ||
- | worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = areaStyle; | ||
- | worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | ||
- | ShapeFileFeatureLayer capitalLayer = new ShapeFileFeatureLayer(@"../../Data/WorldCapitals.shp"); | ||
- | PointStyle pointStyle = new PointStyle(); | ||
- | pointStyle.SymbolType = PointSymbolType.Square; | ||
- | pointStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.StandardColors.White); | ||
- | pointStyle.SymbolPen = new GeoPen(GeoColor.StandardColors.Black, 1); | ||
- | pointStyle.SymbolSize = 6; | ||
- | |||
- | PointStyle stackStyle = new PointStyle(); | ||
- | stackStyle.SymbolType = PointSymbolType.Square; | ||
- | stackStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.StandardColors.Maroon); | ||
- | stackStyle.SymbolPen = new GeoPen(GeoColor.StandardColors.Transparent, 0); | ||
- | stackStyle.SymbolSize = 2; | ||
- | |||
- | pointStyle.CustomPointStyles.Add(stackStyle); | ||
- | capitalLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = pointStyle; | ||
- | // This setting also applies from ZoonLevel01 to ZoomLevel20, that means we can see city symbols the same style with ZoomLevel01 all the time. | ||
- | capitalLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | ||
- | |||
- | LayerOverlay layerOverlay = new LayerOverlay(); | ||
- | layerOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean))); | ||
- | layerOverlay.Layers.Add(worldLayer); | ||
- | // We need to add both of the new layers to the Layer OverLay. | ||
- | layerOverlay.Layers.Add(capitalLayer); | ||
- | |||
- | Map1.Overlays.Add(layerOverlay); | ||
- | Map1.CurrentExtent = new RectangleShape(-134, 70, -56, 7); | ||
- | Map1.Refresh(); | ||
- | } | ||
- | </code> | ||
- | |||
- | And the result is as follows (Figure 9): | ||
- | |||
- | {{mapsuite10:wpf:Map_Suite_Wpf_QSG_ShowPointStyle.png}} | ||
- | \\ | ||
- | //Figure 9. Map of Europe with 2 layers.// |