/// <summary> /// Load game assets /// </summary> protected override void LoadContent() { WzDirectory MapWzFile = Program.WzManager["map"]; // Map.wz WzDirectory UIWZFile = Program.WzManager["ui"]; // BGM if (Program.InfoManager.BGMs.ContainsKey(mapBoard.MapInfo.bgm)) { audio = new WzMp3Streamer(Program.InfoManager.BGMs[mapBoard.MapInfo.bgm], true); if (audio != null) { audio.Volume = 0.3f; audio.Play(); } } if (mapBoard.VRRectangle == null) { vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y); } else { vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height); } //SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); // Background and objects List <WzObject> usedProps = new List <WzObject>(); foreach (LayeredItem tileObj in mapBoard.BoardItems.TileObjs) { WzImageProperty tileParent = (WzImageProperty)tileObj.BaseInfo.ParentObject; mapObjects[tileObj.LayerNumber].Add( MapSimulatorLoader.CreateMapItemFromProperty(texturePool, tileParent, tileObj.X, tileObj.Y, mapBoard.CenterPoint, _DxDeviceManager.GraphicsDevice, ref usedProps, tileObj is IFlippable ? ((IFlippable)tileObj).Flip : false)); } foreach (BackgroundInstance background in mapBoard.BoardItems.BackBackgrounds) { WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject; backgrounds_back.Add( MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip)); } foreach (BackgroundInstance background in mapBoard.BoardItems.FrontBackgrounds) { WzImageProperty bgParent = (WzImageProperty)background.BaseInfo.ParentObject; backgrounds_front.Add( MapSimulatorLoader.CreateBackgroundFromProperty(texturePool, bgParent, background, _DxDeviceManager.GraphicsDevice, ref usedProps, background.Flip)); } // Load reactors foreach (ReactorInstance reactor in mapBoard.BoardItems.Reactors) { //WzImage imageProperty = (WzImage)NPCWZFile[reactorInfo.ID + ".img"]; ReactorItem reactorItem = MapSimulatorLoader.CreateReactorFromProperty(texturePool, reactor, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_Reactors.Add(reactorItem); } // Load NPCs foreach (NpcInstance npc in mapBoard.BoardItems.NPCs) { //WzImage imageProperty = (WzImage) NPCWZFile[npcInfo.ID + ".img"]; NpcItem npcItem = MapSimulatorLoader.CreateNpcFromProperty(texturePool, npc, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_NPCs.Add(npcItem); } // Load Mobs foreach (MobInstance mob in mapBoard.BoardItems.Mobs) { //WzImage imageProperty = Program.WzManager.FindMobImage(mobInfo.ID); // Mob.wz Mob2.img Mob001.wz MobItem npcItem = MapSimulatorLoader.CreateMobFromProperty(texturePool, mob, _DxDeviceManager.GraphicsDevice, ref usedProps); mapObjects_Mobs.Add(npcItem); } // Load portals WzSubProperty portalParent = (WzSubProperty)MapWzFile["MapHelper.img"]["portal"]; WzSubProperty gameParent = (WzSubProperty)portalParent["game"]; //WzSubProperty editorParent = (WzSubProperty) portalParent["editor"]; foreach (PortalInstance portal in mapBoard.BoardItems.Portals) { PortalItem portalItem = MapSimulatorLoader.CreatePortalFromProperty(texturePool, gameParent, portal, _DxDeviceManager.GraphicsDevice, ref usedProps); if (portalItem != null) { mapObjects_Portal.Add(portalItem); } } // Load tooltips WzSubProperty farmFrameParent = (WzSubProperty)UIWZFile["UIToolTip.img"]?["Item"]?["FarmFrame"]; foreach (ToolTipInstance tooltip in mapBoard.BoardItems.ToolTips) { TooltipItem item = MapSimulatorLoader.CreateTooltipFromProperty(texturePool, farmFrameParent, tooltip, _DxDeviceManager.GraphicsDevice); mapObjects_tooltips.Add(item); } // Cursor WzImageProperty cursorImageProperty = (WzImageProperty)UIWZFile["Basic.img"]?["Cursor"]; this.mouseCursor = MapSimulatorLoader.CreateMouseCursorFromProperty(texturePool, cursorImageProperty, 0, 0, _DxDeviceManager.GraphicsDevice, ref usedProps, false); // Spine object skeletonMeshRenderer = new SkeletonMeshRenderer(GraphicsDevice) { PremultipliedAlpha = false }; // Minimap WzSubProperty minimapFrameProperty = (WzSubProperty)UIWZFile["UIWindow2.img"]?["MiniMap"]; miniMap = MapSimulatorLoader.CreateMinimapFromProperty(minimapFrameProperty, mapBoard, GraphicsDevice, mapBoard.MapInfo.strMapName, mapBoard.MapInfo.strStreetName); // spriteBatch = new SpriteBatch(GraphicsDevice); // default positioning for character SetCameraMoveX(true, true, 0); SetCameraMoveY(true, true, 0); // Debug items System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1); bitmap_debug.SetPixel(0, 0, System.Drawing.Color.White); texture_debugBoundaryRect = bitmap_debug.ToTexture2D(_DxDeviceManager.GraphicsDevice); // cleanup // clear used items foreach (WzObject obj in usedProps) { obj.MSTag = null; obj.MSTagSpine = null; // cleanup } usedProps.Clear(); }
/// <summary> /// The GetPortals method returns an ArrayList containing all of the /// Portals registered in this database.<br/> /// GetPortals Stored Procedure /// </summary> /// <returns> /// a list of portals /// </returns> public ArrayList GetPortalsArrayList() { var portals = new ArrayList(); // Create Instance of Connection and Command Object using (var connection = Config.SqlConnectionString) { using (var command = new SqlCommand(StringsRbGetPortals, connection)) { // Mark the Command as a SPROC command.CommandType = CommandType.StoredProcedure; // Execute the command connection.Open(); using (var dr = command.ExecuteReader(CommandBehavior.CloseConnection)) { try { while (dr.Read()) { var p = new PortalItem { Name = dr["PortalName"].ToString(), Path = dr["PortalPath"].ToString(), ID = Convert.ToInt32(dr["PortalID"].ToString()) }; portals.Add(p); } } finally { dr.Close(); // by Manu, fixed bug 807858 } } // Return the portals return portals; } } }
// Note: all code below (except call to ConfigureOfflineJobForBasemap) is identical to code in the Generate offline map sample. #region Generate offline map private async void Initialize() { try { // Call a function to set up the AuthenticationManager for OAuth. SetOAuthInfo(); // Create the ArcGIS Online portal. ArcGISPortal portal = await ArcGISPortal.CreateAsync(); // Get the Naperville water web map item using its ID. PortalItem webmapItem = await PortalItem.CreateAsync(portal, WebMapId); // Create a map from the web map item. Map onlineMap = new Map(webmapItem); // Display the map in the MapView. MyMapView.Map = onlineMap; // Disable user interactions on the map (no panning or zooming from the initial extent). MyMapView.InteractionOptions = new MapViewInteractionOptions { IsEnabled = false }; // Create a graphics overlay for the extent graphic and apply a renderer. SimpleLineSymbol aoiOutlineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.Red, 3); GraphicsOverlay extentOverlay = new GraphicsOverlay { Renderer = new SimpleRenderer(aoiOutlineSymbol) }; MyMapView.GraphicsOverlays.Add(extentOverlay); // Add a graphic to show the area of interest (extent) that will be taken offline. Graphic aoiGraphic = new Graphic(_areaOfInterest); extentOverlay.Graphics.Add(aoiGraphic); // Hide the map loading progress indicator. LoadingIndicator.Visibility = Visibility.Collapsed; // When the map view unloads, try to clean up existing output data folders. MyMapView.Unloaded += (s, e) => { // Find output mobile map folders in the temp directory. string[] outputFolders = Directory.GetDirectories(Environment.ExpandEnvironmentVariables("%TEMP%"), "NapervilleWaterNetwork*"); // Loop through the folder names and delete them. foreach (string dir in outputFolders) { try { // Delete the folder. Directory.Delete(dir, true); } catch (Exception) { // Ignore exceptions (files might be locked, for example). } } }; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error loading map"); } }
public SaveDialogFragment(PortalItem mapItem) { _portalItem = mapItem; }
private async void Initialize() { try { // Show a loading indicator. _progressIndicator.SetTitle("Loading"); _progressIndicator.SetMessage("Loading the available map areas."); _progressIndicator.SetCancelable(false); _progressIndicator.Show(); // Get the offline data folder. _offlineDataFolder = Path.Combine(GetDataFolder(), "SampleData", "DownloadPreplannedMapAreas"); // If the temporary data folder doesn't exist, create it. if (!Directory.Exists(_offlineDataFolder)) { Directory.CreateDirectory(_offlineDataFolder); } // Create a portal that contains the portal item. ArcGISPortal portal = await ArcGISPortal.CreateAsync(); // Create a webmap based on the id. PortalItem webmapItem = await PortalItem.CreateAsync(portal, PortalItemId); // Create the offline task and load it. _offlineMapTask = await OfflineMapTask.CreateAsync(webmapItem); // Query related preplanned areas. _preplannedMapAreas = await _offlineMapTask.GetPreplannedMapAreasAsync(); // Load each preplanned map area. foreach (var area in _preplannedMapAreas) { await area.LoadAsync(); } // Show a popup menu of available areas when the download button is clicked. _downloadButton.Click += (s, e) => { // Create a menu to show the available map areas. PopupMenu areaMenu = new PopupMenu(this, _downloadButton); areaMenu.MenuItemClick += (sndr, evt) => { // Get the name of the selected area. string selectedArea = evt.Item.TitleCondensedFormatted.ToString(); // Download and show the map. OnDownloadMapAreaClicked(selectedArea); }; // Create the menu options. foreach (PreplannedMapArea area in _preplannedMapAreas) { areaMenu.Menu.Add(area.PortalItem.Title.ToString()); } // Show the menu in the view. areaMenu.Show(); }; // Remove loading indicators from the UI. _progressIndicator.Dismiss(); } catch (Exception ex) { // Something unexpected happened, show error message. var builder = new AlertDialog.Builder(this); builder.SetMessage(ex.Message).SetTitle("An error occurred").Show(); } }
public SaveMapDialogOverlay(CoreGraphics.CGRect frame, nfloat transparency, UIColor color, Item mapItem) : base(frame) { // Store the current portal item for the map (if any) _portalItem = mapItem as PortalItem; // Create a semi-transparent overlay with the specified background color BackgroundColor = color; Alpha = transparency; // Set size and spacing for controls nfloat controlHeight = 25; nfloat rowSpace = 11; nfloat buttonSpace = 15; nfloat textViewWidth = Frame.Width - 60; nfloat buttonWidth = 60; // Get the total height and width of the control set (four rows of controls, three sets of space) nfloat totalHeight = (4 * controlHeight) + (3 * rowSpace); nfloat totalWidth = textViewWidth; // Find the center x and y of the view nfloat centerX = Frame.Width / 2; nfloat centerY = Frame.Height / 2; // Find the start x and y for the control layout nfloat controlX = centerX - (totalWidth / 2); nfloat controlY = centerY - (totalHeight / 2); // Title text input _titleTextField = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight)); _titleTextField.Placeholder = "Title"; _titleTextField.AutocapitalizationType = UITextAutocapitalizationType.None; _titleTextField.BackgroundColor = UIColor.LightGray; // Adjust the Y position for the next control controlY = controlY + controlHeight + rowSpace; // Description text input _descriptionTextField = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight)); _descriptionTextField.Placeholder = "Description"; _descriptionTextField.AutocapitalizationType = UITextAutocapitalizationType.None; _descriptionTextField.BackgroundColor = UIColor.LightGray; // Adjust the Y position for the next control controlY = controlY + controlHeight + rowSpace; // Tags text input _tagsTextField = new UITextField(new CoreGraphics.CGRect(controlX, controlY, textViewWidth, controlHeight)); _tagsTextField.Text = "ArcGIS Runtime, Web Map"; _tagsTextField.AutocapitalizationType = UITextAutocapitalizationType.None; _tagsTextField.BackgroundColor = UIColor.LightGray; // Adjust the Y position for the next control controlY = controlY + controlHeight + rowSpace; // Button to save the map UIButton saveButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight)); saveButton.SetTitle("Save", UIControlState.Normal); saveButton.SetTitleColor(UIColor.Blue, UIControlState.Normal); saveButton.TouchUpInside += SaveButtonClick; // Adjust the X position for the next control controlX = controlX + buttonWidth + buttonSpace; // Button to cancel the save UIButton cancelButton = new UIButton(new CoreGraphics.CGRect(controlX, controlY, buttonWidth, controlHeight)); cancelButton.SetTitle("Cancel", UIControlState.Normal); cancelButton.SetTitleColor(UIColor.Blue, UIControlState.Normal); cancelButton.TouchUpInside += (s, e) => { OnCanceled.Invoke(this, null); }; // Add the controls AddSubviews(_titleTextField, _descriptionTextField, _tagsTextField, saveButton, cancelButton); // If there's an existing portal item, configure the dialog for "update" (read-only entries) if (this._portalItem != null) { _titleTextField.Text = this._portalItem.Title; _titleTextField.Enabled = false; _descriptionTextField.Text = this._portalItem.Description; _descriptionTextField.Enabled = false; _tagsTextField.Text = string.Join(",", this._portalItem.Tags); _tagsTextField.Enabled = false; // Change the button text saveButton.SetTitle("Update", UIControlState.Normal); } }
public async void ChangeBasemap(string basemap) { // Apply the selected basemap to the map switch (basemap) { case "Topographic": // Set the basemap to Topographic _map.Basemap = Basemap.CreateTopographic(); break; case "Topographic Vector": // Set the basemap to Topographic (vector) _map.Basemap = Basemap.CreateTopographicVector(); break; case "Streets": // Set the basemap to Streets _map.Basemap = Basemap.CreateStreets(); break; case "Streets Vector": // Set the basemap to Streets (vector) _map.Basemap = Basemap.CreateStreetsVector(); break; case "Imagery": // Set the basemap to Imagery _map.Basemap = Basemap.CreateImagery(); break; case "Oceans": // Set the basemap to Oceans _map.Basemap = Basemap.CreateOceans(); break; case "USGS National Map": // Set the basemap to USGS National Map by opening it from ArcGIS Online var itemID = "809d37b42ca340a48def914df43e2c31"; // Connect to ArcGIS Online ArcGISPortal agsOnline = await ArcGISPortal.CreateAsync(); // Get the USGS webmap item PortalItem usgsMapItem = await PortalItem.CreateAsync(agsOnline, itemID); // Create a new basemap using the item _map.Basemap = new Basemap(usgsMapItem); break; case "World Globe 1812": // Create a URI that points to a map service to use in the basemap var uri = new Uri("https://tiles.arcgis.com/tiles/IEuSomXfi6iB7a25/arcgis/rest/services/World_Globe_1812/MapServer"); // Create an ArcGISTiledLayer from the URI ArcGISTiledLayer baseLayer = new ArcGISTiledLayer(uri); // Create a basemap from the layer and assign it to the map _map.Basemap = new Basemap(baseLayer); break; } }
private async void AddMapItemClick(object sender, RoutedEventArgs e) { // Get a web map from the selected portal item and display it in the map view. if (MapItemListBox.SelectedItem == null) { MessageDialog dialog = new MessageDialog("No web map item is selected."); await dialog.ShowAsync(); return; } // Clear status messages. MessagesTextBlock.Text = string.Empty; // Store status (or errors) when adding the map. var statusInfo = new StringBuilder(); try { // Clear the current MapView control from the app. MyMapGrid.Children.Clear(); // See if using the public or secured portal; get the appropriate object reference. ArcGISPortal portal = null; if (_usingPublicPortal) { portal = _publicPortal; } else { portal = _iwaSecuredPortal; } // Throw an exception if the portal is null. if (portal == null) { throw new Exception("Portal has not been instantiated."); } // Get the portal item ID from the selected list box item (read it from the Tag property). var itemId = (MapItemListBox.SelectedItem as ListBoxItem).Tag.ToString(); // Use the item ID to create a PortalItem from the appropriate portal. var portalItem = await PortalItem.CreateAsync(portal, itemId); if (portalItem != null) { // Create a Map using the web map (portal item). Map webMap = new Map(portalItem); // Create a new MapView control to display the Map. MapView myMapView = new MapView { Map = webMap }; // Add the MapView to the app. MyMapGrid.Children.Add(myMapView); } // Report success. statusInfo.AppendLine("Successfully loaded web map from item #" + itemId + " from " + portal.Uri.Host); } catch (Exception ex) { // Add an error message. statusInfo.AppendLine("Error accessing web map: " + ex.Message); } finally { // Show messages. MessagesTextBlock.Text = statusInfo.ToString(); } }
private void PreloadResource(ResourceLoader resLoader, PortalItem portal) { string path; var view = new PortalItem.ItemView(); //加载editor { var typeName = PortalItem.PortalTypes[portal.Type]; path = $@"Map\MapHelper.img\portal\editor\{typeName}"; var aniData = resLoader.LoadAnimationData(path); if (aniData != null) { view.EditorAnimator = CreateAnimator(aniData); } } //加载动画 { string typeName, imgName; switch (portal.Type) { case 7: typeName = PortalItem.PortalTypes[2]; break; default: typeName = PortalItem.PortalTypes[portal.Type]; break; } switch (portal.Image) { case 0: imgName = "default"; break; default: imgName = portal.Image.ToString(); break; } path = $@"Map\MapHelper.img\portal\game\{typeName}\{imgName}"; var aniNode = PluginManager.FindWz(path); if (aniNode != null) { bool useParts = new[] { "portalStart", "portalContinue", "portalExit" } .Any(aniName => aniNode.Nodes[aniName] != null); if (useParts) //加载动作动画 { var animator = CreateSMAnimator(aniNode, resLoader); view.Animator = animator; view.Controller = new PortalItem.Controller(view); } else //加载普通动画 { var aniData = resLoader.LoadAnimationData(aniNode); if (aniData != null) { view.Animator = CreateAnimator(aniData); } } } } portal.View = view; }