MFC之 MapWinGis叠加谷歌瓦片地图

本文档展示了如何使用C++实现谷歌地图API,包括谷歌地图、卫星图、混合图和地形图的提供者类。代码中定义了不同类型的GoogleBaseProvider子类,用于生成不同类型的瓦片图片URL,并实现了安全词的获取方法。这些类为地图渲染提供了基础支持。
摘要由CSDN通过智能技术生成

1、核心代码

/**************************************************************************************
 * Project: MapWindow Open Source (MapWinGis ActiveX control)
 **************************************************************************************
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at http://www.mozilla.org/mpl/
 * See the License for the specific language governing rights and limitations
 * under the License.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 **************************************************************************************
 * Contributor(s):
 * (Open source contributors should list themselves and their modifications here). */

#pragma once
#include "BaseProvider.h"

// *******************************************************
//			GoogleBaseProvider
// *******************************************************
class GoogleBaseProvider : public BaseProvider
{
protected:
	CString server;
	CString UrlFormatServer;
	CString UrlFormatRequest;
	CString SecureWord;
	CString Sec1;
public:
	GoogleBaseProvider()
	{
		LanguageStr = "zh-CN";
		SecureWord = "Galileo";
		Sec1 = "&s=";
		server = "google.cn";
		_refererUrl.Format("http://maps.%s/", server);
		_licenseUrl = "https://mapwingis.codeplex.com/wikipage?title=googletiles";
		int year = Utility::GetCurrentYear();
		_copyright.Format(L"Copyright @ %d, Google,All Rights Reserved", year);
		this->_projection = new MercatorProjection();
		this->_maxZoom = 20;
	}

	CString MakeTileImageUrl(CPoint &pos, int zoom)
	{
		CString sec1 = "";
		CString sec2 = "";
		GetSecureWords(pos, sec1, sec2);

		CString s;
		s.Format(_urlFormat, UrlFormatServer, GetServerNum(pos, 4), server, UrlFormatRequest, Version, LanguageStr, pos.x, sec1, pos.y, zoom, sec2);
		return s;//http://mt3.google.cn/vt/lyrs=m@285000000&hl=zh-CN&x=7&y=12&z=5&s=G
	}

	void GetSecureWords(CPoint &pos, CString &sec1, CString &sec2)
	{
		sec1 = "";
		sec2 = "";
		int seclen = ((pos.x * 3) + pos.y) % 8;
		sec2 = SecureWord.Left(seclen);
		if (pos.y >= 10000 && pos.y < 100000)
		{
			sec1 = Sec1;
		}
	}
};

// *******************************************************
//			GoogleBaseProvider
// *******************************************************
class GoogleMapProvider : public GoogleBaseProvider
{
public:
	GoogleMapProvider()
	{
		UrlFormatServer = "mt";
		UrlFormatRequest = "vt";	
		Version = "m@285000000";		
		/*
			m:路线图  
			t:地形图  
			p:带标签的地形图  
			s:卫星图  
			y:带标签的卫星图  
			h:标签层(路名、地名等)
		*/
		Id = tkTileProvider::GoogleMaps;
		Name = "GoogleMaps";
		_urlFormat = "http://%s%d.%s/%s/lyrs=%s&hl=%s&x=%d%s&y=%d&z=%d&s=%s";
		_subProviders.push_back(this);
	}
};

// *******************************************************
//			GoogleSatelliteProvider
// *******************************************************
class GoogleSatelliteProvider : public GoogleBaseProvider
{
public:
	GoogleSatelliteProvider()
	{
		UrlFormatServer = "mt";
		UrlFormatRequest = "vt";	
		Version = "y@285000000";		
		/*
			m:路线图  
			t:地形图  
			p:带标签的地形图  
			s:卫星图  
			y:带标签的卫星图  
			h:标签层(路名、地名等)
		*/
		Id = tkTileProvider::GoogleSatellite;
		Name = "GoogleSatellite";
		_urlFormat = "http://%s%d.%s/%s/lyrs=%s&hl=%s&x=%d%s&y=%d&z=%d&s=%s";
		_subProviders.push_back(this);
	}
};

// *******************************************************
//			GoogleHybridProvider
// *******************************************************
class GoogleHybridProvider : public GoogleBaseProvider
{
public:
	GoogleHybridProvider(CTileProviders* list)
	{
		UrlFormatServer = "mt";
		UrlFormatRequest = "vt";
		Version = "h@285000000";
		Id = tkTileProvider::GoogleHybrid;
		Name = "GoogleHybrid";
		_urlFormat = "http://%s%d.%s/%s/lyrs=%s&hl=%s&x=%d%s&y=%d&z=%d&s=%s";
		_subProviders.push_back(list->get_Provider(tkTileProvider::GoogleSatellite));
		_subProviders.push_back(this);
	}
};

// *******************************************************
//			GoogleTerrainProvider
// *******************************************************
class GoogleTerrainProvider : public GoogleBaseProvider
{
public:
	GoogleTerrainProvider()
	{
		UrlFormatServer = "mt";
		UrlFormatRequest = "vt";
		Version = "t@164,r@285000000";
		Id = tkTileProvider::GoogleTerrain;
		Name = "GoogleTerrain";
		_urlFormat = "http://%s%d.%s/%s/v=%s&hl=%s&x=%d%s&y=%d&z=%d&s=%s";
		_subProviders.push_back(this);
	}
};

2、效果图

后期奉上,敬请关注..

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值