terra-draw-amap-adapter
v0.1.0
Published
Terra Draw adapter for AMap JSAPI v2.0.
Readme
terra-draw-amap-adapter
Terra Draw adapter for AMap JSAPI v2.0. The adapter renders Terra Draw features using AMap vector overlays and maps Terra Draw pointer interactions to the AMap container.
Install
pnpm add terra-draw terra-draw-amap-adapterIf you load AMap JSAPI with the official loader, also install it in your application:
pnpm add @amap/amap-jsapi-loaderUsage
import AMapLoader from "@amap/amap-jsapi-loader";
import { TerraDraw, TerraDrawFreehandMode } from "terra-draw";
import { TerraDrawAMapAdapter } from "terra-draw-amap-adapter";
window._AMapSecurityConfig = {
securityJsCode: import.meta.env.VITE_AMAP_SECURITY_CODE,
};
const AMap = await AMapLoader.load({
key: import.meta.env.VITE_AMAP_JSAPI_KEY,
version: "2.0",
});
AMap.getConfig().appname = "terra-draw-amap-adapter";
const map = new AMap.Map("map", {
viewMode: "3D",
center: [116.397428, 39.90923],
zoom: 11,
});
const draw = new TerraDraw({
adapter: new TerraDrawAMapAdapter({
lib: AMap,
map,
}),
modes: [new TerraDrawFreehandMode()],
});
draw.start();
draw.setMode("freehand");The package does not load AMap or manage credentials. Configure window._AMapSecurityConfig before calling AMapLoader.load, keep credentials in your application environment, and pass the loaded AMap library plus the AMap.Map instance to the adapter.
Development
pnpm install
pnpm run checkLicense
MIT
