ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
默认参数 如图: ![](https://img.kancloud.cn/dc/aa/dcaabfad41bd2a0f195c38b61d25b5e4_860x533.png) ``` // 图片 component.config.mapImgShow = false; component.config.image = 'images/class_icon.png'; component.config.mapImgSize = 10; component.config.mapImgOffsetY = 0; component.config.mapImgOffsetX = 0; ``` 配置项如下: 搜索case"chart": 替换整个 ![](https://img.kancloud.cn/da/9c/da9c05f685baefecc3d991f62e7fb8ee_831x574.png) ``` case "chart": layerConfig.elements.push( { title: '文本字段', type: "select-s-column", bind: "mapFontColumn", }, { title: '联动维度', type: "select-s-column", bind: "linkageDimension", }, { title: '颜色', type: "colorpicker", bind: "mapFontColor", }, { title: '字体大小', type: "configSlide", bind: "mapFontSize", config: { slideEnd: 48 } }, { title: '文本偏移-X轴', type: "configSlide", bind: "mapFontOffsetX", config: { slideEnd: 48 } }, { title: '文本偏移-Y轴', type: "configSlide", bind: "mapFontOffsetY", config: { slideEnd: 48 } }, { title: '图标', type: "switch", bind: "mapImgShow", on: vsLang.on, off: vsLang.off }, { title: vsLang.image, type: "imagepicker", bind: { name: "gemap", data: "image" }, show: function() { return component.config.mapImgShow != null && component.config.mapImgShow === true }, }, { title: '图标大小', type: "configSlide", bind: "mapImgSize", config: { slideEnd: 20 }, show: function() { return component.config.mapImgShow != null && component.config.mapImgShow === true }, }, { title: '图标-Y轴', type: "configSlide", bind: "mapImgOffsetY", config: { slideEnd: 100 }, show: function() { return component.config.mapImgShow != null && component.config.mapImgShow === true }, }, { title: '图标-X轴', type: "configSlide", bind: "mapImgOffsetX", config: { slideEnd: 100 }, show: function() { return component.config.mapImgShow != null && component.config.mapImgShow === true }, }, { title: '提示框', type: "switch", bind: "tooltipShow", on: vsLang.on, off: vsLang.off }, { title: vsLang.show_columns, type: "multiQueryColumnSelect", bind: "showColumns", show: function() { return component.config.tooltipShow != null && component.config.tooltipShow === true }, }, { title: vsLang.bg_color, type: "colorpicker", bind: "bgColor_tooltip", show: function() { return component.config.tooltipShow != null && component.config.tooltipShow === true }, }, { title: vsLang.font_color, type: "colorpicker", bind: "fontColor_tooltip", show: function() { return component.config.tooltipShow != null && component.config.tooltipShow === true }, }, ); if (component.config.mapFontColor == null) component.config.mapFontColor = "rgba(0, 0, 0, 1)"; if (component.config.mapFontSize == null) component.config.mapFontSize = 12; if (component.config.mapFontOffsetX == null) component.config.mapFontOffsetX = 0; if (component.config.mapFontOffsetY == null) component.config.mapFontOffsetY = 0; if (component.config.mapImgShow == null) component.config.mapImgShow = false; if (component.config.mapImgSize == null) component.config.mapImgSize = 10; if (component.config.mapImgOffsetY == null) component.config.mapImgOffsetY = 0; if (component.config.mapImgShow == null) component.config.mapImgShow = 0; break; ``` 逻辑代码 搜索case"chart": 替换整个 ![](https://img.kancloud.cn/0b/64/0b64026a5f24e5910d4e40d543061035_859x597.png) ``` case "chart": // console.log(component.config.mapImgShow) // console.log(124354546) // console.log(component.config.image) var aa = component.config.image.replace(/{{appId}}/,localStorage.getItem('appId')); // console.log(aa) // console.log(localStorage.getItem('appId')) // 图片开启 if (map.getLayer(layerId) !== undefined) { map.removeLayer(layerId); } if (map.getSource(sourceId) !== undefined){ map.removeSource(sourceId); } if(component.config.mapImgShow){ var offset = []; if (component.config.mapImgOffsetX != null) { offset.push(parseInt(component.config.mapImgOffsetX)); } else { offset.push(0); } if (component.config.mapImgOffsetY != null) { offset.push(parseInt(component.config.mapImgOffsetY)); } else { offset.push(0); } var imgSize = parseFloat(component.config.mapImgSize/10) // console.log(offset) if(!map.hasImage('imgId')){ map.loadImage('/'+aa,function(error,data){ // console.log(data) map.addImage('imgId', data,{}) }) } if (map.getLayer(layerId) == undefined) { map.addSource(sourceId, { 'type': 'geojson', 'data': geojson }); map.addLayer({ 'id': layerId, 'source': sourceId, 'type': 'symbol', 'layout': { "icon-image":"imgId", "icon-size":imgSize, "icon-offset":offset } }); map.on('click',layerId,function(ev){ // console.log(ev.features) scope.onOverlayItemClicked(ev.features,ev) }) } else { map.getSource(sourceId).setData(geojson); } }else{ var offset = []; if (layer.mapFontOffsetX != null) { offset.push(parseInt(layer.mapFontOffsetX)); } else { offset.push(0); } if (layer.mapFontOffsetY != null) { offset.push(parseInt(layer.mapFontOffsetY)); } else { offset.push(0); } if (map.getLayer(layerId) == undefined) { map.addSource(sourceId, { 'type': 'geojson', 'data': geojson }); map.addLayer({ 'id': layerId, 'source': sourceId, 'type': 'symbol', 'layout': { "text-field": "{name}", "text-size": parseInt(layer.mapFontSize), "text-font": ["SimSun Regular"], "text-offset": offset, }, 'paint': { "text-color": layer.mapFontColor } }); map.on('click',layerId,function(ev){ // console.log(ev.features) scope.onOverlayItemClicked(ev.features,ev) }) } else { map.getSource(sourceId).setData(geojson); map.setPaintProperty(layerId, 'text-color', layer.mapFontColor); map.setLayoutProperty(layerId, 'text-size', parseInt(layer.mapFontSize)); map.setLayoutProperty(layerId, 'text-offset', offset); } } break; ``` 联动事件 如图位置代码 添加作用域 并写以下代码 ![](https://img.kancloud.cn/b6/fa/b6faa78e0d5a9bf22c58517f74f91c99_1072x834.png) ``` // 联动得点击事件 scope.onOverlayItemClicked = function(ev,s) { // console.log(ev) var name = ev[0].properties.name.toString(); if (component.config.linkageDimension == null) { alert("未配置联动维度"); return } // console.log(data) function findWithAttr(array, attr, value) { for(var i = 0; i < array.length; i += 1) { // console.log(array[i][attr]) if(array[i][attr] == value) { return i; }s } } // console.log(component.config.linkageDimension.name) var dm = findWithAttr(data,component.config.mapFontColumn.name,name); console.log(data[dm]) var t = data[dm][component.config.linkageDimension.name]; console.log(t) console.log(scope.component.config.linkageDimension.name) scope.cacheDimensionValue(scope.component.config.linkageDimension.name, t); scope.notifyDimensionValueChange(null, scope.component.config.linkageDimension, t) if(component.config.tooltipShow){ console.log(component.config.showColumns) var gistooltip = "tooltip"+component.id; var x = parseInt(s.point.x)-100; var y = parseInt(s.point.y)+30; // console.log($("#"+gistooltip)) $("."+gistooltip).css({ "overflow":"hidden", "height":"auto", "position":"absolute", "padding":"10px", "z-index": "99999", "display":"block", "top":y+"px", "color":component.config.fontColor_tooltip, "background":component.config.bgColor_tooltip, "left":x+"px", "font-size":"14px", "border-radius":"5px" }); var html = '' for(var i = 0;i<component.config.showColumns.length;i++){ html+='<p style="line-height:20px;">'+component.config.showColumns[i].name+':'+data[dm][component.config.showColumns[i].name]+'</p>' } console.log(html) $("."+gistooltip).empty().html(html) } }; ``` 分享页 : 搜索 case"chart": 如图位置 替换整个 ``` case "chart": // console.log(component.config.mapImgShow) // console.log(124354546) // console.log(component.config.image) var aa = component.config.image.replace(/{{appId}}/,localStorage.getItem('appId')); // console.log(aa) // console.log(localStorage.getItem('appId')) // 图片开启 if (map.getLayer(layerId) !== undefined) { map.removeLayer(layerId); } if (map.getSource(sourceId) !== undefined){ map.removeSource(sourceId); } if(component.config.mapImgShow){ var offset = []; if (component.config.mapImgOffsetX != null) { offset.push(parseInt(component.config.mapImgOffsetX)); } else { offset.push(0); } if (component.config.mapImgOffsetY != null) { offset.push(parseInt(component.config.mapImgOffsetY)); } else { offset.push(0); } var imgSize = parseFloat(component.config.mapImgSize/10) // console.log(offset) if(!map.hasImage('imgId')){ map.loadImage('/'+aa,function(error,data){ // console.log(data) map.addImage('imgId', data,{}) }) } if (map.getLayer(layerId) == undefined) { map.addSource(sourceId, { 'type': 'geojson', 'data': geojson }); map.addLayer({ 'id': layerId, 'source': sourceId, 'type': 'symbol', 'layout': { "icon-image":"imgId", "icon-size":imgSize, "icon-offset":offset } }); map.on('click',layerId,function(ev){ // console.log(ev.features) scope.onOverlayItemClicked(ev.features,ev) }) } else { map.getSource(sourceId).setData(geojson); } }else{ var offset = []; if (layer.mapFontOffsetX != null) { offset.push(parseInt(layer.mapFontOffsetX)); } else { offset.push(0); } if (layer.mapFontOffsetY != null) { offset.push(parseInt(layer.mapFontOffsetY)); } else { offset.push(0); } if (map.getLayer(layerId) == undefined) { map.addSource(sourceId, { 'type': 'geojson', 'data': geojson }); map.addLayer({ 'id': layerId, 'source': sourceId, 'type': 'symbol', 'layout': { "text-field": "{name}", "text-size": parseInt(layer.mapFontSize), "text-font": ["SimSun Regular"], "text-offset": offset, }, 'paint': { "text-color": layer.mapFontColor } }); map.on('click',layerId,function(ev){ // console.log(ev.features) scope.onOverlayItemClicked(ev.features,ev) }) } else { map.getSource(sourceId).setData(geojson); map.setPaintProperty(layerId, 'text-color', layer.mapFontColor); map.setLayoutProperty(layerId, 'text-size', parseInt(layer.mapFontSize)); map.setLayoutProperty(layerId, 'text-offset', offset); } } break; ``` 搜索loadLayer 这个方法 添加作用域 并 添加以下联动事件 ![](https://img.kancloud.cn/bd/8a/bd8ab6eec5f404b1b8545463d74f430e_955x676.png) ``` // 联动得点击事件 scope.onOverlayItemClicked = function(ev,s) { // console.log(ev) var name = ev[0].properties.name.toString(); if (component.config.linkageDimension == null) { alert("未配置联动维度"); return } // console.log(data) function findWithAttr(array, attr, value) { for(var i = 0; i < array.length; i += 1) { // console.log(array[i][attr]) if(array[i][attr] == value) { return i; } } } // console.log(component.config.linkageDimension.name) var dm = findWithAttr(data,component.config.mapFontColumn.name,name); console.log(data[dm]) var t = data[dm][component.config.linkageDimension.name]; console.log(t) console.log(scope.component.config.linkageDimension.name) scope.cacheDimensionValue(scope.component.config.linkageDimension.name, t); scope.notifyDimensionValueChange(null, scope.component.config.linkageDimension, t) if(component.config.tooltipShow){ console.log(component.config.showColumns) var gistooltip = "tooltip"+component.id; var x = parseInt(s.point.x)-100; var y = parseInt(s.point.y)+30; // console.log($("#"+gistooltip)) $("."+gistooltip).css({ "overflow":"hidden", "height":"auto", "position":"absolute", "padding":"10px", "z-index": "99999", "display":"block", "top":y+"px", "color":component.config.fontColor_tooltip, "background":component.config.bgColor_tooltip, "left":x+"px", "font-size":"14px", "border-radius":"5px" }); var html = '' for(var i = 0;i<component.config.showColumns.length;i++){ html+='<p style="line-height:20px;">'+component.config.showColumns[i].name+':'+data[dm][component.config.showColumns[i].name]+'</p>' } console.log(html) $("."+gistooltip).empty().html(html) } }; ```