コード例 #1
0
    public static SharpMap.Map InitializeGoogleMap(GoogleMapType mt)
    {
        SharpMap.Map map = new SharpMap.Map();

        GoogleRequest  req;
        ITileSource    tileSource;
        TileAsyncLayer tileLayer;

        if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
        {
            req        = new GoogleRequest(GoogleMapType.GoogleSatellite);
            tileSource = new GoogleTileSource(req);
            tileLayer  = new TileAsyncLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
            map.Layers.Add(tileLayer);
            req        = new GoogleRequest(GoogleMapType.GoogleLabels);
            tileSource = new GoogleTileSource(req);
            mt         = GoogleMapType.GoogleLabels;
        }
        else
        {
            req        = new GoogleRequest(mt);
            tileSource = new GoogleTileSource(req);
        }

        tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + mt);
        map.BackgroundLayer.Add(tileLayer);
        map.ZoomToBox(tileLayer.Envelope);
        return(map);
    }
コード例 #2
0
        /// <summary>
        /// Converts GoogleMapType enum value to parameter string
        /// </summary>
        /// <param name="mapType">The map type enum value.</param>
        /// <returns>Parameter string for the given map type</returns>
        public static string GetGoogleMapTypeString(GoogleMapType mapType)
        {
            switch (mapType)
            {
            case (GoogleMapType.RoadMap):
            {
                return("roadmap");
            }

            case (GoogleMapType.Satellite):
            {
                return("satellite");
            }

            case (GoogleMapType.Terrain):
            {
                return("terrain");
            }

            case (GoogleMapType.Hybrid):
            {
                return("hybrid");
            }

            default:
            {
                return("roadmap");
            }
            }
        }
コード例 #3
0
ファイル: TileLayerSample.cs プロジェクト: cugkgq/Project
        private static Map InitializeMapGoogle(GoogleMapType mt)
        {
            Map map = new Map();

            GoogleRequest req;
            ITileSource   tileSource;
            TileLayer     tileLayer;

            if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
            {
                req        = new GoogleRequest(GoogleMapType.GoogleSatellite);
                tileSource = new GoogleTileSource(req);
                tileLayer  = new TileLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
                map.Layers.Add(tileLayer);
                req        = new GoogleRequest(GoogleMapType.GoogleLabels);
                tileSource = new GoogleTileSource(req);
                mt         = GoogleMapType.GoogleLabels;
            }
            else
            {
                req        = new GoogleRequest(mt);
                tileSource = new GoogleTileSource(req);
            }

            tileLayer = new TileLayer(tileSource, "TileLayer - " + mt);
            map.Layers.Add(tileLayer);
            map.ZoomToBox(tileLayer.Envelope);
            return(map);
        }
コード例 #4
0
ファイル: MapHelper.cs プロジェクト: vz0/custom-gis-server
    public static SharpMap.Map InitializeGoogleMap(GoogleMapType mt)
    {
        SharpMap.Map map = new SharpMap.Map();

        GoogleRequest req;
        ITileSource tileSource;
        TileAsyncLayer tileLayer;

        if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
        {
            req = new GoogleRequest(GoogleMapType.GoogleSatellite);
            tileSource = new GoogleTileSource(req);
            tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
            map.Layers.Add(tileLayer);
            req = new GoogleRequest(GoogleMapType.GoogleLabels);
            tileSource = new GoogleTileSource(req);
            mt = GoogleMapType.GoogleLabels;
        }
        else
        {
            req = new GoogleRequest(mt);
            tileSource = new GoogleTileSource(req);
        }

        tileLayer = new TileAsyncLayer(tileSource, "TileLayer - " + mt);
        map.BackgroundLayer.Add(tileLayer);
        map.ZoomToBox(tileLayer.Envelope);
        return map;
    }
コード例 #5
0
        /// <summary>
        /// Initializes the url builder.
        /// </summary>
        /// <param name="width">Width of the map in pixels.</param>
        /// <param name="height">Height of the map in pixels.</param>
        /// <param name="mapType">Type of the map.</param>
        public GoogleStaticMapUrlBuilder(int width, int height, GoogleMapType mapType)
        {
            Width = width;
            Height = height;
            MapType = mapType;

            Markers = new List<MapMarker>();
            Paths = new List<MapPath>();
        }
コード例 #6
0
 /// <summary>
 /// Constructor a new GoogleMapOption structure
 /// </summary>
 public GoogleMapOption(LatLng center, GoogleMapType type = GoogleMapType.Roadmap, int zoomLevel = 10, bool visibleZoomControl = false,
                        bool enableGesture = true, ZoomControlPosition controlPosition           = ZoomControlPosition.RightBottom)
 {
     Center  = center;
     MapType = type;
     _zoom   = Math.Min(Math.Max(zoomLevel, 1.0), 20.0);;
     IsZoomControlVisible = visibleZoomControl;
     HasGestureEnabled    = enableGesture;
     ZoomControlPosition  = controlPosition;
 }
