高德地图使用实例一
高德地图使用实例1:
function mapInit(creditLevel,riskLevel,industryGeneralCategory,superviseCategory,warnStatus,backgroundColorMouseOut,backgroundColorMouseOver,keyword) { var bounds; var search; var markers = []; var cloudMarkers = []; var massData = []; var massDataArr = []; var mass; var mouseTool; var overlays = []; var layObj = []; var totalPage; //初始化 var map = new AMap.Map('container', { mapStyle: "amap://styles/8e139ff0c17f006b3470942873ac036a", zoom: 11, zooms: [11, 18], center: [121.707, 31.0868] }); var oldZoom = map.getZoom(); //添加边界坐标 var polygons = []; for (var i = 0, l = pudong.length; i < l; i++) { var polygon = new AMap.Polygon({ map: map, strokeWeight: 3, strokeOpacity: .9, path: pudong[i].lnglat, fillOpacity: .2, fillColor: "rgba(3, 129, 241, 0.9)", /*蓝色*/ strokeColor: "rgb(3, 129, 241, 1)" }); polygons.push(polygon); } //云图检索 var searchOptions = { //map: map, // panel: 'panel', keywords: '', pageSize: 100, orderBy: '_id:ASC', autoFitView: false, pageIndex: 1 }; search = new AMap.CloudDataSearch("5ca16a4a7bbf1916093774d5", searchOptions); var infoWindowNew = new AMap.InfoWindow({ offset: new AMap.Pixel(0, -30) }); var queryIndexMapCount_data = ""; //添加覆盖物 $.post(basePath + "/indexInfo/queryIndexMapCount",{ "creditLevel":creditLevel, "riskLevel":riskLevel, "industryGeneralCategory":industryGeneralCategory, "superviseCategory":superviseCategory, "warnStatus":warnStatus },function(data){ var resultData = data.data; queryIndexMapCount_data = resultData; for(var i=0;i0){ for(var k=0; k<resultData.length; k++){ if(resultData[k].street == districtList[i].name){ count = resultData[k].count; licence1 = resultData[k].licence1;//证照齐全 licence2 = resultData[k].licence2;//有照无证 } } } //createMaker(districtList[i].name, count , districtList[i].center,{name:districtList[i].name,licence1:licence1,licence2:licence2},backgroundColorMouseOut,backgroundColorMouseOver) createMakerFun1(districtList[i].name, count, districtList[i].center, { x: licence1, y: licence2 }) } }); function createMakerFun1(name,count, center, paramsData) { // search.searchByDistrict(name, function(status,result){ // var count = result.count == undefined?0:result.count; createMaker(name, count, center, paramsData); search.clear(); // }); } //添加覆盖物 function createMaker(name, number, position, paramsData) { var html = ' ' + name + '
' + number + '
'; var infoWindowNew = new AMap.InfoWindow({ offset: new AMap.Pixel(0, -30) }); var marker = new AMap.Marker({ position: position, offset: new AMap.Pixel(-12, -24), content: html }); markers.push(marker); map.add(markers); marker.on('mouseover', function(ev) { // console.log(ev); var domObj = ev.target.getContentDom(); $(domObj).find(".circlemarker").css({ 'background': 'rgba(0, 167, 91, 0.9)', 'box-shadow': '0em 0em 0.5em rgba(0, 0, 0, 0.9)' }); var polygonsNew = []; for (var i = 0, l = pudong.length; i < l; i++) { if (pudong[i].name == name) { var polygon = new AMap.Polygon({ map: map, strokeWeight: 3, strokeOpacity: .9, path: pudong[i].lnglat, fillOpacity: 0, fillColor: "rgba(0, 167, 91, 0.9)", strokeColor: "rgba(0, 167, 91, 0.9)" //绿色//"red" }) polygonsNew.push(polygon) } } var content = "证照齐全:" + paramsData.x + "
" + "有照无证:" + paramsData.y + "
"; infoWindowNew.setContent(content); infoWindowNew.open(map, ev.target.getPosition()); }) marker.on('mouseout', function(ev) { $(".circlemarker").css({ 'background': 'rgba(3, 129, 241, 0.9)', //蓝色 //'box-shadow':'box-shadow:0em 0em 0.5em rgba(0, 167, 91, 0.9)' }) var polygonsNew = []; for (var i = 0, l = pudong.length; i < l; i++) { if (pudong[i].name == name) { var polygon = new AMap.Polygon({ map: map, strokeWeight: 3, strokeOpacity: .9, path: pudong[i].lnglat, fillOpacity: 0, fillColor: "rgba(3, 129, 241, 0.9)", /* rgb(0, 167,91)*/ strokeColor: "rgba(3, 129, 241, 1)" }) polygonsNew.push(polygon) } } infoWindowNew.close(); }) marker.on('click', function(i) { massDataArr = [];//云图数据初始化 //console.log(i) var e = i.target.getPosition(); var zoom = map.getZoom(); infoWindowNew.close(); if (zoom < 12) { map.setZoom(12); map.setCenter([e.lng, e.lat]); } if (12 <= zoom && zoom < 14) { map.setZoom(14); map.setCenter([e.lng, e.lat]); } if (14 <= zoom && zoom < 15) { map.setZoom(15); map.setCenter([e.lng, e.lat]); } if (name != '上海市') { //console.log(name); massData = []; if (mass) { mass.clear(); } //20表示两千条数据 for (var i = 1; i <= 20; i++) { addMass(name, i, function(pageIndex) { if (pageIndex == 20) { setTimeout(function() { //console.log("##"+JSON.stringify(massDataArr)); cloudSearch1('success', { 'datas': massDataArr }) }, 500) } }); } } }) } function addMass(name, pageIndex, callBack) { search = new AMap.CloudDataSearch("5ca16a4a7bbf1916093774d5", { //map: map, // panel: 'panel', keywords: keyword, pageSize: 100, orderBy: '_id:ASC', autoFitView: false, pageIndex: pageIndex }); //多边形检索 var streetLatLng = ""; for(var i=0;i<pudong.length;i++){ if(pudong[i].name == name){ streetLatLng = pudong[i].lnglat; } } search.searchInPolygon(streetLatLng, function(status, data) { if (data.datas) { for (var i = 0; i < data.datas.length; i++) { massDataArr.push(data.datas[i]) } callBack(pageIndex); //cloudSearch1(status,data) } }); /*search.searchByDistrict(name, function(status, data) { if (data.datas) { for (var i = 0; i < data.datas.length; i++) { massDataArr.push(data.datas[i]) } callBack(pageIndex); //cloudSearch1(status,data) } });*/ } //云图搜索成功回调1 function cloudSearch1(status, data, sec) { // console.log(data) //console.log("dataCont = "+data.count); totalPage = Math.ceil(data.count / 100) if (mass && !sec) { mass.clear(); //map.remove(massData) massData = []; } var dataArr = data.datas; if (dataArr && dataArr.length >0) { for (var i = 0; i < dataArr.length; i++) { var massObj = dataArr[i]; massObj.lnglat = dataArr[i]._location; massData.push(massObj) } var infoWindow = new AMap.InfoWindow({ offset: new AMap.Pixel(0, -30) }); var style = [{ url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png', anchor: new AMap.Pixel(1, 6), size: new AMap.Size(11, 11) }, { url: 'https://a.amap.com/jsapi_demos/static/images/mass1.png', anchor: new AMap.Pixel(4, 4), size: new AMap.Size(7, 7) }, { url: 'https://a.amap.com/jsapi_demos/static/images/mass2.png', anchor: new AMap.Pixel(6, 6), size: new AMap.Size(12, 12) }]; mass = new AMap.MassMarks(massData, { opacity: 0.8, zIndex: 111, zooms: [12, 19], cursor: 'pointer', style: style[2] }); mass.setData(massData); mass.setStyle(style[0]); mass.setMap(map); mass.on('mouseover', function(e) { var content = setContent(e.data); infoWindow.setContent(content); infoWindow.open(map, e.data.lnglat); }); mass.on('mouseout', function(e) { infoWindow.close() }); mass.on('click', function(e) { //console.log(e) //location.href = 'company_hx.html?enty_id=' + e.data.ENTY_ID window.location.href=basePath+"/company/toCompanyHx?companyId="+e.data.ENTY_ID; }); $(".poibox").on('click', function() { var mIndex = $(this).index(); var length = massDataArr.length; var oIndex = length-100 + mIndex; var content = setContent(massData[oIndex]); infoWindow.setContent(content); infoWindow.open(map, massData[oIndex]._location); map.setCenter(massData[oIndex]._location); }); } //map.setFitView(); } function setContent(obj) { var hangye = obj.igc == undefined?"":obj.igc; var establishDate = ''; if(obj.ESTABLISH_DATE == undefined || obj.ESTABLISH_DATE == ''){ establishDate = '无'; }else{ establishDate = obj.ESTABLISH_DATE.substring(0,10); } var tradeStartDate = obj.TRADE_START_DATE == ''?'无':obj.TRADE_START_DATE; var tradeEndDate = obj.TRADE_END_DATE == ''?'无':obj.TRADE_END_DATE; if(obj.TRADE_START_DATE == undefined || obj.TRADE_START_DATE == ''){ tradeStartDate = '无'; }else{ tradeStartDate = obj.TRADE_START_DATE.substring(0,10); } if(obj.TRADE_END_DATE == undefined || obj.TRADE_END_DATE == ''){ tradeEndDate = '无'; }else{ tradeEndDate = obj.TRADE_END_DATE.substring(0,10); } var currency = obj.CURRENCY == ''?'':" (万)"+obj.CURRENCY; var aaeptOrganId = obj.ACCEPT_ORGAN_ID == ''?'浦东新区市场监督管理局':obj.ACCEPT_ORGAN_ID; var content = "企业名称:" + obj._name + "
" + "行业类别:" + hangye + "
" + "成立时间:" + establishDate + "
" + "法人代表:" + obj.FR_NAME + "
" + "注册号:" + obj.REG_NO + "
" + "营业期限:" + tradeStartDate+ " 至 "+ tradeEndDate + "
" + "注册资本:" + obj.CPTL + currency +"
" + "企业地址:" + obj._address + "
" + "登记机关:" + aaeptOrganId; return content; } //监听地图缩放事件 map.on('zoomend', function(ev) { for (var i = map.getAllOverlays('polygon'), e = 0; e < i.length; e++) { map.remove(i[e]) } map.remove(markers); markers = []; if (map.getZoom() == 11) { markers = []; map.remove(cloudMarkers); cloudMarkers = []; search.clear(); //添加边界坐标 var polygons = []; for (var i = 0, l = pudong.length; i < l; i++) { var polygon = new AMap.Polygon({ map: map, strokeWeight: 3, strokeOpacity: .9, path: pudong[i].lnglat, fillOpacity: .2, fillColor: "rgba(3, 129, 241, 0.9)", /*蓝色*/ strokeColor: "rgba(3, 129, 241, 0.9)" /*蓝色*/ }) polygons.push(polygon) } //添加覆盖物 var resultData = queryIndexMapCount_data; for(var i=0;i0){ for(var k=0; k<resultData.length; k++){ if(resultData[k].street == districtList[i].name){ count = resultData[k].count; licence1 = resultData[k].licence1; licence2 = resultData[k].licence2; } } } createMakerFun1(districtList[i].name, count, districtList[i].center, { x: licence1, y: licence2 }) } $("#polygonWrap").hide(); } else { $("#polygonWrap").show(); } $("#mapCheck").prop('checked', 0) if (!$("#mapCheck").prop('checked')) { mouseTool.close(true) //关闭,并清除覆盖物 } //console.log(map.getZoom()) }) //$("#polygonWrap").hide() mouseTool = new AMap.MouseTool(map); //画多边形 function drawPolygon() { mouseTool.polygon({ fillColor: '#00b0ff', strokeColor: '#80d8ff' //同Polygon的Option设置 }); } $("#mapCheck").on('change', function(ev) { if (this.checked) { //画多边形 drawPolygon(); } else { mouseTool.close(true) //关闭,并清除覆盖物 } }); //监听draw事件 AMap.event.addListener(mouseTool, 'draw', function(e) { //画多边形 if (e.obj.CLASS_NAME == 'AMap.Polygon') { overlays = e.obj.getPath(); layObj.push(e.obj); overlays.push(overlays[0]); //执行区域搜索 var x = overlays[0].lng; var x1 = overlays[1].lng; if (x != x1) { if (search != null) { //search.clear(); for (var i = map.getAllOverlays('polygon'), e = 0; e < i.length; e++) { map.remove(i[e]) } } //实例化搜索 search.searchInPolygon(overlays, function(status, data) { cloudSearch1(status, data, false) }); } } }); map.on('mousedown', function() { // map.remove(layObj); // layObj = []; }) }
上一篇:WebSocket 使用实例
下一篇:高德地图使用实例二
文章
总共 0 条评论