8 |
9 | Mode
10 |
11 |
12 |
13 | {{#each this.modes as |item|}}
14 |
26 | {{/each}}
27 |
28 |
29 |
30 | Tools
31 |
32 |
33 | {{#if (is-equal this.markupData.mode 'draw')}}
34 |
35 | {{#each this.drawTools as |tool|}}
36 |
44 | {{/each}}
45 |
46 | {{else if (is-equal this.markupData.mode 'measure')}}
47 |
48 | {{#each this.measureTools as |tool|}}
49 |
57 | {{/each}}
58 |
59 | {{/if}}
60 |
61 | {{! template-lint-disable simple-unless}}
62 | {{#unless (is-equal this.toolId 'pan')}}
63 | {{#if this.activeTool.options}}
64 |
65 | Options
66 |
67 |
71 | {{/if}}
72 | {{/unless}}
73 |
74 |
81 |
91 |
92 |
93 | {{yield}}
94 |
95 |
--------------------------------------------------------------------------------
/addon/components/google-maps-markup.js:
--------------------------------------------------------------------------------
1 | import { inject as service } from '@ember/service';
2 | import { tracked, cached } from '@glimmer/tracking';
3 | import { alias } from '@ember/object/computed';
4 | import { copy } from 'ember-copy';
5 | import { run, next } from '@ember/runloop';
6 | import { A as boundArray } from '@ember/array';
7 | import { set, action } from '@ember/object';
8 | import { v1 } from 'uuid';
9 | import { Root } from 'ember-composability-tools';
10 | import MODE from '../utils/modes';
11 | import overlayToFeature from '../utils/overlay-to-feature';
12 | import featureCenter from '../utils/feature-center';
13 | import initMeasureLabel from '../utils/init-measure-label';
14 | import mapLabelFactory from '../utils/map-label';
15 | import dynamicLabelFactory from '../utils/dynamic-label';
16 | import labelPlotter from '../utils/label-plotter';
17 |
18 | const clearAllConfirm =
19 | 'Markup is unsaved. Do you wish to continue clearing all markup?';
20 |
21 | export default class GoogleMapsMarkup extends Root {
22 | @service('markupData') markupData;
23 |
24 | // Start Attrs
25 | @cached
26 | get editable() {
27 | return this.args.editable ?? true;
28 | }
29 |
30 | @cached
31 | get panForOffscreen() {
32 | return this.args.panForOffscreen ?? true;
33 | }
34 |
35 | @cached
36 | get autoResetToPan() {
37 | return this.args.autoResetToPan ?? false;
38 | }
39 |
40 | @cached
41 | get map() {
42 | let map = this.args.map || this.markupData.map;
43 |
44 | return map;
45 | }
46 |
47 | get childComponents() {
48 | return [...this.children];
49 | }
50 | // End Attrs
51 |
52 | @alias('markupData.layers')
53 | dataLayers;
54 | @alias('markupData.results')
55 | results;
56 | @alias('markupData.modes')
57 | modes;
58 | @alias('markupData.drawTools')
59 | drawTools;
60 | @alias('markupData.measureTools')
61 | measureTools;
62 | @alias('markupData.textGeoJson')
63 | textGeoJson;
64 | @alias('markupData.tools')
65 | tools;
66 |
67 | @tracked drawFinished;
68 | @tracked toolActive;
69 | @tracked lastActiveLayer;
70 | @tracked activeTool = undefined;
71 | @tracked toolId = undefined;
72 |
73 | listeners = boundArray();
74 | toolListeners = boundArray();
75 | currentPoints = boundArray();
76 | resultsHidden = false;
77 |
78 | constructor() {
79 | super(...arguments);
80 |
81 | if (!window.google) {
82 | throw new Error('Sorry, but `window.google` is required for this addon');
83 | }
84 | this.toolId = this.tools.pan.id;
85 | this.dm = new google.maps.drawing.DrawingManager({
86 | drawingControl: false,
87 | });
88 | this.MapLabel = mapLabelFactory();
89 | this.currentLabel = new this.MapLabel(undefined, {
90 | dontScale: true,
91 | });
92 | this.DynamicLabel = dynamicLabelFactory();
93 |
94 | this.initPopupEvents();
95 | }
96 |
97 | @action
98 | setup(_el, [map]) {
99 | if (!this.mapSetup && map) {
100 | this.mapSetup = true;
101 | this.setupLayers(map);
102 | this.changeMode(MODE.draw);
103 | }
104 | }
105 |
106 | initPopupEvents() {
107 | let editable = this.editable;
108 |
109 | if (editable) {
110 | let popup = new google.maps.InfoWindow();
111 |
112 | popup.setContent(`