private async static Task <bool> ProcessTile(FeatureLayer shapeFile, int tileX, int tileY, int zoom, IEnumerable <string> columnNames, string targetFolder) { List <FeatureLayer> layers = new List <FeatureLayer>(); FeatureLayer layer = (FeatureLayer)shapeFile.CloneDeep(); layers.Add(layer); Tile vectorTile = new Tile(); await Task.Run(() => { vectorTile = Generate(tileX, tileY, zoom, layers, columnNames, 512, 1); }); if (vectorTile != null && vectorTile.Layers.Count > 0) { await Task.Run(() => { using (MemoryStream ms = new MemoryStream()) { vectorTile.Serialize(ms); byte[] content = ms.ToArray(); byte[] gzippedContent = GZipData(content); File.WriteAllBytes(Path.Combine(targetFolder, $"{zoom}_{tileX}_{tileY}.mvt"), gzippedContent); } }); return(true); } return(false); }
private void EditLayerStyle(FeatureLayer layer) { if (layer != null) { FormStyleEditor frmStyleEditor = new FormStyleEditor(); frmStyleEditor.CurrentStyleType = themeView.Items[selectedOrder].StyleType; frmStyleEditor.ColumnNames = ExplorerHelper.GetColumnNames(layer); frmStyleEditor.BaseLayer = layer; // store layer status and will recover it after serialize/deserialize bool isOpened = layer.IsOpen; // close layer to avoid serialize exception layer.Close(); // clone layer Layer clonedLayer = layer.CloneDeep(); DialogResult isStyleChanged; winformsMap1.Overlays[0].Lock.EnterWriteLock(); try { isStyleChanged = frmStyleEditor.ShowDialog(); } finally { winformsMap1.Overlays[0].Lock.ExitWriteLock(); } if (isStyleChanged == DialogResult.OK) { themeView.Items[selectedOrder].StyleType = frmStyleEditor.CurrentStyleType; winformsMap1.Refresh(); } else { // because user cancel modify style, so restore layer ((LayerOverlay)winformsMap1.Overlays[0]).Layers[selectedOrder] = clonedLayer; } // recover layer status if (isOpened) { layer.Open(); } } }