html创建纯色背景,纯色背景-简单标注-示例中心-JS API UI 组件示例 | 高德地图API...

纯色背景

html,

body,

#container {

width: 100%;

height: 100%;

margin: 0px;

}

.amap-marker-label {

font-size: 13px;

border: 1px solid orange;

background: #fff;

border-radius: 10px 0 0 0;

color: #690441;

}

.color_bar {

width: 30px;

height: 18px;

}

/**

* 替换内置样式的图片

*/

.amap-simple-marker-def-style.my_color .amap-simple-marker-icon {

background-image: url('../assets/mbg_v2-fs8.png');

}

@media (min--moz-device-pixel-ratio: 1.5),

(-o-min-device-pixel-ratio: 3/2),

(-webkit-min-device-pixel-ratio: 1.5),

(min-device-pixel-ratio: 1.5),

(min-resolution: 1.5dppx) {

.amap-simple-marker-def-style.my_color .amap-simple-marker-icon {

background-image: url('../assets/mbg_v2@2x-fs8.png');

}

}

//创建地图

var map = new AMap.Map('container', {

zoom: 4

});

AMapUI.loadUI(['overlay/SimpleMarker'], function(SimpleMarker) {

//内置的样式

var iconStyles = SimpleMarker.getBuiltInIconStyles('default');

if (typeof(console) !== 'undefined') {

console.log(iconStyles.join(', '));

}

//获取一批grid排布的经纬度

var lngLats = getGridLngLats(map.getCenter(), 5, iconStyles.length, 130, 70);

for (var i = 0, len = lngLats.length; i < len; i++) {

new SimpleMarker({

iconTheme:'default',

//添加自定义的class

containerClassNames: 'my_color',

//使用内置的iconStyle

iconStyle: iconStyles[i],

//图标文字

iconLabel: {

//A,B,C.....

innerHTML: String.fromCharCode('A'.charCodeAt(0) + i),

style: {

//颜色, #333, red等等,这里仅作示例,取iconStyle中首尾相对的颜色

color: iconStyles[len - 1 - i]

}

},

//显示定位点

//showPositionPoint:true,

map: map,

position: lngLats[i],

title: 'iconStyle: ' + iconStyles[i] + '_' + iconStyles[len - 1 - i],

//Marker的label,见https://lbs.amap.com/api/javascript-api/reference/overlay/#Marker

label: {

content: iconStyles[i] + '

// offset: new AMap.Pixel(27, 25)

}

});

}

});

AMap.plugin(['AMap.ToolBar'], function() {

map.addControl(new AMap.ToolBar({

map: map

}));

});

/**

* 返回一批网格排列的经纬度

* @param {AMap.LngLat} center 网格中心

* @param {number} colNum 列数

* @param {number} size 总数

* @param {number} cellX 横向间距

* @param {number} cellY 竖向间距

* @return {Array} 返回经纬度数组

*/

function getGridLngLats(center, colNum, size, cellX, cellY) {

var pxCenter = map.lnglatToPixel(center);

var rowNum = Math.ceil(size / colNum);

var startX = pxCenter.getX(),

startY = pxCenter.getY();

cellX = cellX || 70;

cellY = cellY || 70;

var lngLats = [];

for (var r = 0; r < rowNum; r++) {

for (var c = 0; c < colNum; c++) {

var x = startX + (c - (colNum - 1) / 2) * (cellX);

var y = startY + (r - (rowNum - 1) / 2) * (cellY);

lngLats.push(map.pixelToLngLat(new AMap.Pixel(x, y)));

if (lngLats.length >= size) {

break;

}

}

}

return lngLats;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值