@vuemap/vue-amap
Version:
高德地图vue3版本封装
121 lines (116 loc) • 3.79 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var lodashEs = require('lodash-es');
require('../../../mixins/index.js');
require('../../../utils/index.js');
var buildHelper = require('../../../utils/buildHelper.js');
var useRegister = require('../../../mixins/useRegister.js');
var script = /* @__PURE__ */ vue.defineComponent({
...{
name: "ElAmapGeojson",
inheritAttrs: false
},
__name: "GeoJSON",
props: buildHelper.buildProps({
// 要加载的标准GeoJSON对象
geo: {
type: Object,
required: true
},
// marker的默认样式
markerOptions: {
type: Object
},
// 指定点要素的绘制方式,缺省时为Marker的默认样式。geojson为当前要素对应的GeoJSON对象,lnglats为对应的线的路径
getMarker: {
type: Function
},
// polyline的默认样式
polylineOptions: {
type: Object
},
// 指定线要素的绘制方式,缺省时为Polyline的默认样式。geojson为当前要素对应的GeoJSON对象,lnglats为对应的线的路径
getPolyline: {
type: Function
},
// polygon的默认样式
polygonOptions: {
type: Object
},
// 指定面要素的绘制方式,缺省时为Polygon的默认样式。geojson为当前要素对应的GeoJSON对象,lnglats为对应的线的路径
getPolygon: {
type: Function
}
}),
emits: ["init"],
setup(__props, { expose: __expose, emit: __emit }) {
const props = __props;
const emits = __emit;
let $amapComponent;
const { $$getInstance, parentInstance } = useRegister.useRegister((options, parentComponent) => {
return new Promise((resolve) => {
AMap.plugin(["AMap.GeoJSON"], () => {
if (!options.getMarker) {
options.getMarker = createMarker;
}
if (!options.getPolyline) {
options.getPolyline = createPolyline;
}
if (!options.getPolygon) {
options.getPolygon = createPolygon;
}
$amapComponent = new AMap.GeoJSON(options);
parentComponent.add($amapComponent);
resolve($amapComponent);
});
});
}, {
emits,
propsRedirect: {
geo: "geoJSON"
},
watchRedirectFn: {
__geoJSON(value) {
if ($amapComponent) {
$amapComponent.importData(value);
}
}
},
destroyComponent() {
if ($amapComponent && (parentInstance == null ? void 0 : parentInstance.$amapComponent)) {
if (!(parentInstance == null ? void 0 : parentInstance.isDestroy)) {
parentInstance == null ? void 0 : parentInstance.$amapComponent.remove($amapComponent);
}
$amapComponent = null;
}
}
});
const createMarker = (geojson, lnglat) => {
let options = props.markerOptions || {};
options = lodashEs.merge({}, options, geojson.properties);
options.position = lnglat;
return new AMap.Marker(options);
};
const createPolyline = (geojson, lnglat) => {
let options = props.polylineOptions || {};
options = lodashEs.merge({}, options, geojson.properties);
options.path = lnglat;
return new AMap.Polyline(options);
};
const createPolygon = (geojson, lnglat) => {
let options = props.polygonOptions || {};
options = lodashEs.merge({}, options, geojson.properties);
options.path = lnglat;
return new AMap.Polygon(options);
};
__expose({
$$getInstance
});
return (_ctx, _cache) => {
return vue.openBlock(), vue.createElementBlock("div");
};
}
});
exports.default = script;
//# sourceMappingURL=GeoJSON.vue2.js.map