在地图上添加POI
使用Tangram的Marker, 可以在地图上做各种标记, 效果图:

Tangram是通过Marker在地图上添加标记的,Marker分Point, Polyline和Polygon三种, 分别对应点、线、面三种几何体。
Tangram使用统一的Marker接口来管理Marker:
namespace Tangram {
class Map {
public:
// Add a marker object to the map and return an ID for it; an ID of 0 indicates an invalid marker;
// the marker will not be drawn until both styling and geometry are set using the functions below.
MarkerID markerAdd();
// Remove a marker object from the map; returns true if the marker ID was found and successfully
// removed, otherwise returns false.
bool markerRemove(MarkerID _marker);
// Set the styling for a marker object; _styling is a string of YAML that specifies a 'draw rule'
// according to the scene file syntax; returns true if the marker ID was found and successfully
// updated, otherwise returns false.
bool markerSetStyling(MarkerID _marker, const char* _styling);
// Set a bitmap to use as the image for a point marker; _data is a buffer of RGBA pixel data with
// length of _width * _height; pixels are in row-major order beginning from the bottom-left of the
// image; returns true if the marker ID was found and successfully updated, otherwise returns false.
bool markerSetBitmap(MarkerID _marker, int _width, int _height, const unsigned int* _data);
// Set the geometry of a marker to a point at the given coordinates; markers can have their
// geometry set multiple times with possibly different geometry types; returns true if the
// marker ID was found and successfully updated, otherwise returns false.
bool markerSetPoint(MarkerID _marker, LngLat _lngLat);
// Set the geometry of a marker to a point at the given coordinates; if the marker was previously
// set to a point, this eases the position over the given duration in seconds with the given EaseType;
// returns true if the marker ID was found and successfully updated, otherwise returns false.
bool markerSetPointEased(MarkerID _marker, LngLat _lngLat, float _duration, EaseType _ease);
// Set the geometry of a marker to a polyline along the given coordinates; _coordinates is a
// pointer to a sequence of _count LngLats; markers can have their geometry set multiple times
// with possibly different geometry types; returns true if the marker ID was found and
// successfully updated, otherwise returns false.
bool markerSetPolyline(MarkerID _marker, LngLat* _coordinates, int _count);
// Set the geometry of a marker to a polygon with the given coordinates; _counts is a pointer
// to a sequence of _rings integers and _coordinates is a pointer to a sequence of LngLats with
// a total length equal to the sum of _counts; for each integer n in _counts, a polygon is created
// by taking the next n LngLats from _coordinates, with winding order and internal polygons
// behaving according to the GeoJSON specification; markers can have their geometry set multiple
// times with possibly different geometry types; returns true if the marker ID was found and
// successfully updated, otherwise returns false.
bool markerSetPolygon(MarkerID _marker, LngLat* _coordinates, int* _counts, int _rings);
// Set the visibility of a marker object; returns true if the marker ID was found and successfully
// updated, otherwise returns false.
bool markerSetVisible(MarkerID _marker, bool _visible);
// Set the ordering of point marker object relative to other markers; higher values are drawn 'above';
// returns true if the marker ID was found and successfully updated, otherwise returns false.
bool markerSetDrawOrder(MarkerID _marker, int _drawOrder);
// Remove all marker objects from the map; Any marker IDs previously returned from 'markerAdd'
// are invalidated after this.
void markerRemoveAll();
};
}
我觉得使用统一的接口来处理Marker在易用性有些欠缺, 因此决定使用单独的class来处理: Marker, Polyline, Polygon.
Tangram使用各种style来处理Marker的显示效果, 可能是对Tangram的实现还没有了解清楚, 暂时没有发现直接给一个Marker加上label的方法, 只好采用了一个hack的方法: 同时生成两个Tangram::Marker, 一个用来显示icon, 另一个用来显示label。
头文件:
class MarkerImpl: public Marker
{
public:
MarkerImpl(Tangram::Map* map);
~MarkerImpl(); // Mark interface
private:
virtual void setImage(const std::string &iconURI) override;
virtual void setTitle(const std::string &title) override; private:
Tangram::Map* m_map;
Tangram::MarkerID m_iconID; //use this marker to show icon
Tangram::MarkerID m_labelID; //use this marker to show label };
实现
void MarkerImpl::setImage(const std::string &iconURI)
{
QImage img(QString(iconURI.c_str())); int width = img.width();
int height = img.height();
auto argb = new unsigned int [width * height];
for(int h=height-; h>-; --h){
for(int w=; w<width; ++w){
int pix = img.pixelColor(w, h).rgba();
int pb = (pix >> ) & 0xff;
int pr = (pix << ) & 0x00ff0000;
int pix1 = (pix & 0xff00ff00) | pr | pb;
argb[w + h*width] = pix1;
}
} m_map->markerSetBitmap(m_iconID, width, height, argb); const char* MARKER_ICON_STYLE = "{ style: 'points', color: 'white', size: [%1px, %1px], order: 100, collide: false }";
QString iconStyle = QString(MARKER_ICON_STYLE).arg(width).arg(height);
m_map->markerSetStyling(m_iconID, iconStyle.toStdString().c_str()); delete[] argb;
} void MarkerImpl::setTitle(const std::string &title)
{
const char* MARKER_TEXT_STYLE = "{ style: 'text', text_source: 'function(){ return \"%1\"}', offset: [0px, 24px], text_wrap: false}";
QString labelStyle = QString(MARKER_TEXT_STYLE).arg(title.c_str());
m_map->markerSetStyling(m_labelID, labelStyle.toStdString().c_str());
}
Tangram的核心特性是可配置性, 通过一个YAML scene文件, 定义不同的style, 可以配置几乎所有的显示效果。 这是一个很大的话题, 以后单独分析
在地图上添加POI的更多相关文章
- 在地图上添加POI(二)
在上一篇中实现一个icon + label的Marker需要使用两个Tangram的Marker, 今天分析了Tangram的源码后, 发现Tangram时支持单一Marker同时显示的, 这需要使用 ...
- GMap.Net开发之在地图上添加多边形
上一篇介绍了在GMap上添加自定义标签(GMapMarker),这篇介绍在GMap上添加多边形(GMapPolyogn),并且介绍如何在地图上画任意的多边形. 如果已经知道了多边形的各个点的位置,就可 ...
- google maps js v3 api教程(2) -- 在地图上添加标记
原文链接 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 我们在创建地图 ...
- 【百度地图API】如何在地图上添加标注?——另有:坐标拾取工具+打车费用接口介绍
原文:[百度地图API]如何在地图上添加标注?--另有:坐标拾取工具+打车费用接口介绍 摘要: 在这篇文章中,你将学会,如何利用百度地图API进行标注.如何使用API新增的打车费用接口. ------ ...
- 【百度地图API】建立全国银行位置查询系统(三)——如何在地图上添加银行标注
原文:[百度地图API]建立全国银行位置查询系统(三)--如何在地图上添加银行标注 <摘要>你将在第三章中学会以下知识: 如何在地图上添加带银行logo的标注?(你也可以换成商场logo, ...
- 微信小程序--地图上添加图片
如何在微信小程序地图添加上,添加图片? 在微信小程序中,地图的层级最高,所以我们没有办法,通过定位,在地图上添加图片等信息; 处理办法: 添加控件:controls; 其中有个属性position,进 ...
- 利用WPF建立自己的3d gis软件(非axhost方式)(四)在地图上添加FrameworkElement
原文:利用WPF建立自己的3d gis软件(非axhost方式)(四)在地图上添加FrameworkElement 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUw ...
- Google Map API v2 (三)----- 地图上添加标记(Marker),标记info窗口,即指定经纬度获取地址字符串
接上篇 http://www.cnblogs.com/inkheart0124/p/3536322.html 1,在地图上打个标记 private MarkerOptions mMarkOption; ...
- ArcGIS 在地图上添加标注
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- QQ空间的“神奇”图片
近几天好多朋友问我qq空间出现的神奇图片原理,最近比较烦,事情比较多,一直没理.加上我对PHP之类的语言也一知半解. 今天闲了看了一下QQ空间,发现这个很早以前就有人写过这样的帖子了 看别人解释 (转 ...
- zzuli oj 1167逆转数(指针专题)
Description 任意给你一个整数,这个数可能很大(最长不超过100位),你能求出它的逆转数吗? 逆转数定义如下: 1.一个末尾没有0的整数,它的逆转数就是各位数字逆序输出: 2.一个负数 ...
- javax.servlet不存在的问题
摘自:http://blog.csdn.net/tgeh23/article/details/2216682 最近在学习servlet,看书看的似乎还比较理想就想上机试下,这一试就发现,问题来 ...
- sql server 表空间
在SqlServer2005中,建表时是默认把所有的表都保存在PRIMARY默认表空间中的.当数据库中表很多,并且数据量很大时,会导致数据库性能严重下降,有必要将一些大的表放到不同的表空间中去.主要的 ...
- SQL 维护用得到的监控语句
使用DMV来分析SQL Server启动以来累计使用CPU资源最多的语句.例如下面的语句就可以列出前50名 s2.dbid, ( , ( ( ) )) AS sql_statement, execut ...
- sql server中创建链接服务器图解教程
转自sql server中创建链接服务器图解教程 1.展开服务器对象-->链接服务器-->右击"新建链接服务器" 注意:必须以数据库管理员身份登录(通常也就是sa帐号) ...
- Entity FrameWork知识点汇总
这里罗列的并非EF的所有知识点 ,只是我在开发过程中遇到或者使用到的知识,记录于此, 备忘 1:EF的三种创建方式 A:Database First B:Model First C:Code Firs ...
- The APR based Apache Tomcat Native library
Tomcat启动的时候出现下面这样的提示: 2015-11-06 14:24:12 org.apache.catalina.core.AprLifecycleListener init 信息: The ...
- 李洪强iOS开发之-环信02.2_环信官网下载环信 SDK
李洪强iOS开发之-环信02.2_环信官网下载环信 SDK 移动客服即时通讯云 iOS SDK 当前版本:V3.1.4 2016-07-08 [ 版本历史 ] | 开发指南 | 知识库 | Demo源 ...
- [收藏转贴]构建RESTful风格的WCF服务
RESTful Wcf是一种基于Http协议的服务架构风格. 相较 WCF.WebService 使用 SOAP.WSDL.WS-* 而言,几乎所有的语言和网络平台都支持 HTTP 请求. RESTf ...