コード例 #7
0
 // Set the selected item of the box to the provided value
 private void SetMapType(ComboBox box, GoogleMapType mapTye)
 {
     foreach (var item in box.Items)
     {
         var boxItem = item as ComboBoxItem;
         if (boxItem != null && (GoogleMapType)boxItem.Tag == mapTye)
         {
             box.SelectedItem = item;
             return;
         }
     }
 }
コード例 #8
0
        public GoogleMapsOptions MapType(GoogleMapType mapType)
        {
            if (GoogleMapUtils.IsPlatformNotSupported)
            {
                return(this);
            }

            if (GoogleMapUtils.IsAndroid)
            {
                _ajo.CallAJO(MapTypeMethodName, (int)mapType);
            }
            else
            {
                _dic[MapTypeMethodName] = (int)mapType;
            }

            return(this);
        }
コード例 #9
0
        /// <summary>
        /// Returns the string representation of the provided map type.
        /// </summary>
        /// <param name="mapType">The map type to get the string reprentation for.</param>
        /// <returns>The string representation of the provided map type</returns>
        public static string GetMapTypeString(GoogleMapType mapType)
        {
            switch (mapType)
            {
            case GoogleMapType.Hybrid:
                return("hybrid");

            case GoogleMapType.Road:
                return("roadmap");

            case GoogleMapType.Satellite:
                return("satellite");

            case GoogleMapType.Terrain:
                return("terrain");

            default:
                return("roadmap");
            }
        }
