全景图中常用的功能点有:
1.皮肤定制,指定皮肤中icon的位置、图片、样式等
2.音频的播放与暂停
3.地图路线
4.添加logo或地标
5.点击事件
此次总结地图分享功能点,步骤如下:
1.在xml中引入高德地图插件
<plugin name="nv" keep="true" devices="mobile" url="js/action.js"
desloc="39.9178540000,116.3970060000" desname="北京故宫"/>
2.在xml中写地图调用方法
<action name="naviToMap">
plugin[nv].setdes(get(plugin[nv].desloc),get(plugin[nv].desname));
plugin[nv].navigation();
</action>
复制代码
3.在xml中写地图iocn,配置oclick
<layer name="skin_btn_mymap" style="skin_base|skin_glow" crop="0|256|64|64" align="right" x="15" y="-250" scale="0.5" onclick="naviToMap();js(clickBury('travel_panorama_locate_click','travel_panorama_locate');)" />
复制代码
4.编写获取当前位置、跳转地图js,当前位置的获取需要注意,ios中仅支持https协议
var krpanoplugin = function () {
var local = this;
// save the 'this' pointer from the current plugin object
var krpano = null;
// the krpano and plugin interface objects
var plugin = null;
var plugincanvas = null;
// optionally - a canvas object for graphic content
var plugincanvascontext = null;
// registerplugin - startup point for the plugin (required)
// - krpanointerface = krpano interface object
// - pluginpath = string with the krpano path of the plugin (e.g. "plugin[pluginname]")
// - pluginobject = the plugin object itself (the same as: pluginobject = krpano.get(pluginpath) )
local.registerplugin = function (krpanointerface, pluginpath, pluginobject) {
krpano = krpanointerface;
plugin = pluginobject;
// add a from xml callable functions:
plugin.setdes=setdes;
plugin.navigation=navigation;
}
var desLocation;
var desName;
function setdes(des,name) {
desLocation=des;
desName=name;
//alert(desLocation);
//alert(desName);
}
function navigation()
{
if (navigator.geolocation){
if(isiOS){
//从app端获取定位信息(解决用户拒绝定位后无法重新定位)
var position = {
coords:{
longitude:"",
latitude:""
}
};
AHJavascriptBridge.invoke('fetchLocation',{},function(args,callback){
position.coords.longitude = args.longitude;
position.coords.latitude = args.latitude;
showPosition(position);
});
}else{
//自己获取定位
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
}
else{
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position)
{
var mapUrl = encodeURIComponent("http://m.amap.com/?from="+position.coords.latitude+","+position.coords.longitude+"(我的位置)&to="+desLocation+"("+desName+")&type=0");
if(myversion==1){//安卓
AHJavascriptBridge.invoke('goMap',{"url":mapUrl,"title":"从我的位置到"+desName});
}else{//M端
window.location.href="http://m.amap.com/?from="+position.coords.latitude+","+position.coords.longitude+"(我的位置)&to="+desLocation+"("+desName+")&type=0";
}
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
alert("请在手机设置里修改定位权限");
break;
case error.POSITION_UNAVAILABLE:
alert("Location information is unavailable.");
break;
case error.TIMEOUT:
x.innerHTML=
alert("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
alert("An unknown error occurred.");
break;
}
}
// unloadplugin - end point for the plugin (optionally)
// - will be called from krpano when the plugin will be removed
// - everything that was added by the plugin (objects,intervals,...) should be removed here
local.unloadplugin = function () {
plugin = null;
krpano = null;
}
复制代码
};