高德地图 - DIY我的地图
body { margin: 0; font: 13px/1.5 "Microsoft YaHei", "Helvetica Neue", "Sans-Serif"; min-height: 960px; min-width: 600px; }
.my-map { margin: 0 auto; width: 80%; height: 450px; } .my-map .icon { background: url(//a.amap.com/lbs-dev-yuntu/static/web/image/tools/creater/marker.png) no-repeat; } .my-map .icon-cir { height: 31px; width: 28px; } .my-map .icon-cir-red { background-position: -11px -5px; } .my-map .icon-cir { height: 31px; width: 28px; } .my-map .icon-cir-red { background-position: -11px -5px; }
.amap-container{height: 100%;}
.myinfowindow{width: 240px;min-height: 50px;}
.myinfowindow h5{ height: 20px; line-height: 20px; overflow: hidden; font-size: 14px; font-weight: bold; width: 220px; text-overflow: ellipsis; word-break: break-all; white-space: nowrap; }
.myinfowindow div{ margin-top: 10px; min-height: 40px; line-height: 20px; font-size: 13px; color: #6f6f6f; }
!function(){
var infoWindow, map, level = 9,
center = {lng: 114.077552, lat: 22.847549},
features = [{"icon":"cir","color":"red","name":"广州办公室","desc":"广州市黄埔区公园西路大湾区数字娱乐大厦5楼5009室","lnglat":{"Q":23.13731131430739,"R":113.25966942474247,"lng":113.449962,"lat":23.098918},"offset":{"x":-9,"y":-31},"type":"Marker"}, {"icon":"cir","color":"red","name":"深圳办公室","desc":"深圳市南山区深南中路高新园德赛科技大厦7楼705室","lnglat":{"Q":22.547548998303707,"R":114.0575515048206,"lng":113.954492,"lat":22.539418},"offset":{"x":-9,"y":-31},"type":"Marker"}
,
{"icon":"cir","color":"red","name":"深圳仓储","desc":"深圳市福田区中航路华强北鼎诚大厦8楼813室","lnglat":{"Q":22.547548998303707,"R":114.0575515048206,"lng":114.083914,"lat":22.543225},"offset":{"x":-9,"y":-31},"type":"Marker"} ,
{"icon":"cir","color":"red","name":"东莞注塑工厂","desc":"东莞市寮步镇寮东路华健科技园A1栋1、2、4楼","lnglat":{"Q":22.547548998303707,"R":114.0575515048206,"lng":113.913329,"lat":22.994116},"offset":{"x":-9,"y":-31},"type":"Marker"}
];
function loadFeatures(){
for(var feature, data, i = 0, len = features.length, j, jl, path; i < len; i++){
data = features[i];
switch(data.type){
case "Marker":
feature = new AMap.Marker({ map: map, position: new AMap.LngLat(data.lnglat.lng, data.lnglat.lat),
zIndex: 3, extData: data, offset: new AMap.Pixel(data.offset.x, data.offset.y), title: data.name,
content: '
' });
break;
case "Polyline":
for(j = 0, jl = data.path.length, path = []; j < jl; j++){
path.push(new AMap.LngLat(data.path[j].lng, data.path[j].lat));
}
feature = new AMap.Polyline({ map: map, path: path, extData: data, zIndex: 2,
strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity });
break;
case "Polygon":
for(j = 0, jl = data.path.length, path = []; j < jl; j++){
path.push(new AMap.LngLat(data.path[j].lng, data.path[j].lat));
}
feature = new AMap.Polygon({ map: map, path: path, extData: data, zIndex: 1,
strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity,
fillColor: data.fillColor, fillOpacity: data.fillOpacity });
break;
default: feature = null;
}
if(feature){ AMap.event.addListener(feature, "click", mapFeatureClick); }
}
}
function mapFeatureClick(e){
if(!infoWindow){ infoWindow = new AMap.InfoWindow({autoMove: true,isCustom: false}); }
var extData = e.target.getExtData();
infoWindow.setContent("
" + extData.name + "
" + extData.desc + "
");
infoWindow.open(map, e.lnglat);
}
map = new AMap.Map("mapContainer", {center: new AMap.LngLat(center.lng, center.lat), level: level, keyboardEnable:true, dragEnable:true, scrollWheel:true, doubleClickZoom:true});
loadFeatures();
map.on('complete', function(){
map.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function(){
map.addControl(new AMap.ToolBar({ruler: true, direction: true, locate: false})); map.addControl(new AMap.OverView({isOpen: true})); map.addControl(new AMap.Scale);
});
})
}();