コード例 #1
0
        private static MGLRasterTileSource CreateRasterTileSource(JsonStyleFile jsonStyle, string name, JsonSource source, MGLSpriteAtlas spriteAtlas)
        {
            //if (!string.IsNullOrEmpty(source.Url))
            //{
            //    // Get TileJSON from http/https url
            //    jsonSource = new Source();
            //}

            // Create new raster layer
            var rasterSource = new MGLRasterTileSource(name, CreateTileSource(source))
            {
                TileSize   = source?.TileSize ?? 256,
                MinVisible = source?.ZoomMin ?? 0,
                MaxVisible = source?.ZoomMax ?? 30,
            };

            // If we have a new raster tile source, than get style for this
            if (rasterSource != null)
            {
                // Add all ThemeStyles for this layer
                var style = ExtractStyles(rasterSource.Name, jsonStyle.StyleLayers, spriteAtlas).FirstOrDefault <IVectorStyleLayer>();
                if (style != null)
                {
                    // Replace color with white for opacity
                    ((MGLPaint)style.Paints.First <IVectorPaint>()).SetFixColor(SKColors.White);
                }
                rasterSource.Style = style;
            }

            return(rasterSource);
        }
コード例 #2
0
        private static void ExtractGlyphs(JsonStyleFile jsonStyle, object glyphAtlas)
        {
            // Save urls for glyphs
            var glyphsUrl = jsonStyle.Glyphs;

            if (!string.IsNullOrEmpty(glyphsUrl))
            {
                // Not implemented yet
            }
        }
コード例 #3
0
        private static void ExtractSprites(JsonStyleFile jsonStyle, MGLSpriteAtlas spriteAtlas)
        {
            // Save urls for sprite and glyphs
            var spriteUrl = jsonStyle.Sprite;

            if (!string.IsNullOrEmpty(spriteUrl))
            {
                spriteAtlas.AddSpriteSource(spriteUrl);
            }
        }
コード例 #4
0
        /// <summary>
        /// Extract all given sources (background, raster, vector and so on) given by this JSON file
        /// </summary>
        private static List <IDrawableTileSource> ExtractSources(JsonStyleFile jsonStyle, Dictionary <string, JsonSource> sources, MGLSpriteAtlas spriteAtlas)
        {
            List <IDrawableTileSource> tileSources = new List <IDrawableTileSource>();

            // Read all tile sources
            foreach (var source in sources)
            {
                var jsonSource = source.Value;

                switch (source.Value.Type)
                {
                case "raster":
                    var rasterSource = CreateRasterTileSource(jsonStyle, source.Key, source.Value, spriteAtlas);
                    if (rasterSource != null)
                    {
                        tileSources.Add(rasterSource);
                    }
                    break;

                case "vector":
                    var vectorSource = CreateVectorTileSource(jsonStyle, source.Key, source.Value, spriteAtlas);
                    if (vectorSource != null)
                    {
                        tileSources.Add(vectorSource);
                    }
                    break;

                case "geoJson":
                    break;

                case "image":
                    break;

                case "video":
                    break;

                default:
                    throw new ArgumentException($"{source.Value.Type} isn't a valid source");
                }
            }

            return(tileSources);
        }
