@operato/scene-google-map 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +15 -0
- package/assets/favicon.ico +0 -0
- package/assets/images/spinner.png +0 -0
- package/dist/gmap-marker.d.ts +67 -0
- package/dist/gmap-marker.js +230 -0
- package/dist/gmap-marker.js.map +1 -0
- package/dist/gmap-path.d.ts +54 -0
- package/dist/gmap-path.js +296 -0
- package/dist/gmap-path.js.map +1 -0
- package/dist/google-map.d.ts +49 -0
- package/dist/google-map.js +178 -0
- package/dist/google-map.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/gmap-marker.d.ts +18 -0
- package/dist/templates/gmap-marker.js +20 -0
- package/dist/templates/gmap-marker.js.map +1 -0
- package/dist/templates/gmap-path.d.ts +21 -0
- package/dist/templates/gmap-path.js +25 -0
- package/dist/templates/gmap-path.js.map +1 -0
- package/dist/templates/google-map.d.ts +18 -0
- package/dist/templates/google-map.js +20 -0
- package/dist/templates/google-map.js.map +1 -0
- package/dist/templates/index.d.ts +53 -0
- package/dist/templates/index.js +5 -0
- package/dist/templates/index.js.map +1 -0
- package/helps/scene/component/gmap-map.ko.md +3 -0
- package/helps/scene/component/gmap-map.md +3 -0
- package/helps/scene/component/gmap-map.zh.md +3 -0
- package/helps/scene/component/gmap-marker.ko.md +3 -0
- package/helps/scene/component/gmap-marker.md +3 -0
- package/helps/scene/component/gmap-marker.zh.md +3 -0
- package/helps/scene/component/gmap-path.ko.md +3 -0
- package/helps/scene/component/gmap-path.md +3 -0
- package/helps/scene/component/gmap-path.zh.md +3 -0
- package/icons/gmap-marker.png +0 -0
- package/icons/gmap-path.png +0 -0
- package/icons/google-map.png +0 -0
- package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +15 -0
- package/logs/.5e5d741d8b7784a2fbad65eedc0fd46946aaf6f2-audit.json +15 -0
- package/logs/application-2024-01-01-16.log +9 -0
- package/logs/connections-2024-01-01-16.log +41 -0
- package/package.json +62 -0
- package/schema.graphql +3966 -0
- package/src/gmap-marker.ts +306 -0
- package/src/gmap-path.ts +365 -0
- package/src/google-map.ts +215 -0
- package/src/index.ts +8 -0
- package/src/templates/gmap-marker.ts +20 -0
- package/src/templates/gmap-path.ts +25 -0
- package/src/templates/google-map.ts +20 -0
- package/src/templates/index.ts +5 -0
- package/test/basic-test.html +67 -0
- package/test/index.html +24 -0
- package/test/unit/test-google-map.js +33 -0
- package/test/unit/util.js +22 -0
- package/things-scene.config.js +5 -0
- package/translations/en.json +6 -0
- package/translations/ja.json +6 -0
- package/translations/ko.json +6 -0
- package/translations/zh.json +6 -0
- package/tsconfig.json +22 -0
- package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,215 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
const NATURE = {
|
6
|
+
mutable: false,
|
7
|
+
resizable: true,
|
8
|
+
rotatable: true,
|
9
|
+
properties: [
|
10
|
+
{
|
11
|
+
type: 'number',
|
12
|
+
label: 'latitude',
|
13
|
+
name: 'lat',
|
14
|
+
property: {
|
15
|
+
step: 0.000001,
|
16
|
+
max: 90,
|
17
|
+
min: -90
|
18
|
+
}
|
19
|
+
},
|
20
|
+
{
|
21
|
+
type: 'number',
|
22
|
+
label: 'longitude',
|
23
|
+
name: 'lng',
|
24
|
+
property: {
|
25
|
+
step: 0.000001,
|
26
|
+
min: -180,
|
27
|
+
max: 180
|
28
|
+
}
|
29
|
+
},
|
30
|
+
{
|
31
|
+
type: 'number',
|
32
|
+
label: 'zoom',
|
33
|
+
name: 'zoom'
|
34
|
+
},
|
35
|
+
{
|
36
|
+
type: 'string',
|
37
|
+
label: 'api-key',
|
38
|
+
name: 'apiKey'
|
39
|
+
}
|
40
|
+
],
|
41
|
+
'value-property': 'latlng'
|
42
|
+
// help: 'scene/component/gmap-map'
|
43
|
+
}
|
44
|
+
|
45
|
+
import { Component, HTMLOverlayContainer, Properties, ScriptLoader, error } from '@hatiolab/things-scene'
|
46
|
+
|
47
|
+
function getGlobalScale(component: GoogleMap) {
|
48
|
+
var scale = { x: 1, y: 1 }
|
49
|
+
var parent: Component = component
|
50
|
+
|
51
|
+
while (parent) {
|
52
|
+
let { x, y } = parent.get('scale') || { x: 1, y: 1 }
|
53
|
+
scale.x *= x || 1
|
54
|
+
scale.y *= y || 1
|
55
|
+
|
56
|
+
parent = parent.parent
|
57
|
+
}
|
58
|
+
return scale
|
59
|
+
}
|
60
|
+
|
61
|
+
export default class GoogleMap extends HTMLOverlayContainer {
|
62
|
+
static load(component: GoogleMap) {
|
63
|
+
var key = component.get('apiKey')
|
64
|
+
ScriptLoader.load('https://maps.googleapis.com/maps/api/js' + (key ? '?key=' + key : '')).then(
|
65
|
+
() => component.onload(),
|
66
|
+
error
|
67
|
+
)
|
68
|
+
}
|
69
|
+
|
70
|
+
private static loaded: boolean = false
|
71
|
+
|
72
|
+
private _listenTo?: Component
|
73
|
+
private _listener? = function (this: GoogleMap, after: any) {
|
74
|
+
after.scale && this.rescale()
|
75
|
+
}.bind(this)
|
76
|
+
|
77
|
+
private _anchor?: HTMLDivElement
|
78
|
+
private _map?: google.maps.Map
|
79
|
+
|
80
|
+
ready() {
|
81
|
+
super.ready()
|
82
|
+
|
83
|
+
if (this.rootModel) {
|
84
|
+
this._listenTo = this.rootModel
|
85
|
+
this.rootModel.on('change', this._listener!)
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
removed() {
|
90
|
+
if (this._listenTo) {
|
91
|
+
this._listenTo.off('change', this._listener!)
|
92
|
+
|
93
|
+
delete this._listenTo
|
94
|
+
delete this._listener
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* google map은 scale된 상태에서 마우스 포지션을 정확히 매핑하지 못하므로, 마커를 정상적으로 동작시키지 못한다.
|
100
|
+
* 따라서, google map의 경우에는 부모의 스케일의 역으로 transform해서, scale을 1로 맞추어야 한다.
|
101
|
+
*/
|
102
|
+
rescale() {
|
103
|
+
var anchor = this._anchor
|
104
|
+
if (!anchor) {
|
105
|
+
return
|
106
|
+
}
|
107
|
+
var scale = getGlobalScale(this)
|
108
|
+
|
109
|
+
var sx = 1 / scale.x
|
110
|
+
var sy = 1 / scale.y
|
111
|
+
|
112
|
+
var transform = `scale(${sx}, ${sy})`
|
113
|
+
|
114
|
+
;['-webkit-', '-moz-', '-ms-', '-o-', ''].forEach(prefix => {
|
115
|
+
anchor!.style[(prefix + 'transform') as any] = transform
|
116
|
+
anchor!.style[(prefix + 'transform-origin') as any] = '0px 0px'
|
117
|
+
})
|
118
|
+
|
119
|
+
var { width, height } = this.state
|
120
|
+
anchor.style.width = width * scale.x + 'px'
|
121
|
+
anchor.style.height = height * scale.y + 'px'
|
122
|
+
|
123
|
+
if (GoogleMap.loaded) {
|
124
|
+
google.maps.event.trigger(this.map, 'resize')
|
125
|
+
let { lat, lng } = this.state
|
126
|
+
this.map &&
|
127
|
+
this.map.setCenter({
|
128
|
+
lat,
|
129
|
+
lng
|
130
|
+
})
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
createElement() {
|
135
|
+
super.createElement()
|
136
|
+
this._anchor = document.createElement('div')
|
137
|
+
this.element.appendChild(this._anchor)
|
138
|
+
this.rescale()
|
139
|
+
|
140
|
+
GoogleMap.load(this)
|
141
|
+
}
|
142
|
+
|
143
|
+
onload() {
|
144
|
+
GoogleMap.loaded = true
|
145
|
+
|
146
|
+
var { lat, lng, zoom } = this.state
|
147
|
+
|
148
|
+
try {
|
149
|
+
this._map = new google.maps.Map(this._anchor!, {
|
150
|
+
zoom,
|
151
|
+
center: new google.maps.LatLng(lat, lng)
|
152
|
+
})
|
153
|
+
} finally {
|
154
|
+
/*
|
155
|
+
* setState 로 map 객체가 생성되었음을 change 이벤트로 알려줄 수 있다
|
156
|
+
* - set('map', this._map)으로 만들 지 않도록 주의한다.
|
157
|
+
* - setState('map', this._map)으로해야 컴포넌트 모델에 추가되지 않는다.
|
158
|
+
*/
|
159
|
+
this.setState('map', this._map)
|
160
|
+
this.rescale()
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
get tagName() {
|
165
|
+
return 'div'
|
166
|
+
}
|
167
|
+
|
168
|
+
get map() {
|
169
|
+
return this._map
|
170
|
+
}
|
171
|
+
|
172
|
+
dispose() {
|
173
|
+
super.dispose()
|
174
|
+
|
175
|
+
delete this._anchor
|
176
|
+
}
|
177
|
+
|
178
|
+
setElementProperties(div: HTMLDivElement) {
|
179
|
+
this.rescale()
|
180
|
+
}
|
181
|
+
|
182
|
+
onchange(after: Properties, before: Properties) {
|
183
|
+
if (GoogleMap.loaded) {
|
184
|
+
if (after.zoom) {
|
185
|
+
this.map!.setZoom(after.zoom)
|
186
|
+
}
|
187
|
+
|
188
|
+
if ('lat' in after || 'lng' in after) {
|
189
|
+
let { lat, lng } = this.state
|
190
|
+
this.map!.setCenter(new google.maps.LatLng(lat, lng))
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
super.onchange(after, before)
|
195
|
+
|
196
|
+
this.rescale()
|
197
|
+
}
|
198
|
+
|
199
|
+
get latlng() {
|
200
|
+
return {
|
201
|
+
lat: this.get('lat'),
|
202
|
+
lng: this.get('lng')
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
set latlng(latlng) {
|
207
|
+
this.set(latlng)
|
208
|
+
}
|
209
|
+
|
210
|
+
get nature() {
|
211
|
+
return NATURE
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
Component.register('google-map', GoogleMap)
|
package/src/index.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
const icon = new URL('../../icons/gmap-marker.png', import.meta.url).href
|
2
|
+
|
3
|
+
export default {
|
4
|
+
type: 'gmap-marker',
|
5
|
+
description: 'google map marker',
|
6
|
+
group: 'etc',
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
8
|
+
icon,
|
9
|
+
model: {
|
10
|
+
type: 'gmap-marker',
|
11
|
+
left: 150,
|
12
|
+
top: 150,
|
13
|
+
width: 40,
|
14
|
+
height: 60,
|
15
|
+
lat: 22.308117,
|
16
|
+
lng: 114.225443,
|
17
|
+
fillStyle: '#00ff00',
|
18
|
+
hidden: true
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
const icon = new URL('../../icons/gmap-path.png', import.meta.url).href
|
2
|
+
|
3
|
+
export default {
|
4
|
+
type: 'gmap-path',
|
5
|
+
description: 'google map path',
|
6
|
+
group: 'etc',
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
8
|
+
icon,
|
9
|
+
model: {
|
10
|
+
type: 'gmap-path',
|
11
|
+
left: 150,
|
12
|
+
top: 150,
|
13
|
+
width: 40,
|
14
|
+
height: 60,
|
15
|
+
latlngs: [
|
16
|
+
{
|
17
|
+
lat: 22.308117,
|
18
|
+
lng: 114.225443
|
19
|
+
}
|
20
|
+
],
|
21
|
+
startEndMarkerDifferentDesign: true,
|
22
|
+
fillStyle: '#00ff00',
|
23
|
+
hidden: true
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const icon = new URL('../../icons/google-map.png', import.meta.url).href
|
2
|
+
|
3
|
+
export default {
|
4
|
+
type: 'google-map',
|
5
|
+
description: 'google-map',
|
6
|
+
group: 'etc',
|
7
|
+
/* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
|
8
|
+
icon,
|
9
|
+
model: {
|
10
|
+
type: 'google-map',
|
11
|
+
left: 150,
|
12
|
+
top: 150,
|
13
|
+
width: 300,
|
14
|
+
height: 200,
|
15
|
+
lat: 22.308117,
|
16
|
+
lng: 114.225443,
|
17
|
+
zoom: 20,
|
18
|
+
apiKey: 'AIzaSyBgQZb-SFqjQBC_XTxNiz0XapejNwV9PgA'
|
19
|
+
}
|
20
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!--
|
2
|
+
@license
|
3
|
+
Copyright © HatioLab Inc. All rights reserved.
|
4
|
+
-->
|
5
|
+
<!doctype html>
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<meta charset="utf-8">
|
9
|
+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
10
|
+
|
11
|
+
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
12
|
+
<script src="../../web-component-tester/browser.js"></script>
|
13
|
+
|
14
|
+
<!-- Step 1: import the element to test -->
|
15
|
+
<link rel="import" href="../things-scene-google-map.html">
|
16
|
+
</head>
|
17
|
+
<body>
|
18
|
+
|
19
|
+
<!-- You can use the document as a place to set up your fixtures. -->
|
20
|
+
<test-fixture id="things-scene-google-map-fixture">
|
21
|
+
<template>
|
22
|
+
<things-scene-google-map>
|
23
|
+
<h2>things-scene-google-map</h2>
|
24
|
+
</things-scene-google-map>
|
25
|
+
</template>
|
26
|
+
</test-fixture>
|
27
|
+
|
28
|
+
<script>
|
29
|
+
suite('<things-scene-google-map>', function() {
|
30
|
+
|
31
|
+
var myEl;
|
32
|
+
|
33
|
+
setup(function() {
|
34
|
+
myEl = fixture('things-scene-google-map-fixture');
|
35
|
+
});
|
36
|
+
|
37
|
+
test('defines the "author" property', function() {
|
38
|
+
assert.equal(myEl.author.name, 'Dimitri Glazkov');
|
39
|
+
assert.equal(myEl.author.image, 'http://addyosmani.com/blog/wp-content/uploads/2013/04/unicorn.jpg');
|
40
|
+
});
|
41
|
+
|
42
|
+
test('says hello', function() {
|
43
|
+
assert.equal(myEl.sayHello(), 'things-scene-google-map says, Hello World!');
|
44
|
+
|
45
|
+
var greetings = myEl.sayHello('greetings Earthlings');
|
46
|
+
assert.equal(greetings, 'things-scene-google-map says, greetings Earthlings');
|
47
|
+
});
|
48
|
+
|
49
|
+
test('fires lasers', function(done) {
|
50
|
+
myEl.addEventListener('things-scene-google-map-lasers', function(event) {
|
51
|
+
assert.equal(event.detail.sound, 'Pew pew!');
|
52
|
+
done();
|
53
|
+
});
|
54
|
+
myEl.fireLasers();
|
55
|
+
});
|
56
|
+
|
57
|
+
test('distributed children', function() {
|
58
|
+
var els = myEl.getContentChildren();
|
59
|
+
assert.equal(els.length, 1, 'one distributed node');
|
60
|
+
assert.equal(els[0], myEl.querySelector('h2'), 'content distributed correctly');
|
61
|
+
});
|
62
|
+
|
63
|
+
});
|
64
|
+
</script>
|
65
|
+
|
66
|
+
</body>
|
67
|
+
</html>
|
package/test/index.html
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
<!--
|
2
|
+
@license
|
3
|
+
Copyright © HatioLab Inc. All rights reserved.
|
4
|
+
-->
|
5
|
+
<!DOCTYPE html>
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<meta charset="utf-8">
|
9
|
+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
10
|
+
|
11
|
+
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
12
|
+
<script src="../../web-component-tester/browser.js"></script>
|
13
|
+
</head>
|
14
|
+
<body>
|
15
|
+
<script>
|
16
|
+
// Load and run all tests (.html, .js):
|
17
|
+
WCT.loadSuites([
|
18
|
+
'basic-test.html',
|
19
|
+
'basic-test.html?dom=shadow'
|
20
|
+
]);
|
21
|
+
</script>
|
22
|
+
|
23
|
+
</body>
|
24
|
+
</html>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
import './util'
|
6
|
+
|
7
|
+
import { expect } from 'chai'
|
8
|
+
|
9
|
+
import '../../bower_components/things-scene-core/things-scene-min'
|
10
|
+
import { GoogleMap } from '../../src/index'
|
11
|
+
|
12
|
+
describe('GoogleMap', function () {
|
13
|
+
|
14
|
+
var board;
|
15
|
+
|
16
|
+
beforeEach(function () {
|
17
|
+
board = scene.create({
|
18
|
+
model: {
|
19
|
+
components: [{
|
20
|
+
id: 'google-map',
|
21
|
+
type: 'google-map'
|
22
|
+
}]
|
23
|
+
}
|
24
|
+
})
|
25
|
+
});
|
26
|
+
|
27
|
+
it('component should be found by its id.', function () {
|
28
|
+
|
29
|
+
var component = board.findById('google-map')
|
30
|
+
|
31
|
+
expect(!!component).not.to.equal(false);
|
32
|
+
});
|
33
|
+
});
|
@@ -0,0 +1,22 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
var noop = () => {}
|
6
|
+
|
7
|
+
global.Canvas = require('canvas');
|
8
|
+
|
9
|
+
Canvas.prototype.setAttribute = noop;
|
10
|
+
Canvas.prototype.style = {};
|
11
|
+
|
12
|
+
global.Image = Canvas.Image;
|
13
|
+
global.screen = {
|
14
|
+
width: 1280,
|
15
|
+
height: 800
|
16
|
+
};
|
17
|
+
|
18
|
+
global.window = global;
|
19
|
+
|
20
|
+
global.addEventListener = noop;
|
21
|
+
global.location = {};
|
22
|
+
global.getComputedStyle = noop;
|
package/tsconfig.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "es2018",
|
4
|
+
"module": "esnext",
|
5
|
+
"moduleResolution": "node",
|
6
|
+
"noEmitOnError": true,
|
7
|
+
"lib": ["es2019", "dom"],
|
8
|
+
"strict": true,
|
9
|
+
"esModuleInterop": false,
|
10
|
+
"allowSyntheticDefaultImports": true,
|
11
|
+
"experimentalDecorators": true,
|
12
|
+
"importHelpers": true,
|
13
|
+
"outDir": "dist",
|
14
|
+
"sourceMap": true,
|
15
|
+
"inlineSources": true,
|
16
|
+
"rootDir": "src",
|
17
|
+
"declaration": true,
|
18
|
+
"incremental": true,
|
19
|
+
"skipLibCheck": true
|
20
|
+
},
|
21
|
+
"include": ["**/*.ts", "*.d.ts"]
|
22
|
+
}
|