factory.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export function createPoint (BMap, options = {}) {
  2. const {lng, lat} = options
  3. return new BMap.Point(lng, lat)
  4. }
  5. export function createPixel (BMap, options = {}) {
  6. const {x, y} = options
  7. return new BMap.Pixel(x, y)
  8. }
  9. export function createBounds (BMap, options = {}) {
  10. const {sw, ne} = options
  11. return new BMap.Bounds(createPoint(BMap, sw), createPoint(BMap, ne))
  12. }
  13. export function createSize (BMap, options = {}) {
  14. const {width, height} = options
  15. return new BMap.Size(width, height)
  16. }
  17. export function createIcon (BMap, options = {}) {
  18. const {url, size, opts = {}} = options
  19. return new BMap.Icon(url, createSize(BMap, size), {
  20. anchor: opts.anchor && createSize(BMap, opts.anchor),
  21. imageSize: opts.imageSize && createSize(BMap, opts.imageSize),
  22. imageOffset: opts.imageOffset && createSize(BMap, opts.imageOffset),
  23. infoWindowAnchor: opts.infoWindowAnchor && createSize(BMap, opts.infoWindowAnchor),
  24. printImageUrl: opts.printImageUrl
  25. })
  26. }
  27. export function createLabel (BMap, options = {}) {
  28. const {content, opts} = options
  29. return new BMap.Label(content, {
  30. offset: opts.offset && createSize(BMap, opts.offset),
  31. position: opts.position && createPoint(BMap, opts.position),
  32. enableMassClear: opts.enableMassClear
  33. })
  34. }