!function(){ var infowindow, map, level = 18, center = {lng: 119.653486, lat: 29.09862}, features = [{"icon":"cir","color":"red","name":"浙江尖峰集团股份有限公司","desc":"中国•浙江金华市婺江东路88号","lnglat":{"q":22.682100545684076,"r":114.28293269634247,"lng":113.916536,"lat":22.733736},"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); }); }) }();