Commit 9689f444 authored by Michael Underwood's avatar Michael Underwood
Browse files

Add LCircleMarker component

parent 5eb4724b
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
<script>
import { onMounted, ref, inject } from "vue";
import { remapEvents, propsBinder } from "../utils.js";
import { props, setup as circleMarkerSetup } from "../functions/circleMarker";
import { render } from "../functions/layer";

/**
 * Circle Marker component, lets you add and personalize circle markers on the map
 */
export default {
  name: "LCircleMarker",
  props,
  setup(props, context) {
    const leafletRef = ref({});
    const ready = ref(false);

    const addLayer = inject("addLayer");

    const { options, methods } = circleMarkerSetup(props, leafletRef, context);

    onMounted(async () => {
      const { circleMarker, DomEvent, setOptions } = await import(
        "leaflet/dist/leaflet-src.esm"
      );

      leafletRef.value = circleMarker(props.latLng, options);

      const listeners = remapEvents(context.attrs);
      DomEvent.on(leafletRef.value, listeners);

      propsBinder(methods, leafletRef.value, props, setOptions);

      addLayer({
        ...props,
        ...methods,
        leafletObject: leafletRef.value,
      });
      ready.value = true;
    });
    return render(ready, context);
  },
};
</script>
+1 −0
Original line number Diff line number Diff line
export { default as LCircleMarker } from "./LCircleMarker.vue";
export { default as LControlAttribution } from "./LControlAttribution.vue";
export { default as LControlLayers } from "./LControlLayers.vue";
export { default as LControlScale } from "./LControlScale.vue";
+40 −0
Original line number Diff line number Diff line
import { props as pathProps, setup as pathSetup } from "./path";

export const props = {
  ...pathProps,
  latLng: {
    type: [Object, Array],
    custom: true,
    default: null,
  },
  /**
   * Radius of the marker in pixels.
   */
  radius: {
    type: Number,
    default: null,
  },
};

export const setup = (props, leafletRef, context) => {
  const { options: pathOptions, methods: pathMethods } = pathSetup(
    props,
    leafletRef,
    context
  );
  const options = {
    ...pathOptions,
    ...props,
  };
  const methods = {
    ...pathMethods,
    setRadius(radius) {
      leafletRef.value.setRadius(radius);
    },
    setLatLng(latLng) {
      leafletRef.value.setLatLng(latLng);
    },
  };

  return { options, methods };
};