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 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-map-geofence

v1.0.0

Published

Google map geofence library to create geofences, drapg and drop, add node, delete node.

Downloads

7

Readme

Google Maps Geofence

geofence.js - Google maps geofence api in a more sophisticated way.

Click for demo https://sujancse.github.io/geofence/

How to Use

  1. Add a reference to Google Maps API
  2. Add gmap-v3-geofence.min.js in your HTML
  3. And don't forget to add the Google Maps API key
<!DOCTYPE html>
<html>
<head>
  <title>Geofence Demo</title>
  <script src="http://maps.google.com/maps/api/js?key=YOUR_API_KEY"></script>
  <script src="gmap-v3-geofence.js"></script>
  <style type="text/css">
    #mymap {
      width: auto;
      height: 450px;
    }
  </style>
</head>
<body>
  <div id="mymap"></div>
  <script>
  
    var coords = [
        [23.832570352277692,90.41199964550788],
        [23.798165936805923,90.38352334497074],
        [23.79768310017011,90.43916111914064]
    ];
    
    var geofence = new Geofence({mapId: 'mymap'});
    
    geofence.draw(coords);
    
  </script>
</body>
</html>

Geofence Events

Events list

  • nodeClick
  • polygonClick
  • dragStart
  • dragEnd
  • setAt
  • insertAt

Example Usage

Click on the node and delete

geofence.on('nodeClick', [polygon], function (event, polygon) {
    // Do something with the event and clicked polygon
    
    // Your can show infoWindow or marker
    var contentString = '<button id="delete">Delete</button>';
    infoWindow = geofence.createInfowindow(contentString, event);
    
    // Then on infowindow ready click delete to delete the node
    geofence.onDomReady(infoWindow, function() {
        selectId('delete').addEventListener('click', function() {
            geofence.close(infoWindow);
            geofence.deleteNode(event, polygon);
        });
    });
});

Drag end revert the polygon

geofence.on('dragEnd', [polygon], function (event, polygon, previousState) {
    
    // Show the infowindow
    var contentString = '<button id="revert">Revert</button>';
    infoWindow = geofence.createInfowindow(contentString, event);
    
    // On infowindow ready revert the polygon to previous state
    geofence.onDomReady(infoWindow, function() {
        selectId('revert').addEventListener('click', function() {
            geofence.close(infoWindow);
            geofence.revert(polygon, previousState);
        });
    });
});

API functions

Draw the polygon

/**
 * Draw polygon using coordinates
 *
 * @param coordinates
 * @param options optional
 * @returns {*}
 */
 
geofence.draw(coords, options);

Polygon events

On polygon node click

/**
* On node click will give you the event
* which includes the node coordinates
* See demo example how to use that coordinates
*/

geofence.on('nodeClick', [polygon], function (event, polygon) {
    // Do something with the node and polygon
});

On polygon click

/**
* On click will give you the event
* which includes the clicked coordinates
* See demo example how to use that coordinates
*/

geofence.on('polygonClick', [polygon], function (event, polygon) {
    // Do something with the event and polygon
});

Delete the clicked node

/**
* Delete the node by passing the node clicked event 
* and the polygon object
*
* Use this function inside on node click event
*/

geofence.deleteNode(event, polygon);

Drag the polygon and catch the event

/**
* Polygon dragStart will give you the event
* which includes the current coordinates
*/

geofence.on('dragStart', function(event, polygon) {
    // Do somethong with the event and polygon
});

Polygon dragEnd event

/**
* Polygon dragEnd will give you the event, current polygon
* and the previous polygon state
*
* See the advanced demo to know
* How to get back to the previous demo
*/

geofence.on('dragEnd', function(event, polygon, previousState) {
    // Do somethong with the event, polygon and previousState
});

Polygon insertAt and setAt event

/**
* Polygon insertAt and setAt will give you the event and polygon
*
* You get the polygon coordinates and events
*/

geofence.on('insertAt', function(event, polygon) {
    // Do somethong with the event and polygon
});

geofence.on('setAt', function(event, polygon) {
    // Do somethong with the event and polygon
});

Create InfoWindow and Marker

Create an infoWindow

/**
* Provide the content string
* Make sure you use this inside some events
*/

geofence.createInfowindow(contentString, event);

geofence.close(infoWindow);

Create a marker

/**
* Provide the title
* Make sure you use this inside some events
*/

geofence.createMarker(title, event);

geofence.closeMarker(marker);

General helper functions

Revert the polygon to previous state

/**
* Revert the polygon to previous state
* Make sure to use inside dragEnd event
*/

geofence.revert(polygon, previousState);

Get the polygon coordinates

/**
 * Get the polygon coordinates
 *
 * @param polygon object
 * @returns {*|Array}
 */
 
geofence.getCoordinates(polygon);

Get the polygon coordinates string

/**
 * Get the polygon coordinates string
 *
 * @param polygon object
 * @returns string
 */
 
geofence.getCoordinatesString(polygon);

Coordinates string to array

/**
 * Get the polygon coordinates string to array
 *
 * @param polygon object
 * @returns array
 */
 
geofence.stringToArray(coordinatesString);

Coordinates to LatLng object

/**
 * Coordinates to LatLng object
 *
 * @param polygon object
 * @returns LatLng object
 */
 
geofence.coordinatesToLatLng(coordinates);