コード例 #10
0
        public async Task <byte[]> GetMapAsync(float latitude, float longitude, int zoom, int scale, int width, int height, GoogleMapType mapType, GoogleImageFormat format, IList <TrackCoordinate> trackCoordinates)
        {
            byte[] bitmap = null;

            try
            {
                var requestUri = string.Empty;

                for (int i = _resolutionModifierStep; i <= _maxResolutionModifierStep; i++)
                {
                    if (i > _resolutionModifierStep)
                    {
                        _logger.LogTrace($"Attempting to build Track Map requestUri at resolution of {i}");
                    }
                    string pathParameter = BuildMapPath(trackCoordinates, i);

                    requestUri = string.Format(
                        "https://maps.googleapis.com/maps/api/staticmap?&scale=1center={0}&zoom={1}&size={2}&maptype={3}&format={4}&key={5}{6}",
                        $"{latitude},{longitude}",
                        zoom,
                        $"{width}x{height}",
                        GoogleMapHelper.GetGoogleMapTypeString(mapType),
                        GoogleMapHelper.GetGoogleFormatString(format),
                        GoogleMapHelper.ApiKey,
                        pathParameter);

                    if (requestUri.Length < 8192)
                    {
                        break;
                    }
                    else if (requestUri.Length > 8192 && i >= _maxResolutionModifierStep)
                    {
                        throw new InvalidOperationException($"requestUri too long: {requestUri.Length}");
                    }
                }
                _logger.LogTrace($"Google Maps requestUri: {requestUri}");

                using (WebClient wc = new WebClient())
                {
                    bitmap = await wc.DownloadDataTaskAsync(new Uri(requestUri));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception in GetMapAsync");
                throw;
            }

            return(bitmap);
        }
コード例 #11
0
 public GoogleTileSource(GoogleMapType mapType)
     : this(new GoogleRequest(mapType), new NullCache())
 {
 }
コード例 #12
0
ファイル: GoogleTileSource.cs プロジェクト: galchen/brutile
 public GoogleTileSource(GoogleMapType mapType)
     : this(new GoogleRequest(mapType))
 {
 }
コード例 #13
0
ファイル: GoogleRequest.cs プロジェクト: galchen/brutile
 public GoogleRequest(GoogleMapType googleMapType)
     : this(googleMapType, LanguageType.English)
 {
 }
コード例 #14
0
ファイル: GoogleRequest.cs プロジェクト: galchen/brutile
 public GoogleRequest(GoogleMapType googleMapType, LanguageType languageType)
 {
     Language = languageType;
     MapType = googleMapType;
 }
コード例 #15
0
ファイル: GoogleRequest.cs プロジェクト: galchen/brutile
 public GoogleRequest(GoogleMapType googleMapType)
     : this(googleMapType, LanguageType.English)
 {
 }
コード例 #16
0
ファイル: GoogleRequest.cs プロジェクト: galchen/brutile
 public GoogleRequest(GoogleMapType googleMapType, LanguageType languageType)
 {
     Language = languageType;
     MapType  = googleMapType;
 }
コード例 #17
0
 public string GetMapUri(float latitude, float longitude, int zoom, int scale, int width, int height, GoogleMapType mapType, GoogleImageFormat format)
 {
     return(GetMapUri(latitude, longitude, zoom, scale, width, height, mapType, format, null));
 }
コード例 #18
0
 public GoogleTileSource(GoogleMapType mapType)
     : this(new GoogleRequest(mapType))
 {
 }
コード例 #19
0
 /// <summary>
 /// Creates a control for creating an url for Google Static Maps.
 /// </summary>
 /// <param name="url">The Url helper instance that this method extends.</param>
 /// <param name="width">Width of the image in pixels.</param>
 /// <param name="height">Height of the image in pixels.</param>
 /// <param name="mapType">Type of map.</param>
 /// <returns>A control that allows further configuration of the map.</returns>
 public static GoogleStaticMapControl GoogleStaticMap(this UrlHelper url, int width, int height, GoogleMapType mapType)
 {
     return new GoogleStaticMapControl(width, height, mapType)
         .AsUrl();
 }
コード例 #20
0
 /// <summary>
 /// Creates a control for creating an img tag for Google Static Maps.
 /// </summary>
 /// <param name="html">The HTML helper instance that this method extends.</param>
 /// <param name="width">Width of the image in pixels.</param>
 /// <param name="height">Height of the image in pixels.</param>
 /// <param name="mapType">Type of map.</param>
 /// <param name="htmlAttributes">An object that contains the HTML attributes to set for the element.</param>
 /// <returns>A control that allows further configuration of the map.</returns>
 public static GoogleStaticMapControl GoogleStaticMap(this HtmlHelper html, int width, int height, GoogleMapType mapType, object htmlAttributes)
 {
     return new GoogleStaticMapControl(width, height, mapType)
         .AsImage(htmlAttributes);
 }
コード例 #21
0
 /// <summary>
 /// Creates a control for creating an img tag for Google Static Maps.
 /// </summary>
 /// <param name="html">The HTML helper instance that this method extends.</param>
 /// <param name="width">Width of the image in pixels.</param>
 /// <param name="height">Height of the image in pixels.</param>
 /// <param name="mapType">Type of map.</param>
 /// <returns>A control that allows further configuration of the map.</returns>
 public static GoogleStaticMapControl GoogleStaticMap(this HtmlHelper html, int width, int height, GoogleMapType mapType)
 {
     return GoogleStaticMap(html, width, height, mapType, null);
 }
コード例 #22
0
        public string GetMapUri(float latitude, float longitude, int zoom, int scale, int width, int height, GoogleMapType mapType, GoogleImageFormat format, IList <TrackCoordinate> trackCoordinates)
        {
            var requestUri = string.Empty;

            for (int i = _resolutionModifierStep; i <= _maxResolutionModifierStep; i++)
            {
                if (i > _resolutionModifierStep)
                {
                    _logger.LogTrace($"Attempting to build Track Map requestUri at resolution of {i}");
                }
                string pathParameter = BuildMapPath(trackCoordinates, i);

                requestUri = string.Format(
                    "https://maps.googleapis.com/maps/api/staticmap?center={0}&zoom={1}&size={2}&maptype={3}&format={4}{5}&key={6}",
                    $"{latitude},{longitude}",
                    zoom,
                    $"{width}x{height}",
                    GoogleMapHelper.GetGoogleMapTypeString(mapType),
                    GoogleMapHelper.GetGoogleFormatString(format),
                    pathParameter,
                    GoogleMapHelper.ApiKey);

                if (requestUri.Length < 8192)
                {
                    break;
                }
                else if (requestUri.Length > 8192 && i >= _maxResolutionModifierStep)
                {
                    throw new InvalidOperationException($"requestUri too long: {requestUri.Length}");
                }
            }

            return(requestUri);
        }
コード例 #23
0
ファイル: TileLayerSample.cs プロジェクト: lishxi/_SharpMap
        private static Map InitializeMapGoogle(GoogleMapType mt)
        {
            Map map = new Map();

            GoogleRequest req;
            ITileSource tileSource;
            TileLayer tileLayer;
           
            if (mt == (GoogleMapType.GoogleSatellite | GoogleMapType.GoogleLabels))
            {
                req = new GoogleRequest(GoogleMapType.GoogleSatellite);
                tileSource = new GoogleTileSource(req);
                tileLayer = new TileLayer(tileSource, "TileLayer - " + GoogleMapType.GoogleSatellite);
                map.Layers.Add(tileLayer);
                req = new GoogleRequest(GoogleMapType.GoogleLabels);
                tileSource = new GoogleTileSource(req);
                mt = GoogleMapType.GoogleLabels;
            }
            else
            {
                req = new GoogleRequest(mt);
                tileSource = new GoogleTileSource(req);
            }

            tileLayer = new TileLayer(tileSource, "TileLayer - " + mt);
            map.Layers.Add(tileLayer);
            map.ZoomToBox(tileLayer.Envelope);
            return map;
        }
コード例 #24
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        /// <param name="html">The HTML helper instance that this method extends.</param>
        /// <param name="width">Width of the image in pixels.</param>
        /// <param name="height">Height of the image in pixels.</param>
        /// <param name="mapType">Type of map.</param>
        public GoogleStaticMapControl(int width, int height, GoogleMapType mapType)
        {
            _urlBuilder = new GoogleStaticMapUrlBuilder(width, height, mapType);

            _renderMode = RenderMode.Image;
        }