问题描述
最近突然发现,高德地图放大后居然不显示公司名字,还以为是没有交钱做地图标注。然后告知IT部门在对接地图标注的事情。但是开发这边还是觉得有问题,毕竟是接入API,怎么会其余的公司显示呢,经过测试发现是版本问题,版本对照表如下
高德官方API地址
html
// V2.0 API地址
https://lbs.amap.com/api/javascript-api-v2/documentation#map
// 注意2.0版本不要添加lang或者this.map.setLang("en");
// 否则会影响下面的地图代码,导致marker无法显示
// V1.4.15 API地址
https://lbs.amap.com/demo/javascript-api/example/map/map-english
// lang的可选值如下
<script>
//初始化地图
var map = new AMap.Map('container', {
resizeEnable: true,
center: [121.498586, 31.239637],
lang: "en" //可选值:en, zh_en, zh_cn
});
// en=英文版
// zh_en=中英双语显示
// zh_cn=中文简体
</script>
接入教程
amap-jsapi-loader插件安装
html
npm install @amap/amap-jsapi-loader --save
# or
yarn add @amap/amap-jsapi-loader
VUE源码
html
// 以下代码是使用的ruoyi-vue框架
<template>
<div class="app-container" style="padding-bottom: 0;">
<el-row>
<el-col :span="24">
<div id="mapDiv" ref="mapDiv"></div>
</el-col>
</el-row>
</div>
</template>
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode:'18a3c4536975dd465f6134e1b2eaf38b',//替换自己的
}
</script>
<script>
import AMapLoader from '@amap/amap-jsapi-loader';
import request from '@/utils/request'
import { formatDateStr } from "@/api/time";
import { getDeviceNum } from "@/api/index";
export default {
name: "Index",
data() {
return {
tableTimer:null,
tableListSize:10,
visibleSize:4,
tableTop: 0,
lineHeight: 28,
// 版本号
version: "3.8.6",
map: null,
allNum: 0,
onlineNum: 0,
warningNum: 0,
remoteNum: 0,
markerdom: null,
marker: [],
markernum: [[-15.8, 21.8]],
infoWindow: null,
tableHeight: 117,
};
},
created() {
},
methods: {
showInfoClickTag(data){
let id = data;
request({
url: '/index/getIndexDeviceInfoByOne?id='+id,
method: 'get'
}).then(response => {
if(response != null && response.data != null){
if(this.infoWindow != null){
this.infoWindow.close();
}
let onlineStatus = this.$i18n.t('wordOffline');
if(response.data.online == 0){
onlineStatus = this.$i18n.t('wordOnline');
}
let deviceStatus = this.$i18n.t('wordFault');
if(response.data.devStatus == 0){
deviceStatus = this.$i18n.t('wordNormal');
}
let deviceContent = "<div class=\"map_div_css\">";
deviceContent += "<div style=\"border-bottom:1px solid #ffffff; margin-bottom: 5px;\">"+this.$i18n.t('indexTableDeviceInfo')+"</div>";
deviceContent += "<div>"+this.$i18n.t('indexTableCorporation')+":"+response.data.companyName+"</div>";
deviceContent += "<div>"+this.$i18n.t('indexTablePrimaryKey')+":"+response.data.devId+"</div>";
deviceContent += "<div>"+this.$i18n.t('indexTableDeviceName')+":"+response.data.name+"</div>";
deviceContent += "<div>"+this.$i18n.t('indexTableDeviceOnlineStatus')+":"+onlineStatus+"</div>";
deviceContent += "<div>"+this.$i18n.t('indexTableDeviceStatus')+":"+deviceStatus+"</div>";
deviceContent += "</div>";
this.infoWindow = new AMap.InfoWindow({
isCustom: true, //使用自定义窗体
content: deviceContent,
closeWhenClickMap: true,
offset: new AMap.Pixel(16, -45)
});
this.infoWindow.open(this.map, [response.data.longitude,response.data.latitude]);
}
}
);
},
initMap() {
let _this = this;
let language = localStorage.getItem("language");
let mapVersion = "1.4.15";
if(language == "zh-CN"){
mapVersion = "2.0";
}else{
//lang=en,zh_en,zh_cn
// v2.0情况下,lang不会报错也不起作用
// 只有1.4.15才有英文版地图,setLang在2.0时候会报错,影响后面的代码,所以增加判断
if(language == "zh-TW"){
this.map.setLang("zh_en");
}else {
this.map.setLang("en");
}
}
AMapLoader.load({
key: "36cf857a028b0a296c6ba86b3a56fb32", //替换自己的
version: mapVersion,
resizeEnable: true,
}).then((AMap) => {
// 全局map定义在main.js文件中
this.map = new AMap.Map("mapDiv", {
lang: "en",
zoom: 19,
viewMode: '2D',
buildingAnimation: false,
center: [121.33406, 31.327717],
// mapStyle: "amap://styles/fresh"
});
request({
url: '/index/listMap',
method: 'get',
params: this.queryParams
}).then(response => {
if(response != null && response.rows != null){
_this.marker = [];
for (let i = 0; i < response.rows.length; i++) {
let pngColorName = "map_pink";
if(response.rows[i].onlineFlag == 0){
pngColorName = "map_gree";
}
let pngColorPath = require("../assets/images/"+pngColorName+".png");
_this.markerdom = "" +
"<div class=\"custom_content_marker\">" +
" <img src=\""+pngColorPath+"\" style=\"width:26px;\" onclick=\"showInfoFun('"+response.rows[i].id+"')\" >" +
"</div>";
_this.marker.push(new AMap.Marker({
position: new AMap.LngLat(response.rows[i].longitude, response.rows[i].latitude),
content: _this.markerdom,
offset: new AMap.Pixel(-13, -30)
}));
}
_this.map.add(_this.marker);
_this.map.setFitView();
}
}
);
}).catch(e => {
console.log(e);
})
},
},
mounted() {
this.initMap();
// 很重要,否则marker点击事件无法触发
window.showInfoFun = (data) => {
this.showInfoClickTag(data);
}
},
};
</script>
<style scoped lang="scss">
#mapDiv {
padding: 0px;
margin: 0px;
width: 100%;
height: 48vh;
}
::v-deep .map_div_css{
background: #304156;
padding: 7px;
font-size: 14px;
color: #ffffff;
border-radius: 6px;
font-family: initial;
}
</style>
效果展示
结束
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
html
package cn.renkai721.bean.vo;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class MakeUpTheWordCount {
private String make_up_the_word_count_column_999999999_1;
private String make_up_the_word_count_column_999999999_2;
private String make_up_the_word_count_column_999999999_3;
private String make_up_the_word_count_column_999999999_4;
private String make_up_the_word_count_column_999999999_5;
private String make_up_the_word_count_column_999999999_6;
private String make_up_the_word_count_column_999999999_7;
private String make_up_the_word_count_column_999999999_8;
private String make_up_the_word_count_column_999999999_9;
private String make_up_the_word_count_column_999999999_10;
private String make_up_the_word_count_column_999999999_11;
private String make_up_the_word_count_column_999999999_12;
private String make_up_the_word_count_column_999999999_13;
private String make_up_the_word_count_column_999999999_14;
private String make_up_the_word_count_column_999999999_15;
private String make_up_the_word_count_column_999999999_16;
private String make_up_the_word_count_column_999999999_17;
private String make_up_the_word_count_column_999999999_18;
private String make_up_the_word_count_column_999999999_19;
private String make_up_the_word_count_column_999999999_20;
public String getMake_up_the_word_count_column_999999999_1() {
return make_up_the_word_count_column_999999999_1;
}
public void setMake_up_the_word_count_column_999999999_1(String make_up_the_word_count_column_999999999_1) {
this.make_up_the_word_count_column_999999999_1 = make_up_the_word_count_column_999999999_1;
}
public String getMake_up_the_word_count_column_999999999_2() {
return make_up_the_word_count_column_999999999_2;
}
public void setMake_up_the_word_count_column_999999999_2(String make_up_the_word_count_column_999999999_2) {
this.make_up_the_word_count_column_999999999_2 = make_up_the_word_count_column_999999999_2;
}
public String getMake_up_the_word_count_column_999999999_3() {
return make_up_the_word_count_column_999999999_3;
}
public void setMake_up_the_word_count_column_999999999_3(String make_up_the_word_count_column_999999999_3) {
this.make_up_the_word_count_column_999999999_3 = make_up_the_word_count_column_999999999_3;
}
public String getMake_up_the_word_count_column_999999999_4() {
return make_up_the_word_count_column_999999999_4;
}
public void setMake_up_the_word_count_column_999999999_4(String make_up_the_word_count_column_999999999_4) {
this.make_up_the_word_count_column_999999999_4 = make_up_the_word_count_column_999999999_4;
}
public String getMake_up_the_word_count_column_999999999_5() {
return make_up_the_word_count_column_999999999_5;
}
public void setMake_up_the_word_count_column_999999999_5(String make_up_the_word_count_column_999999999_5) {
this.make_up_the_word_count_column_999999999_5 = make_up_the_word_count_column_999999999_5;
}
public String getMake_up_the_word_count_column_999999999_6() {
return make_up_the_word_count_column_999999999_6;
}
public void setMake_up_the_word_count_column_999999999_6(String make_up_the_word_count_column_999999999_6) {
this.make_up_the_word_count_column_999999999_6 = make_up_the_word_count_column_999999999_6;
}
public String getMake_up_the_word_count_column_999999999_7() {
return make_up_the_word_count_column_999999999_7;
}
public void setMake_up_the_word_count_column_999999999_7(String make_up_the_word_count_column_999999999_7) {
this.make_up_the_word_count_column_999999999_7 = make_up_the_word_count_column_999999999_7;
}
public String getMake_up_the_word_count_column_999999999_8() {
return make_up_the_word_count_column_999999999_8;
}
public void setMake_up_the_word_count_column_999999999_8(String make_up_the_word_count_column_999999999_8) {
this.make_up_the_word_count_column_999999999_8 = make_up_the_word_count_column_999999999_8;
}
public String getMake_up_the_word_count_column_999999999_9() {
return make_up_the_word_count_column_999999999_9;
}
public void setMake_up_the_word_count_column_999999999_9(String make_up_the_word_count_column_999999999_9) {
this.make_up_the_word_count_column_999999999_9 = make_up_the_word_count_column_999999999_9;
}
public String getMake_up_the_word_count_column_999999999_10() {
return make_up_the_word_count_column_999999999_10;
}
public void setMake_up_the_word_count_column_999999999_10(String make_up_the_word_count_column_999999999_10) {
this.make_up_the_word_count_column_999999999_10 = make_up_the_word_count_column_999999999_10;
}
public String getMake_up_the_word_count_column_999999999_11() {
return make_up_the_word_count_column_999999999_11;
}
public void setMake_up_the_word_count_column_999999999_11(String make_up_the_word_count_column_999999999_11) {
this.make_up_the_word_count_column_999999999_11 = make_up_the_word_count_column_999999999_11;
}
public String getMake_up_the_word_count_column_999999999_12() {
return make_up_the_word_count_column_999999999_12;
}
public void setMake_up_the_word_count_column_999999999_12(String make_up_the_word_count_column_999999999_12) {
this.make_up_the_word_count_column_999999999_12 = make_up_the_word_count_column_999999999_12;
}
public String getMake_up_the_word_count_column_999999999_13() {
return make_up_the_word_count_column_999999999_13;
}
public void setMake_up_the_word_count_column_999999999_13(String make_up_the_word_count_column_999999999_13) {
this.make_up_the_word_count_column_999999999_13 = make_up_the_word_count_column_999999999_13;
}
public String getMake_up_the_word_count_column_999999999_14() {
return make_up_the_word_count_column_999999999_14;
}
public void setMake_up_the_word_count_column_999999999_14(String make_up_the_word_count_column_999999999_14) {
this.make_up_the_word_count_column_999999999_14 = make_up_the_word_count_column_999999999_14;
}
public String getMake_up_the_word_count_column_999999999_15() {
return make_up_the_word_count_column_999999999_15;
}
public void setMake_up_the_word_count_column_999999999_15(String make_up_the_word_count_column_999999999_15) {
this.make_up_the_word_count_column_999999999_15 = make_up_the_word_count_column_999999999_15;
}
public String getMake_up_the_word_count_column_999999999_16() {
return make_up_the_word_count_column_999999999_16;
}
public void setMake_up_the_word_count_column_999999999_16(String make_up_the_word_count_column_999999999_16) {
this.make_up_the_word_count_column_999999999_16 = make_up_the_word_count_column_999999999_16;
}
public String getMake_up_the_word_count_column_999999999_17() {
return make_up_the_word_count_column_999999999_17;
}
public void setMake_up_the_word_count_column_999999999_17(String make_up_the_word_count_column_999999999_17) {
this.make_up_the_word_count_column_999999999_17 = make_up_the_word_count_column_999999999_17;
}
public String getMake_up_the_word_count_column_999999999_18() {
return make_up_the_word_count_column_999999999_18;
}
public void setMake_up_the_word_count_column_999999999_18(String make_up_the_word_count_column_999999999_18) {
this.make_up_the_word_count_column_999999999_18 = make_up_the_word_count_column_999999999_18;
}
public String getMake_up_the_word_count_column_999999999_19() {
return make_up_the_word_count_column_999999999_19;
}
public void setMake_up_the_word_count_column_999999999_19(String make_up_the_word_count_column_999999999_19) {
this.make_up_the_word_count_column_999999999_19 = make_up_the_word_count_column_999999999_19;
}
public String getMake_up_the_word_count_column_999999999_20() {
return make_up_the_word_count_column_999999999_20;
}
public void setMake_up_the_word_count_column_999999999_20(String make_up_the_word_count_column_999999999_20) {
this.make_up_the_word_count_column_999999999_20 = make_up_the_word_count_column_999999999_20;
}
}