MFC之 MapWinGis叠加百度瓦片地图

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). */

// BaiduProjection.h 

#pragma once
#include "BaseProvider.h"
#include "BaiduProjection.h"
#include <math.h>

class BaiduBaseProvider: public BaseProvider
{
protected:
    CString Styles;
public:
	BaiduBaseProvider() 
	{
		_minZoom = 4;
		_maxZoom = 19;

		_refererUrl = "http://maps.baidu.com/";
		_licenseUrl = "https://mapwingis.codeplex.com/wikipage?title=baidutiles";
		int year = Utility::GetCurrentYear();
		_copyright.Format(L"Copyright @ %d, Baidu,All Rights Reserved", year);
		_urlFormat =  "http://p3.map.gtimg.com/maptilesv2/%d/%d/%d/%d_%d.png?version=20130701";
		//"http://online%d.map.bdimg.com/tile/?qt=tile&x=%s&y=%s&z=%d&styles=%s";
		
		_projection = new BaiduProjection();//MercatorProjection();
	}
	
	CString MakeTileImageUrl(CPoint &pos, int zoom)
	{
		int offsetX = pow((double)2, zoom-1);
		int offsetY = offsetX - 1;

		int numX = pos.x - offsetX;
		int numY = -pos.y + offsetY;

		CString sNumX;
		sNumX.Format("%d", numX);
		sNumX.Replace("-", "M");

		CString sNumY;
		sNumY.Format("%d", numY);
		sNumY.Replace("-", "M");

 		CString s;
// 		int x = pos.x;
// 		int y = pos.y;
// 		int z = zoom;
// 		y = pow(double(z), 2) - 1 - y;
		//s.Format(UrlFormat, zoom, floor((double)x/16), floor((double)y/16), x, y);
		s.Format(_urlFormat, GetServerNum(pos, 3), sNumX, sNumY, zoom, Styles);
		return s;//"http://online1.map.bdimg.com/onlinelabel/?qt=tile&x=709&y=216&z=12&styles=pl&udt=20151031&scaler=1&p=1";
		// 原来:http://q4.baidu.com/it/u=x=12730;y=4778;z=16;v=016;type=web&fm=44
		// 更新:http://online1.map.bdimg.com/tile/?qt=tile&x=23144&y=6686&z=17&styles=pl
	}
};

class BaiduMapProvider: public BaiduBaseProvider
{
public:
	BaiduMapProvider() 
	{
		Styles = "pl";
		Id = tkTileProvider::BaiduMaps;
		Name = "BaiduMaps";
		_subProviders.push_back(this);
		_urlFormat = "http://online%d.map.bdimg.com/tile/?qt=tile&x=%s&y=%s&z=%d&styles=pl";
			//"http://online%d.map.bdimg.com/onlinelabel/?qt=tile&x=%s&y=%s&z=%d&styles=sl&v=083&udt=20150815&p=1";
	}

	CString MakeTileImageUrl(CPoint &pos, int zoom)
	{
// 		pos.x = 554;
// 		pos.y = 401;
// 		zoom = 10;
		int offsetX = pow((double)2, zoom-1);
		int offsetY = offsetX - 1;

		int numX = pos.x - offsetX;
		int numY = -pos.y + offsetY;

		CString sNumX;
		sNumX.Format("%d", numX);
		sNumX.Replace("-", "M");

		CString sNumY;
		sNumY.Format("%d", numY);
		sNumY.Replace("-", "M");

		CString s;
		// 		int x = pos.x;
		// 		int y = pos.y;
		// 		int z = zoom;
		// 		y = pow(double(z), 2) - 1 - y;
		//s.Format(UrlFormat, zoom, floor((double)x/16), floor((double)y/16), x, y);
		s.Format(_urlFormat, GetServerNum(pos, 8), sNumX, sNumY, zoom, Styles);
		return s;//"http://online1.map.bdimg.com/onlinelabel/?qt=tile&x=709&y=216&z=12&styles=pl&udt=20151031&scaler=1&p=1";
		// 原来:http://q4.baidu.com/it/u=x=12730;y=4778;z=16;v=016;type=web&fm=44
		// 更新:http://online1.map.bdimg.com/tile/?qt=tile&x=23144&y=6686&z=17&styles=pl
	}
};

class BaiduSatelliteProvider: public BaiduBaseProvider
{
public:
	BaiduSatelliteProvider() 
	{
		//maxZoom = 13;
		Styles = "sate";
		Id = tkTileProvider::BaiduSatellite;
		Name = "BaiduSatellite";
		_urlFormat = "http://shangetu%d.map.bdimg.com/it/u=x=%s;y=%s;z=%d;v=009;type=%s&fm=46";
		_subProviders.push_back(this);
	}

	CString MakeTileImageUrl(CPoint &pos, int zoom)
	{
		int offsetX = pow((double)2, zoom-1);
		int offsetY = offsetX - 1;

		int numX = pos.x - offsetX;
		int numY = -pos.y + offsetY;

		CString sNumX;
		sNumX.Format("%d", numX);
		sNumX.Replace("-", "M");

		CString sNumY;
		sNumY.Format("%d", numY);
		sNumY.Replace("-", "M");

		CString s;
		// 		int x = pos.x;
		// 		int y = pos.y;
		// 		int z = zoom;
		// 		y = pow(double(z), 2) - 1 - y;
		//s.Format(UrlFormat, zoom, floor((double)x/16), floor((double)y/16), x, y);
		s.Format(_urlFormat, GetServerNum(pos, 3), sNumX, sNumY, zoom, Styles);
		return s;//"http://online1.map.bdimg.com/onlinelabel/?qt=tile&x=709&y=216&z=12&styles=pl&udt=20151031&scaler=1&p=1";
		// 原来:http://q4.baidu.com/it/u=x=12730;y=4778;z=16;v=016;type=web&fm=44
		// 更新:http://online1.map.bdimg.com/tile/?qt=tile&x=23144&y=6686&z=17&styles=pl
	}
};

class BaiduSatelliteHybridProvider: public BaiduBaseProvider
{
public:
	BaiduSatelliteHybridProvider() 
	{
		//maxZoom = 13;http://shangetu2.map.bdimg.com/it/u=x=7;y=M1;z=5;v=009;type=sate&fm=46&udt=20150601
		Styles = "sl";
		Id = tkTileProvider::BaiduSatelliteHybrid;
		Name = "BaiduSatelliteHybrid";
		_urlFormat = "http://online%d.map.bdimg.com/onlinelabel/?qt=tile&x=%s&y=%s&z=%d&styles=%s&v=083&udt=20150815&p=0";
		_subProviders.push_back(this);

		//http://shangetu2.map.bdimg.com/it/u=x=42;y=16;z=8;v=009;type=sate&fm=46&udt=20150601	// 卫星底图
		//http://online3.map.bdimg.com/onlinelabel/?qt=tile&x=47&y=16&z=8&styles=sl&v=083&udt=20150815&p=0 路线图
	}
};

2、效果图

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值