Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
cqiang1993
AR.js
提交
e646aa0b
A
AR.js
项目概览
cqiang1993
/
AR.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
AR.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e646aa0b
编写于
10月 18, 2019
作者:
N
Nicolò Carpignoli
提交者:
GitHub
10月 18, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #617 from jeromeetienne/statically-places-enhancements
Fix load static load of places
上级
28f0d6ec
bc0d3735
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
192 addition
and
123 deletion
+192
-123
aframe/examples/click-places/places.js
aframe/examples/click-places/places.js
+125
-74
aframe/examples/places-name/places.js
aframe/examples/places-name/places.js
+67
-49
未找到文件。
aframe/examples/click-places/places.js
浏览文件 @
e646aa0b
const
loadPlaces
=
function
(
coords
)
{
// COMMENT FOLLOWING LINE IF YOU WANT TO USE STATIC DATA AND ADD COORDINATES IN THE FOLLOWING 'PLACES' ARRAY
const
method
=
'
api
'
;
window
.
onload
=
()
=>
{
let
method
=
'
dynamic
'
;
// if you want to statically add places, de-comment following line
// method = 'static';
if
(
method
===
'
static
'
)
{
// setTimeout is a temporary fix
setTimeout
(()
=>
{
let
places
=
staticLoadPlaces
();
renderPlaces
(
places
);
},
3000
);
}
if
(
method
!==
'
static
'
)
{
// first get current user location
return
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
// than use it to load from remote APIs some places nearby
dynamicLoadPlaces
(
position
.
coords
)
.
then
((
places
)
=>
{
renderPlaces
(
places
);
})
},
(
err
)
=>
console
.
error
(
'
Error in retrieving position
'
,
err
),
{
enableHighAccuracy
:
true
,
maximumAge
:
0
,
timeout
:
27000
,
}
);
}
};
const
PLACES
=
[
function
staticLoadPlaces
()
{
return
[
{
name
:
"
Your place name
"
,
location
:
{
lat
:
0
,
// add here latitude if using static data
lng
:
0
,
// add here longitude if using static data
}
},
{
name
:
'
Another place name
'
,
location
:
{
lat
:
0
,
lng
:
0
,
}
}
];
if
(
method
===
'
api
'
)
{
return
loadPlaceFromAPIs
(
coords
);
}
return
Promise
.
resolve
(
PLACES
);
};
}
// getting places from REST APIs
function
loadPlaceFromAPI
s
(
position
)
{
cons
t
params
=
{
function
dynamicLoadPlace
s
(
position
)
{
le
t
params
=
{
radius
:
300
,
// search places not farther than this value (in meters)
clientId
:
'
HZIJGI4COHQ4AI45QXKCDFJWFJ1SFHYDFCCWKPIJDWHLVQVZ
'
,
clientSecret
:
''
,
...
...
@@ -30,10 +62,10 @@ function loadPlaceFromAPIs(position) {
};
// CORS Proxy to avoid CORS problems
cons
t
corsProxy
=
'
https://cors-anywhere.herokuapp.com/
'
;
le
t
corsProxy
=
'
https://cors-anywhere.herokuapp.com/
'
;
// Foursquare API
cons
t
endpoint
=
`
${
corsProxy
}
https://api.foursquare.com/v2/venues/search?intent=checkin
le
t
endpoint
=
`
${
corsProxy
}
https://api.foursquare.com/v2/venues/search?intent=checkin
&ll=
${
position
.
latitude
}
,
${
position
.
longitude
}
&radius=
${
params
.
radius
}
&client_id=
${
params
.
clientId
}
...
...
@@ -52,64 +84,83 @@ function loadPlaceFromAPIs(position) {
})
};
function
renderPlaces
(
places
)
{
let
scene
=
document
.
querySelector
(
'
a-scene
'
);
places
.
forEach
((
place
)
=>
{
const
latitude
=
place
.
location
.
lat
;
const
longitude
=
place
.
location
.
lng
;
// add place icon
const
icon
=
document
.
createElement
(
'
a-image
'
);
icon
.
setAttribute
(
'
gps-entity-place
'
,
`latitude:
${
latitude
}
; longitude:
${
longitude
}
`
);
icon
.
setAttribute
(
'
name
'
,
place
.
name
);
icon
.
setAttribute
(
'
src
'
,
'
../assets/map-marker.png
'
);
// for debug purposes, just show in a bigger scale, otherwise I have to personally go on places...
icon
.
setAttribute
(
'
scale
'
,
'
20, 20
'
);
icon
.
addEventListener
(
'
loaded
'
,
()
=>
window
.
dispatchEvent
(
new
CustomEvent
(
'
gps-entity-place-loaded
'
)));
const
clickListener
=
function
(
ev
)
{
ev
.
stopPropagation
();
ev
.
preventDefault
();
const
name
=
ev
.
target
.
getAttribute
(
'
name
'
);
const
el
=
ev
.
detail
.
intersection
&&
ev
.
detail
.
intersection
.
object
.
el
;
if
(
el
&&
el
===
ev
.
target
)
{
const
label
=
document
.
createElement
(
'
span
'
);
const
container
=
document
.
createElement
(
'
div
'
);
container
.
setAttribute
(
'
id
'
,
'
place-label
'
);
label
.
innerText
=
name
;
container
.
appendChild
(
label
);
document
.
body
.
appendChild
(
container
);
setTimeout
(()
=>
{
container
.
parentElement
.
removeChild
(
container
);
},
1500
);
}
};
icon
.
addEventListener
(
'
click
'
,
clickListener
);
scene
.
appendChild
(
icon
);
});
}
window
.
onload
=
()
=>
{
const
scene
=
document
.
querySelector
(
'
a-scene
'
);
// first get current user location
return
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
// then use it to load from remote APIs some places nearby
loadPlaces
(
position
.
coords
)
.
then
((
places
)
=>
{
places
.
forEach
((
place
)
=>
{
const
latitude
=
place
.
location
.
lat
;
const
longitude
=
place
.
location
.
lng
;
// add place icon
const
icon
=
document
.
createElement
(
'
a-image
'
);
icon
.
setAttribute
(
'
gps-entity-place
'
,
`latitude:
${
latitude
}
; longitude:
${
longitude
}
`
);
icon
.
setAttribute
(
'
name
'
,
place
.
name
);
icon
.
setAttribute
(
'
src
'
,
'
../assets/map-marker.png
'
);
// for debug purposes, just show in a bigger scale, otherwise I have to personally go on places...
icon
.
setAttribute
(
'
scale
'
,
'
20, 20
'
);
icon
.
addEventListener
(
'
loaded
'
,
()
=>
window
.
dispatchEvent
(
new
CustomEvent
(
'
gps-entity-place-loaded
'
)));
const
clickListener
=
function
(
ev
)
{
ev
.
stopPropagation
();
ev
.
preventDefault
();
const
name
=
ev
.
target
.
getAttribute
(
'
name
'
);
const
el
=
ev
.
detail
.
intersection
&&
ev
.
detail
.
intersection
.
object
.
el
;
if
(
el
&&
el
===
ev
.
target
)
{
const
label
=
document
.
createElement
(
'
span
'
);
const
container
=
document
.
createElement
(
'
div
'
);
container
.
setAttribute
(
'
id
'
,
'
place-label
'
);
label
.
innerText
=
name
;
container
.
appendChild
(
label
);
document
.
body
.
appendChild
(
container
);
setTimeout
(()
=>
{
container
.
parentElement
.
removeChild
(
container
);
},
1500
);
}
};
icon
.
addEventListener
(
'
click
'
,
clickListener
);
scene
.
appendChild
(
icon
);
});
})
},
(
err
)
=>
console
.
error
(
'
Error in retrieving position
'
,
err
),
{
enableHighAccuracy
:
true
,
maximumAge
:
0
,
timeout
:
27000
,
}
);
let
method
=
'
dynamic
'
;
// if you want to statically add places, de-comment following line
method
=
'
static
'
;
if
(
method
===
'
static
'
)
{
// setTimeout is a temporary fix
setTimeout
(()
=>
{
let
places
=
staticLoadPlaces
();
renderPlaces
(
places
);
},
3000
);
}
if
(
method
!==
'
static
'
)
{
// first get current user location
return
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
// than use it to load from remote APIs some places nearby
dynamicLoadPlaces
(
position
.
coords
)
.
then
((
places
)
=>
{
renderPlaces
(
places
);
})
},
(
err
)
=>
console
.
error
(
'
Error in retrieving position
'
,
err
),
{
enableHighAccuracy
:
true
,
maximumAge
:
0
,
timeout
:
27000
,
}
);
}
};
aframe/examples/places-name/places.js
浏览文件 @
e646aa0b
const
loadPlaces
=
function
(
coords
)
{
// COMMENT FOLLOWING LINE IF YOU WANT TO USE STATIC DATA AND ADD COORDINATES IN THE FOLLOWING 'PLACES' ARRAY
const
method
=
'
api
'
;
const
PLACES
=
[
window
.
onload
=
()
=>
{
let
method
=
'
dynamic
'
;
// if you want to statically add places, de-comment following line
// method = 'static';
if
(
method
===
'
static
'
)
{
// setTimeout is a temporary fix
setTimeout
(()
=>
{
let
places
=
staticLoadPlaces
();
renderPlaces
(
places
);
},
3000
);
}
if
(
method
!==
'
static
'
)
{
// first get current user location
return
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
// than use it to load from remote APIs some places nearby
dynamicLoadPlaces
(
position
.
coords
)
.
then
((
places
)
=>
{
renderPlaces
(
places
);
})
},
(
err
)
=>
console
.
error
(
'
Error in retrieving position
'
,
err
),
{
enableHighAccuracy
:
true
,
maximumAge
:
0
,
timeout
:
27000
,
}
);
}
};
function
staticLoadPlaces
()
{
return
[
{
name
:
"
Your place name
"
,
location
:
{
...
...
@@ -10,29 +43,30 @@ const loadPlaces = function (coords) {
lng
:
0
,
// add here longitude if using static data
}
},
{
name
:
'
Another place name
'
,
location
:
{
lat
:
0
,
lng
:
0
,
}
}
];
if
(
method
===
'
api
'
)
{
return
loadPlaceFromAPIs
(
coords
);
}
return
Promise
.
resolve
(
PLACES
);
};
}
// getting places from REST APIs
function
loadPlaceFromAPI
s
(
position
)
{
cons
t
params
=
{
function
dynamicLoadPlace
s
(
position
)
{
le
t
params
=
{
radius
:
300
,
// search places not farther than this value (in meters)
clientId
:
'
HZIJGI4COHQ4AI45QXKCDFJWFJ1SFHYDFCCWKPIJDWHLVQVZ
'
,
clientSecret
:
'
2VBFT2H3OWI03RY5TDIMANCX4ATUTRYSXWZJHUVYGRWEZQ24
'
,
clientSecret
:
''
,
version
:
'
20300101
'
,
// foursquare versioning, required but unuseful for this demo
};
// CORS Proxy to avoid CORS problems
cons
t
corsProxy
=
'
https://cors-anywhere.herokuapp.com/
'
;
le
t
corsProxy
=
'
https://cors-anywhere.herokuapp.com/
'
;
// Foursquare API
cons
t
endpoint
=
`
${
corsProxy
}
https://api.foursquare.com/v2/venues/search?intent=checkin
le
t
endpoint
=
`
${
corsProxy
}
https://api.foursquare.com/v2/venues/search?intent=checkin
&ll=
${
position
.
latitude
}
,
${
position
.
longitude
}
&radius=
${
params
.
radius
}
&client_id=
${
params
.
clientId
}
...
...
@@ -51,40 +85,24 @@ function loadPlaceFromAPIs(position) {
})
};
function
renderPlaces
(
places
)
{
let
scene
=
document
.
querySelector
(
'
a-scene
'
);
window
.
onload
=
()
=>
{
const
scene
=
document
.
querySelector
(
'
a-scene
'
);
// first get current user location
return
navigator
.
geolocation
.
getCurrentPosition
(
function
(
position
)
{
// than use it to load from remote APIs some places nearby
loadPlaces
(
position
.
coords
)
.
then
((
places
)
=>
{
places
.
forEach
((
place
)
=>
{
const
latitude
=
place
.
location
.
lat
;
const
longitude
=
place
.
location
.
lng
;
places
.
forEach
((
place
)
=>
{
let
latitude
=
place
.
location
.
lat
;
let
longitude
=
place
.
location
.
lng
;
// add place name
cons
t
text
=
document
.
createElement
(
'
a-link
'
);
text
.
setAttribute
(
'
gps-entity-place
'
,
`latitude:
${
latitude
}
; longitude:
${
longitude
}
;`
);
text
.
setAttribute
(
'
title
'
,
place
.
name
);
text
.
setAttribute
(
'
href
'
,
'
http://www.example.com/
'
);
text
.
setAttribute
(
'
scale
'
,
'
20 20 20
'
);
// add place name
le
t
text
=
document
.
createElement
(
'
a-link
'
);
text
.
setAttribute
(
'
gps-entity-place
'
,
`latitude:
${
latitude
}
; longitude:
${
longitude
}
;`
);
text
.
setAttribute
(
'
title
'
,
place
.
name
);
text
.
setAttribute
(
'
href
'
,
'
http://www.example.com/
'
);
text
.
setAttribute
(
'
scale
'
,
'
20 20 20
'
);
text
.
addEventListener
(
'
loaded
'
,
()
=>
{
window
.
dispatchEvent
(
new
CustomEvent
(
'
gps-entity-place-loaded
'
))
});
text
.
addEventListener
(
'
loaded
'
,
()
=>
{
window
.
dispatchEvent
(
new
CustomEvent
(
'
gps-entity-place-loaded
'
))
});
scene
.
appendChild
(
text
);
});
})
},
(
err
)
=>
console
.
error
(
'
Error in retrieving position
'
,
err
),
{
enableHighAccuracy
:
true
,
maximumAge
:
0
,
timeout
:
27000
,
}
);
};
scene
.
appendChild
(
text
);
});
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录