Here api 使用HERE支持不同地图视图的多语言支持
目前,我正在尝试用德语显示带有JavaScript API的HERE地图。 根据这一点,可以更改地图的语言。当地图第一次加载时,这对德语很有效。但是,当地图视图更改为“卫星”时,这些设置似乎丢失。在我在线找到的所有多语言示例中,更改地图视图的选项都被禁用。对于所有可用的视图,是否可以将语言设置为德语,或者此自定义仅限于一个视图,而我需要禁用其他视图Here api 使用HERE支持不同地图视图的多语言支持,here-api,Here Api,目前,我正在尝试用德语显示带有JavaScript API的HERE地图。 根据这一点,可以更改地图的语言。当地图第一次加载时,这对德语很有效。但是,当地图视图更改为“卫星”时,这些设置似乎丢失。在我在线找到的所有多语言示例中,更改地图视图的选项都被禁用。对于所有可用的视图,是否可以将语言设置为德语,或者此自定义仅限于一个视图,而我需要禁用其他视图 提前感谢,下面的团队DG7是完整的示例代码,可以用中文显示地图的所有视图。您可以根据需要进行更改。 请使用您自己的应用程序id和应用程序代码。下面代
提前感谢,下面的团队DG7是完整的示例代码,可以用中文显示地图的所有视图。您可以根据需要进行更改。 请使用您自己的应用程序id和应用程序代码。下面代码中的主要代码段是createDefaultlayers,您可以在其中指定所有层的语言参数
var defaultLayers = platform.createDefaultLayers({
tileSize: pixelRatio === 1 ? 256 : 512,
ppi: pixelRatio === 1 ? undefined : 320,
lg: 'CHI'
});
快乐编码
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1533195059" />
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
</head>
<body>
<div id="map" style="width: 100%; height: 400px; background: grey" />
<script type="text/javascript" charset="UTF-8" >
/**
* Switches the map language to simplified Chinese
*
* @param {H.Map} map A HERE Map instance within the application
* @pama {H.service.Platform} platform A stub class to access HERE services
*/
function switchMapLanguage(map, platform){
var mapTileService = platform.getMapTileService({
type: 'base'
}),
// Our layer will load tiles from the HERE Map Tile API
chineseMapLayer = mapTileService.createTileLayer(
'maptile',
'normal.day',
pixelRatio === 1 ? 256 : 512,
'png8',
{lg: 'CHI', ppi: pixelRatio === 1 ? undefined : 320}
);
map.setBaseLayer(chineseMapLayer);
// Display default UI components on the map and change default
// language to simplified Chinese.
// Besides supported language codes you can also specify your custom translation
// using H.ui.i18n.Localization.
var ui = H.ui.UI.createDefault(map, defaultLayers, 'zh-CN');
}
/**
* Boilerplate map initialization code starts below:
*/
//Step 1: initialize communication with the platform
var platform = new H.service.Platform({
app_id: 'YOUR-APP-ID',
app_code: 'YOUR-APP-CODE',
useHTTPS: true
});
var pixelRatio = window.devicePixelRatio || 1;
var defaultLayers = platform.createDefaultLayers({
tileSize: pixelRatio === 1 ? 256 : 512,
ppi: pixelRatio === 1 ? undefined : 320,
lg: 'CHI'
});
//Step 2: initialize a map - this map is centered over Hong Kong.
var map = new H.Map(document.getElementById('map'),
defaultLayers.normal.map,{
center: {lat:22.2783, lng:114.1588},
zoom: 12,
pixelRatio: pixelRatio
});
//Step 3: make the map interactive
// MapEvents enables the event system
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
// Now use the map as required...
switchMapLanguage(map , platform);
</script>
</body>
</html>
/**
*将地图语言切换为简体中文
*
*@param{H.Map}在应用程序中映射一个HERE映射实例
*@pama{H.service.Platform}Platform是访问此处服务的存根类
*/
函数开关映射语言(映射、平台){
var mapTileService=platform.getMapTileService({
类型:“基本”
}),
//我们的图层将从HERE Map Tile API加载平铺
chineseMapLayer=mapTileService.createTileLayer(
“maptile”,
“正常,一天”,
像素比率===1?256:512,
"png8",,
{lg:'CHI',ppi:pixelRatio==1?未定义:320}
);
地图设置层(中国玩家);
//在地图上显示默认UI组件并更改默认值
//语言转换为简体中文。
//除了支持的语言代码外,您还可以指定自定义翻译
//使用H.ui.i18n.Localization。
var ui=H.ui.ui.createDefault(map,defaultLayers,'zh CN');
}
/**
*样板图初始化代码从下面开始:
*/
//步骤1:初始化与平台的通信
var平台=新的H.service.platform({
应用程序id:'YOUR-app-id',
应用程序代码:“YOUR-app-code”,
对
});
var pixelRatio=window.devicePixelRatio | | 1;
var defaultLayers=platform.createDefaultLayers({
tileSize:pixelRatio==1?256:512,
ppi:pixelRatio==1?未定义:320,
lg:‘智’
});
/步骤2:初始化地图-该地图以香港为中心。
var map=new H.map(document.getElementById('map'),
defaultLayers.normal.map{
中心:{lat:22.2783,lng:114.1588},
缩放:12,
像素比率:像素比率
});
//步骤3:使地图具有交互性
//MapEvents启用事件系统
//行为实现了平移/缩放的默认交互(也在移动触摸环境中)
var behavior=newh.mapevents.behavior(newh.mapevents.mapevents(map));
//现在根据需要使用地图。。。
switchMapLanguage(地图、平台);