@vuemap/vue-amap
Version:
高德地图vue3版本封装
196 lines (191 loc) • 5.99 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var lodashEs = require('lodash-es');
require('../../../mixins/index.js');
var useEditor = require('../../../mixins/useEditor.js');
require('../../../utils/index.js');
var props = require('./props.js');
var useRegister = require('../../../mixins/useRegister.js');
var util = require('../../../utils/util.js');
var script = /* @__PURE__ */ vue.defineComponent({
...{
name: "ElAmapPolygon",
inheritAttrs: false
},
__name: "Polygon",
props: props.propsTypes,
emits: ["init", "update:path"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emits = __emit;
let $amapComponent;
let destroying = false;
const { $$getInstance, parentInstance } = useRegister.useRegister((options, parentComponent) => {
return new Promise((resolve) => {
$amapComponent = new AMap.Polygon(options);
if (util.isMapInstance(parentComponent)) {
parentComponent.add($amapComponent);
} else if (util.isOverlayGroupInstance(parentComponent)) {
parentComponent.addOverlay($amapComponent);
} else if (util.isVectorLayerInstance(parentComponent)) {
parentComponent.add($amapComponent);
}
bindModelEvents();
resolve($amapComponent);
});
}, {
emits,
watchRedirectFn: {
__zIndex(value) {
if ($amapComponent) {
$amapComponent.setOptions({ zIndex: value });
}
},
__strokeColor(value) {
if ($amapComponent) {
$amapComponent.setOptions({ strokeColor: value });
}
},
__strokeOpacity(value) {
if ($amapComponent) {
$amapComponent.setOptions({ strokeOpacity: value });
}
},
__strokeWeight(value) {
if ($amapComponent) {
$amapComponent.setOptions({ strokeWeight: value });
}
},
__fillColor(value) {
if ($amapComponent) {
$amapComponent.setOptions({ fillColor: value });
}
},
__fillOpacity(value) {
if ($amapComponent) {
$amapComponent.setOptions({ fillOpacity: value });
}
},
__strokeStyle(value) {
if ($amapComponent) {
$amapComponent.setOptions({ strokeStyle: value });
}
},
__strokeDasharray(value) {
if ($amapComponent) {
$amapComponent.setOptions({ strokeDasharray: value });
}
},
__editable(flag) {
createEditor().then(() => {
flag ? resetEditor() : editor.close();
});
},
__path(path) {
if ($amapComponent) {
$amapComponent.setPath(path);
resetEditor();
}
},
__draggable(flag) {
$amapComponent.setOptions({
draggable: flag
});
if (editor) {
if (editor.editingPolyObj && editor.editingPolyObj.origin_options) {
editor.editingPolyObj.origin_options.draggable = flag;
}
}
if (props.editable) {
resetEditor();
}
}
},
destroyComponent() {
destroying = true;
if ($amapComponent && (parentInstance == null ? void 0 : parentInstance.$amapComponent)) {
if (editor) {
if (!parentInstance.isDestroy) {
editor.close();
}
editor = null;
}
if (!parentInstance.isDestroy) {
if (util.isMapInstance(parentInstance.$amapComponent)) {
parentInstance.$amapComponent.remove($amapComponent);
} else if (util.isOverlayGroupInstance(parentInstance.$amapComponent)) {
parentInstance.$amapComponent.removeOverlay($amapComponent);
} else if (util.isVectorLayerInstance(parentInstance.$amapComponent)) {
parentInstance.$amapComponent.remove($amapComponent);
}
}
if ($amapComponent.destroy) {
$amapComponent.destroy();
}
$amapComponent = null;
}
}
});
const resetEditor = lodashEs.debounce(() => {
if (editor && props.editable) {
editor.close();
editor.open();
}
}, 50);
const bindModelEvents = () => {
$amapComponent.on("dragend", () => {
emitModel($amapComponent);
});
$amapComponent.on("touchend", () => {
emitModel($amapComponent);
});
};
const emitModel = (target) => {
if (destroying) {
return;
}
const paths = target.getPath();
const pathArray = paths == null ? void 0 : paths.map(util.convertLnglat);
emits("update:path", pathArray);
};
let editor;
const attrs = vue.useAttrs();
const createEditor = () => {
return new Promise((resolve) => {
if (editor) {
resolve();
} else {
AMap.plugin(["AMap.PolygonEditor"], () => {
editor = new AMap.PolygonEditor(parentInstance == null ? void 0 : parentInstance.$amapComponent, $amapComponent, props.editOptions);
useEditor.useEditor(editor, attrs);
bindEditorModelEvents();
resolve();
});
}
});
};
const bindEditorModelEvents = () => {
editor.on("addnode", (e) => {
emitModel(e.target);
});
editor.on("adjust", (e) => {
emitModel(e.target);
});
editor.on("removenode", (e) => {
emitModel(e.target);
});
editor.on("add", (e) => {
emitModel(e.target);
});
};
__expose({
$$getInstance
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div");
};
}
});
exports.default = script;
//# sourceMappingURL=Polygon.vue2.js.map