npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

google-map-mvvm

v1.0.1

Published

a simple mvvm for google map | 以MVVM的方式使用谷歌地图

Readme

google-map-mvvm

a simple mvvm for google map | 以MVVM的方式使用谷歌地图

usage | 使用

html

<script src="./dist/google-map-mvvm.umd.js"></script>
<script src="./index.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap">

index.js

window.initMap = function () {
  const map = new google.maps.Map(document.getElementById('map'), {
    zoom: 5,
    center: { lat: 24.886, lng: -70.268 },
    mapTypeId: 'terrain',
  });

  // I want both paths and points | 我同时需要画点和路径
  const triangleCoords = [
    { lat: 25.774, lng: -80.190 },
    { lat: 18.466, lng: -66.118 },
    { lat: 32.321, lng: -64.757 },
    { lat: 20.774, lng: -80.190 },
  ];

  // items to show | 需要展示的元素列表
  const items = [
    {
      // a Polyline for paths | 用于画路径的Polyline
      Constructor: google.maps.Polyline,
      // data is param for the constructor | 用于构造Polyline的数据参数
      data: {
        path: triangleCoords,
        geodesic: true,
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 2
      },
    },
    // 4 Circle for each point | 4个Circle用来绘制点
    ...(triangleCoords.map((x)=>{
      return {
        Constructor: google.maps.Circle,
        data: {
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.35,
          center: x,
          radius: 40000
        },
        listeners:{
          // alert point data when click | 点击的时候alert点的信息
          click:function(e){
            console.log({event:e,point:this.data.center})
            alert(JSON.stringify(this.data.center))
          }
        },
      }
    })),
  ]

  // show items through mvvm | 使用mvvm显示这些元素
  const vm = new GoogleMapMvvm({
    items,
  }, map)
}

CMD && ES6

install

npm i google-map-mvvm

use

const GoogleMapMvvm = require('google-map-mvvm')

//or ES6
//import GoogleMapMvvm from 'google-map-mvvm'

apis

config

const config = {
    // items to render
    items: [{
        // constructor
        Constructor: google.maps.Polyline,

        // param for constructor
        data: {
            ...
        },

        // listen to events
        listeners:{
          // like click
          click: function(e){
            ...
          }
        },
    }], 
    // methods
    methods: {
        log: function(){}
    },
    ready: function(){}
}

new GoogleMapMvvm(config,map) 
  • ready: this = GoogleMapMvvm instance
  • methods: in each method, this = GoogleMapMvvm instance
  • listeners: in each listener, this = item in items
  • item.$ref: the instance of item.Constructor
  • item.$vm: GoogleMapMvvm instance

context

const config = {
    items: [{
        Constructor: google.maps.Polyline,
        data: {
            ...
        },
        listeners:{
          click: function(e){
            // call from listener
            this.$vm.log(this)
          }
        },
    }], 
    // methods
    methods: {
        log: function(...args){
            console.log(args)
        }
    },
    ready: function(){
        // call from ready
        this.log('ready')
    }
}
const vm = new GoogleMapMvvm(config,map) 

// call from outside
vm.log('outside')

setItems, addItem, removeItem

// 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

try it out | 体验一下

git clone https://github.com/postor/google-map-mvvm.git
cd google-map-mvvm
npm install && npm run build && npm run start

open http://localhost:8080