Android 矢量室内地图开发实例
程序员文章站
2024-02-27 15:41:03
矢量室内地图开发
因为公司项目的需要,需要开发一套室内地图,并实现路线的规划功能。因为之前没做过这方面的开发,相关的资料也比较少,所以只能一个人去摸索。刚开始我是使用一般...
矢量室内地图开发
因为公司项目的需要,需要开发一套室内地图,并实现路线的规划功能。因为之前没做过这方面的开发,相关的资料也比较少,所以只能一个人去摸索。刚开始我是使用一般的位图去当作的地图,但是这个也让我在后面吃了不少的苦头。
我们知道地图一般都会有缩放和拖拽等功能,正当我把一样利用位图开发的地图样例时,我发现了不少的问题:
1、位图缩放会失真;
2、图片加载比较慢;
3、会导致客户端内存溢出
。。。
因为这些问题,我不得不放弃这种方法。要解决上面的问题只能使用矢量图进行开发了,于是我使用了html5进行了矢量图的开发,不仅解决了地图缩放失真等问题,还同时适用于android、ios等,个人感觉效果还是相当的好,下面我来介绍一下此种方法:
一、矢量地图
因为是矢量地图,那肯定得要有矢量图的数据,那么可能就得去了解一下svg,在这里我就不进行介绍了,大家想学习的可以到网上搜索到很多相关的介绍,下面是地图规定的一种格式:
/** * created by administrator on 2015/11/5. */ $.fn.vectormap('addmap', 'us_aea_en', { "insets": [ {"width": 220, "top": 440, "height": 146.9158157558812, "bbox": [{"y": -8441281.712315228, "x": -5263934.893342895}, {"y": -6227992.545028123, "x": -1949631.2950683108}], "left": 0}, {"width": 80, "top": 460, "height": 129.05725678001465, "bbox": [{"y": -4207380.690946597, "x": -5958501.652314129}, {"y": -3658201.4570359783, "x": -5618076.48127754}], "left": 245}, {"width": 900.0, "top": 0, "height": 550.2150229714246, "bbox": [{"y": -5490839.2352678, "x": -2029243.6460439637}, {"y": -2690044.485299302, "x": 2552083.9617675776}], "left": 0} ], "paths": { "bh-中国建设银行":{"path":"m567.065,977.503h56.717v120.192h-56.717v977.503z" , "name":"中国建设银行"}, "bh-煌上煌":{"path":"m726.819,646.031h103.775v49.061h726.819v646.031z" , "name":"煌上煌"}, "bh-佰汇服务中心":{"path":"m746.113,458.64v46.49v3.559v46.49h80.856v-46.49v-3.559v-46.49h746.113z" , "name":"佰汇服务中心"}, "bh-01":{"path":"m746.113,365.117h84.245v96.714h-84.245v365.117z" , "name":"none"}, "bh-九疑米粉":{"path":"m598.614,599.228v46.803v2.258v46.802h131.719v-46.802v-2.258v-46.803h598.614z" , "name":"九疑米粉"}, "bh-02":{"path":"m598.614,552.426h131.719v49.061h598.614v552.426z" , "name":"none"}, "bh-中国福利彩票":{"path":"m598.614,505.624h79.599v49.061h-79.599v505.624z" , "name":"中国福利彩票"}, "bh-03":{"path":"m598.614,459.134h79.599v49.061h-79.599v459.134z" , "name":"none"}, "bh-04":{"path":"m598.614,402.612h79.599v59.22h-79.599v402.612z" , "name":"none"}, "bh-黑龙茶":{"path":"m621.338,977.503h56.716v120.192h-56.716v977.503z" , "name":"黑龙茶"}, "bh-蒸美味":{"path":"m675.61,841.39h72.875v256.305h675.61v841.39z" , "name":"蒸美味"}, "bh-集信饮食":{"path":"m828.102,921.006h60.87v176.689h-60.87v921.006z" , "name":"集信饮食"}, "bh-衣生衣世":{"path":"m828.102,841.39h60.87v81.99h-60.87v841.39z" , "name":"衣生衣世"}, "bh-佰汇公寓酒店":{"path":"m886.33,549.978h61.136v142.816h886.33v549.978z" , "name":"佰汇公寓酒店"}, "bh-水果美容体":{"path":"m889.937,505.13h74.252v47.925h-74.252v505.13z" , "name":"水果美容体"}, "bh-纤艺美甲":{"path":"m889.937,460.764h74.252v47.924h-74.252v460.764z" , "name":"纤艺美甲"}, }, "height":1200.333,//地图的高 "projection": { "type": "aea", "centralmeridian": -100.0 }, "width": 2384.0//地图宽 });
二、设置地图的缩放量
zoommin:0.5,
zoommax:8,
三、设置地图背景颜色
backgroundcolor:'#fff',
四、设置店铺文字的随地图缩放
onviewportchange: function(e, scale, transx, transy){ console.log('viewportchange', scale, transx, transy); var old = parseint($("text").css("fontsize")); console.log("字体大小:" + old); if( scale < 2.5 || scale == 2.5 ){ $("text").hide(); } else if(scale > 2.5 && scale < 3.5 || scale == 3.5){ $("text").css("fontsize", 9); $("text").show(); } else if(scale > 3.5 && scale < 4.5 || scale == 4.5){ $("text").css("fontsize", 10); $("text").show(); } else if(scale > 4.5 && scale < 5.5 || scale == 5.5){ $("text").css("fontsize", 14); $("text").show(); } else{ $("text").css("fontsize", 16); $("text").show(); } },
五、点击商铺触发的方法
onmarkerover: function(event, index){ console.log('marker-over', index); }, onmarkerout: function(event, index){ console.log('marker-out', index); }, onmarkerclick: function(event, index){ console.log('marker-click', index); }, onmarkerselected: function(event, index, isselected, selectedmarkers){ console.log('marker-select', index, isselected, selectedmarkers); if (window.localstorage) { window.localstorage.setitem( 'jvectormap-selected-markers-bh-1', json.stringify(selectedmarkers) ); } },
六、效果图
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!