コード例 #5
0
        private static IDrawableTileSource CreateVectorTileSource(JsonStyleFile jsonStyle, string name, JsonSource source, MGLSpriteAtlas spriteAtlas)
        {
            JsonSource jsonSource = null;

            if (!string.IsNullOrEmpty(source.Url))
            {
                if (source.Url.StartsWith("http"))
                {
                    // TODO: Get TileJSON from http/https url
                    jsonSource      = JsonConvert.DeserializeObject <JsonSource>(@"{'tiles':['https://free.tilehosting.com/data/v3/{z}/{x}/{y}.pbf.pict?key=tXiQqN3lIgskyDErJCeY'],'name':'OpenMapTiles','format':'pbf','basename':'v3.7.mbtiles','id':'openmaptiles','attribution':'<a href=\'http://www.openmaptiles.org/\' target=\'_blank\'>&copy; OpenMapTiles</a> <a href=\'http://www.openstreetmap.org/about/\' target=\'_blank\'>&copy; OpenStreetMap contributors</a>','description':'A tileset showcasing all layers in OpenMapTiles. http://openmaptiles.org','maxzoom':14,'minzoom':0,'pixel_scale':'256','vector_layers':[{'maxzoom':14,'fields':{'class':'String'},'minzoom':0,'id':'water','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:ru':'String','name:pl':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:lt':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:ko_rm':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','name:ja_kana':'String','name:is':'String','name:th':'String','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:nl':'String','name:es':'String'},'minzoom':0,'id':'waterway','description':''},{'maxzoom':14,'fields':{'class':'String','subclass':'String'},'minzoom':0,'id':'landcover','description':''},{'maxzoom':14,'fields':{'class':'String'},'minzoom':0,'id':'landuse','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','rank':'Number','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:nl':'String','name:pl':'String','ele':'Number','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:lt':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','name:ko_rm':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:ru':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','ele_ft':'Number','name:ja_kana':'String','name:is':'String','osm_id':'Number','name:th':'String','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:es':'String'},'minzoom':0,'id':'mountain_peak','description':''},{'maxzoom':14,'fields':{'class':'String'},'minzoom':0,'id':'park','description':''},{'maxzoom':14,'fields':{'admin_level':'Number','disputed':'Number','maritime':'Number'},'minzoom':0,'id':'boundary','description':''},{'maxzoom':14,'fields':{'ref':'String','class':'String'},'minzoom':0,'id':'aeroway','description':''},{'maxzoom':14,'fields':{'layer':'Number','service':'String','level':'Number','brunnel':'String','indoor':'Number','ramp':'Number','subclass':'String','oneway':'Number','class':'String'},'minzoom':0,'id':'transportation','description':''},{'maxzoom':14,'fields':{'render_min_height':'Number','render_height':'Number'},'minzoom':0,'id':'building','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:ru':'String','name:pl':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:lt':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:ko_rm':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','name:ja_kana':'String','name:is':'String','name:th':'String','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:nl':'String','name:es':'String'},'minzoom':0,'id':'water_name','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','layer':'Number','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:ru':'String','name:pl':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','subclass':'String','name:de':'String','indoor':'Number','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:lt':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:ko_rm':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','network':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','ref':'String','name:ja_kana':'String','level':'Number','ref_length':'Number','name:is':'String','name:th':'String','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:nl':'String','name:es':'String'},'minzoom':0,'id':'transportation_name','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','rank':'Number','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:ru':'String','name:pl':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','capital':'Number','name:sl':'String','name:lv':'String','name:ja':'String','name:ko_rm':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:th':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','iso_a2':'String','name:ja_kana':'String','name:is':'String','name:lt':'String','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:nl':'String','name:es':'String'},'minzoom':0,'id':'place','description':''},{'maxzoom':14,'fields':{'housenumber':'String'},'minzoom':0,'id':'housenumber','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','rank':'Number','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:ru':'String','name:pl':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','subclass':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:lt':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:ko_rm':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','name:ja_kana':'String','name:is':'String','name:th':'String','agg_stop':'Number','name:latin':'String','name:sr-Latn':'String','name:et':'String','name:nl':'String','name:es':'String'},'minzoom':0,'id':'poi','description':''},{'maxzoom':14,'fields':{'name:mt':'String','name:pt':'String','name:az':'String','name:cy':'String','name:rm':'String','name:ko':'String','name:kn':'String','name:ar':'String','name:cs':'String','name_de':'String','name:ro':'String','name:it':'String','name_int':'String','name:nl':'String','name:pl':'String','ele':'Number','name:lt':'String','name:ca':'String','name:hu':'String','name:ka':'String','name:fi':'String','name:da':'String','name:de':'String','name:tr':'String','name:fr':'String','name:mk':'String','name:nonlatin':'String','name:fy':'String','name:zh':'String','name:latin':'String','name:sl':'String','name:lv':'String','name:ja':'String','name:ko_rm':'String','name:no':'String','name:kk':'String','name:sv':'String','name:he':'String','name:ja_rm':'String','name:ga':'String','name:br':'String','name:bs':'String','name:lb':'String','class':'String','name:la':'String','name:sk':'String','name:uk':'String','name:hy':'String','name:ru':'String','name:be':'String','name_en':'String','name:bg':'String','name:hr':'String','name:sr':'String','name:sq':'String','name:th':'String','name:el':'String','name:eo':'String','name:en':'String','name':'String','name:gd':'String','ele_ft':'Number','name:ja_kana':'String','name:is':'String','osm_id':'Number','iata':'String','icao':'String','name:sr-Latn':'String','name:et':'String','name:es':'String'},'minzoom':0,'id':'aerodrome_label','description':''}],'center':[-12.2168,28.6135,4],'bounds':[-180,-85.0511,180,85.0511],'maskLevel':'8','planettime':'1523232000000','version':'3.7','tilejson':'2.0.0'}");
                    jsonSource.Name = name;
                }
                else if (source.Url.StartsWith("mbtiles"))
                {
                    var filename = source.Url.Substring(10);
                    filename = Path.Combine(DirectoryForFiles, filename);
                    if (!File.Exists(filename))
                    {
                        return(null);
                    }
                    var connection = new SQLiteConnectionString(filename, false);
                    var dataSource = new MbTilesTileSource(connection);
                    jsonSource       = JsonConvert.DeserializeObject <JsonSource>(dataSource.Json);
                    jsonSource.Name  = name;
                    jsonSource.Tiles = new List <string> {
                        source.Url
                    };
                    jsonSource.Scheme = dataSource.Schema.YAxis == YAxis.TMS ? "tms" : "osm";
                    jsonSource.Bounds = new JValue[]
                    {
                        new JValue(dataSource.Schema.Extent.MinX),
                        new JValue(dataSource.Schema.Extent.MinY),
                        new JValue(dataSource.Schema.Extent.MaxX),
                        new JValue(dataSource.Schema.Extent.MinX)
                    };
                }
            }

            if (jsonSource == null)
            {
                return(null);
            }

            // Create new vector layer
            var tileSource = CreateTileSource(jsonSource);

            if (jsonSource.Bounds != null)
            {
                var left   = jsonSource.Bounds[0].Type == JTokenType.Float ? (float)jsonSource.Bounds[0] : -180.0f;
                var bottom = jsonSource.Bounds[1].Type == JTokenType.Float ? (float)jsonSource.Bounds[1] : -85.0511f;
                var right  = jsonSource.Bounds[2].Type == JTokenType.Float ? (float)jsonSource.Bounds[2] : 180.0f;
                var top    = jsonSource.Bounds[3].Type == JTokenType.Float ? (float)jsonSource.Bounds[3] : 85.0511f;
            }

            var vectorTileSource = new MGLVectorTileSource(name, tileSource)
            {
                //MinVisible = (jsonSource?.ZoomMax ?? 30).ToResolution(),
                //MaxVisible = (jsonSource?.ZoomMin ?? 0).ToResolution(),
                TileSize = (int)jsonSource?.TileSize,
            };

            // If we have a new vector tile provider, than get styles for this
            if (vectorTileSource != null)
            {
                vectorTileSource.StyleLayers.AddRange(ExtractStyles(vectorTileSource.Name, jsonStyle.StyleLayers, spriteAtlas));
            }

            return(vectorTileSource);
        }
コード例 #6
0
        void CallDeserializedObject()
        {
            var settings = new JsonSerializerSettings();

            jsonStyleFile = JsonConvert.DeserializeObject <JsonStyleFile>(reader.ReadToEnd(), settings);
        }