Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
baidu-map-mvvm
Advanced tools
a simple mvvm for baidu map | 以MVVM的方式使用百度地图
html
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=YOUR_API_KEY"></script>
<script type="text/javascript" src="./dist/baidu-map-mvvm.umd.js"></script>
<script type="text/javascript" src="./index.js"></script>
index.js
// 百度地图API功能
var map = new BMap.Map("allmap"); // 创建Map实例
map.centerAndZoom(new BMap.Point(116.404, 39.915), 15); // 初始化地图,设置中心点坐标和地图级别
//添加地图类型控件
map.addControl(new BMap.MapTypeControl({
mapTypes:[
BMAP_NORMAL_MAP,
BMAP_HYBRID_MAP
]
}));
map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
const items = [
{
Constructor: BMap.Polyline,
data: [
[
new BMap.Point(116.399, 39.910),
new BMap.Point(116.405, 39.920),
new BMap.Point(116.423493, 39.907445)
],
{
strokeColor:"blue",
strokeWeight:2,
strokeOpacity:0.5
},
],
}
]
const vm = new MapMvvm({
items,
}, map)
install
npm i baidu-map-mvvm
use
const MapMvvm = require('baidu-map-mvvm')
//or ES6
//import MapMvvm from 'baidu-map-mvvm'
const config = {
// items to render
items: [{
// constructor
Constructor: baidu.maps.Polyline,
// param for constructor
data: {
...
},
// listen to events
listeners:{
// like click
click: function(e){
...
}
},
// init action
init: function(){}
}],
// methods
methods: {
log: function(){}
},
ready: function(){}
}
new MapMvvm(config,map)
const config = {
items: [{
Constructor: BMap.Polyline,
data: {
...
},
listeners:{
click: function(e){
// call from listener
this.$vm.log(this)
}
},
init: function(){
this.$vm.log(this)
}
}],
// methods
methods: {
log: function(...args){
console.log(args)
}
},
ready: function(){
// call from ready
this.log('ready')
}
}
const vm = new MapMvvm(config,map)
// call from outside
vm.log('outside')
// update all
vm.$setItems(items)
// add
vm.$addItem(item)
// remove
vm.$removeItem(vm.$items[0])
use this
instead of vm
in ready
or method
, use this.$vm
in listener
git clone https://github.com/postor/baidu-map-mvvm.git
cd baidu-map-mvvm
npm install && npm run build && npm run start
FAQs
a simple mvvm for baidu map | 以MVVM的方式使用百度地图
The npm package baidu-map-mvvm receives a total of 0 weekly downloads. As such, baidu-map-mvvm popularity was classified as not popular.
We found that baidu-map-mvvm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.