1
0
forked from x/ContextOS

add love.maps

This commit is contained in:
shaoying 2019-09-29 09:49:07 +08:00
parent 4a58e09fce
commit a58ece0f72
7 changed files with 76 additions and 11 deletions

View File

@ -4,5 +4,5 @@ var version = struct {
host string
self int
}{
"2019-09-27 10:34:50", "centos", 607,
"2019-09-28 15:18:05", "mac", 611,
}

View File

@ -849,9 +849,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
// 响应类型
accept_json := strings.HasPrefix(m.Option("accept"), "application/json")
w := m.Optionv("response").(http.ResponseWriter)
if accept_json {
if !accept_json {
w.Header().Set("Content-Type", "text/html")
} else {
w.Header().Set("Content-Type", "application/json")
}
w.Header().Set("Access-Control-Allow-Origin", "api.map.baidu.com")
web, ok := m.Target().Server.(*WEB)
m.Assert(ok)

View File

@ -1,4 +1,16 @@
{init: function(run, field, option, output) {return {
{init: function(run, field, option, output) {
var id
return {
initMap: function() {var plugin = field.Plugin
var width = field.parentNode.clientWidth-40
!id && (id = plugin.id+"map"+plugin.ID())
kit.AppendChilds(output, [{type: "div", data: {id: id}, style: {width: width+"px", height: width*3/5}}])
map = new BMap.Map(id)
map.addControl(new BMap.NavigationControl())
map.addControl(new BMap.ScaleControl())
map.addControl(new BMap.OverviewMapControl())
map.addControl(new BMap.MapTypeControl())
},
show: function(event) {
run(event, ["", "", "cmd", "ssh.data", "show", option.table.value], function(msg) {ctx.Table(msg, function(value) {
kit.Selector(output, ".s"+value[option.when.value].split(" ")[0].split("-").join(""), function(item) {
@ -56,4 +68,40 @@
})
})
},
Search: function() {var plugin = field.Plugin
plugin.initMap()
var g = new BMap.Geocoder()
g.getPoint(option.place.value, function(p) {
kit.Log("place", p)
if (!p) {alert("not found"); return}
map.centerAndZoom(p, option.scale.value)
}, option.city.value)
},
Record: function() {var plugin = field.Plugin
var l = map.getCenter()
run(event, [option.table.value, option.when.value, option.what.value, option.city.value, option.place.value, l.lng, l.lat, map.getZoom()], function(msg) {
console.log("ok")
})
},
Plays: function() {var plugin = field.Plugin
plugin.initMap(), run(event, [option.table.value], function(msg) {
kit.List(ctx.Table(msg), function(line) {
output.style.opacity = 0
var p = new BMap.Point(line.longitude, line.latitude)
map.centerAndZoom(p, line.scale)
var info = new BMap.InfoWindow(line.when+"<br/>"+line.place, {width: 200, height: 100, title: line.what})
map.openInfoWindow(info, map.getCenter())
var scales = []
for (var i = 0; i < 10; i++) {
scales.push(i*0.1)
}
kit.List(scales, function(scale) {
output.style.opacity = scale
}, 100)
}, 3000)
})
},
}}}

View File

@ -36,6 +36,24 @@ fun days "每一天" "index.js" "index.css" protected \
end
end
fun maps "每一面" "index.js" "index.css" protected \
text "maps" name table imports plugin_table \
text "" name when init date \
text "" name what view long \
text "北京市" name city \
text "弘源首著" name place \
text "16" name scale \
button "搜索" cb Search \
button "记录" cb Record \
button "展示" cb Plays
if $2 == "" || $3 == ""
copy skip ssh.data show _
else
copy ssh.data insert _ when _ what _ city _ place _ longitude _ latitude _ scale _
end
end
fun delay "以后告诉你" protected \
text "delay" name table imports plugin_table \
text "" name when init date\

View File

@ -704,6 +704,6 @@ var page = Page({check: true,
page.onaction[item] && page.onaction[item](event, item, value, page)
})
page.river.Pane.Show()
page.WSS()
// page.WSS()
},
})

View File

@ -734,12 +734,7 @@ function Plugin(page, pane, field, runs) {
Append: function(item, name, value) {
kit.Item(plugin.onaction, function(k, cb) {
item[k] == undefined && (item[k] = typeof cb == "function"? function(event) {
try {
cb(event, action, item.type, input.name, item)
} catch (e) {
console.trace()
kit.Log("err", e)
}
}: cb)
});
item.value = plugin.onformat(item.init)(item.value)

View File

@ -30,6 +30,7 @@
{{range $index, $lib := option . "scripts"}}
<script src="/static/librarys/{{$lib}}"></script>
{{end}}
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak="></script>
</body>
{{end}}