import {deepMerge, wgs84ToGcj02Format} from '../util' let baseGeoData: any = { type: 'FeatureCollection', name: '', crs: {}, features: [ { type: 'Feature', properties: {}, geometry: { type: 'MultiPolygon', coordinates: [[[]]] } } ] } export default (hnMap: any) => { const defaultOption = { id: "", data: baseGeoData, opacity: 1, line: { show: true, color: "#ff00ff", opacity: 1, width: 2, }, area: { show: false, color: "#ffff00", opacity: 1, } } class mars3d_class { type: any = 'geoJson' id: any = null option: any = JSON.parse(JSON.stringify(defaultOption)) config: any = null layerEntity: any = null constructor(option: any) { this.id = option.id deepMerge(this.option, option) this.config = this.formatConfig(this.option) this.layerEntity = new mars3d.layer.GeoJsonLayer(this.config) } formatConfig(option: any) { return { name: option.id, id: option.id, allowDrillPick: true, data: option.data, symbol: { styleOptions: { clampToGround: true, fill: option.area.show, randomColor: !!(option.area.show && option.area.color), // 随机色 outline: option.line.show, opacity: option.opacity, outlineStyle: { color: option.line.color, width: option.line.width, opacity: option.line.opacity, }, } }, // flyTo: true, // attr: option.data } } set(option: any) { deepMerge(this.option, option) this.config = this.formatConfig(this.option) this.layerEntity.setOptions(this.config) } customStyle(callback: any) { this.layerEntity.options.symbol.callback = (attr: any) => { return callback(attr) } } destroy() { this.layerEntity.remove(true) hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id) } setData(data: any) { this.layerEntity.loadGeoJSON(data, {clear: true}) } clear() { this.layerEntity.clear() } flyTo() { this.layerEntity.flyTo() } // 添加属性弹窗 addPopupByAttr() { this.layerEntity.bindPopup((event: any) => { if (event.graphic.attr) { const data = event.graphic.attr return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data}) } }) } // 添加自定义dom弹窗 addCustomPopup(getCustomDom: any) { this.layerEntity.bindPopup(async (event: any) => { if (event.graphic.attr) { const data = event.graphic.attr || {}; return await getCustomDom(data); } }, {offsetY: -20}); } } class gaode_class { id: any = null option: any = JSON.parse(JSON.stringify(defaultOption)) config: any = null layerEntity: any = null constructor(option: any) { this.id = option.id deepMerge(this.option, option) this.config = this.formatConfig(this.option) this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config) } formatConfig(option: any) { const data = option.position.map((v: any) => { return {lng: v.lng, lat: v.lat, count: v.value} }) const amapData = wgs84ToGcj02Format(data) return {} } set(option: any) { deepMerge(this.option, option) this.config = this.formatConfig(this.option) this.layerEntity.setOptions(this.config) } destroy() { this.layerEntity.setMap(null) hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id) } flyTo() { } } const fn: any = { mars3d: mars3d_class, gaode: gaode_class } return fn[hnMap.mapType] }