UNPKG

@xuehongbo/map-craft-js

Version:

MapCraftJS 是一个功能强大且灵活的开源 JavaScript 库,旨在简化互动地图的创建和操作。使用 MapCraftJS,开发者可以轻松地将动态地图功能集成到应用程序中,为用户提供根据自定义配置查看、注释和互动的地图体验。(开发中!!!)

55 lines (50 loc) 1.89 kB
import { loadResources } from '../utils/ResourceLoader.js'; class BMapAdapter { constructor(security,options,callback) { this.options = options; let ak=security.ak; // 调用公共方法加载资源 loadResources({ cssUrl: 'https://api.map.baidu.com/res/webgl/10/bmap.css', jsUrl: `http://api.map.baidu.com/getscript?type=webgl&v=1.0&ak=${ak}&services=&t=20240801100837` }).then(() => { // GL版命名空间为BMapGL // 按住鼠标右键,修改倾斜角和角度 this.map = new BMapGL.Map(options.container); this.map.centerAndZoom(new BMapGL.Point(options.center.lng, options.center.lat), options.zoom); // 初始化地图,设置中心点坐标和地图级别 this.map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放 if (options.mapStyle) { switch (options.mapStyle) { case 'BMAP_SATELLITE_MAP': this.map.setMapType(BMAP_SATELLITE_MAP); break; case 'BMAP_EARTH_MAP': this.map.setMapType(BMAP_EARTH_MAP); break; case 'BMAP_SATELLITE_MAP': this.map.setMapType(BMAP_SATELLITE_MAP); break; default: this.map.setMapStyleV2({ styleId: options.mapStyle }); } } callback() console.log('地图初始化成功') }); } addMarker(options) { const point = new BMapGL.Point(options.position.lng, options.position.lat); const marker = new BMapGL.Marker(point); this.map.addOverlay(marker); return marker; } drawPolyline(points) { const path = points.map(point => new BMap.Point(point.lng, point.lat)); const polyline = new BMap.Polyline(path, { strokeColor: "blue", strokeWeight: 2, strokeOpacity: 0.5 }); this.map.addOverlay(polyline); return polyline; } } export default BMapAdapter;