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

react-google-map-draw-filter

v1.2.2

Published

GoogleMapDrawFilter

Downloads

41

Readme

Google Map Polygon Filter

React component that includes a google map which allows the possibility to draw a draggable polygon that filters the markers within its area.

Also allows the possibility to insert draggable markers and return its coordinates.

WIP comments and feedback are welcome

Demo & Examples

effect showcase

Live demo: miguelgimenezgimenez.github.io/react-google-map-draw-filter

To build the examples locally, run:

npm install
npm start

Then open localhost:8000 in a browser.

Installation

The easiest way to use react-google-map-draw-filter is to install it from NPM and include it in your own React build process (using Browserify, Webpack, etc).

You can also use the standalone build by including dist/react-google-map-draw-filter.js in your page. If you use this, make sure you have already included React, and it is available as a global variable.

npm install react-google-map-draw-filter --save

Usage

const markers = [{info:' Marker1',icon:'image/icon.jpg', label:'A',
latLng:{lng:2.13815342634916,lat:41.39485570794}},
{info:' Marker2', label:'B',latLng:{lng:2.13815342634926,lat:41.39485570795}}];

import GoogleMapDrawFilter from "react-google-map-draw-filter";


<GoogleMapDrawFilter
   apiKey='AIzaSyADYWSlC4yEedJ-5lvQb9UFOVaMMux54Zc'
   drawMode={true} //boolean that toggles draw mode (optional)
   markers={markers} //Require latLng key with lat and lng properties
   handleReturnedMarkers={this.handleReturnedMarkers.bind(this)} //Callback
   //fired when polygon is closed with the markers within the polygon as first argument
			/>								

The main props are :

  • apiKey (REQUIRED) :

api key provided by google.

  • markers :

An array of objects that has to have a [latLng] property with [lat] and [lng] properties like so [latLng:{lng:2,lat:41.}}], this markers will be returned by the callback handleReturned markers when rendered in the map, clicked on or selected within the triangle. the info prop will be the flag shown when the marker is clicked. You can also add a "label" prop which will be rendered inside the marker.

  • handleReturnedMarkers :

callback fired when the polygon is closed returning the markers within the polygon, also when the polygon is resized, with the selected markers as only argument of the callback.

  • onMarkerClick :

callback fired when marker is clicked.Also has the marker as only argument of the callback.

  • drawMode :

Boolean that to can be used to turn on the draw mode. By default is ON.

  • insertMarker:

Boolean to insert a marker in the map. If set to on a draggable marker will be rendered in the map wherever you click. the callback handleReturnedMarkers is fired when set and dragged on the map.

IF WE WANT TO INSERT A MARKER AND GET ITS COORDINATES WE HAVE TO PASS A PROP CALLED INSERT MARKER AND SET IT AS TRUE :

  <GoogleMapDrawFilter
     apiKey='AIzaSyADYWSlC4yEedJ-5lvQb9UFOVaMMux54Zc'
     mapStyle={{height:400,width:800}}
     drawMode={false}
     insertMarker={true}
     handleReturnedMarkers={this.handleReturnedMarkers.bind(this)}
              />

More examples here https://github.com/miguelgimenezgimenez/reactGoogleMapSampleProject

PropTypes

You can provide polygon , and Marker options the same way you would in google maps, the mapStyle takes widtht and height property for the map, set to 600px by default


GoogleMap.propTypes={
	apiKey:React.PropTypes.string.isRequired,
	drawMode:React.PropTypes.bool,
	markers:React.PropTypes.array,
	mapConfig:React.PropTypes.object,
	polygonOptions:React.PropTypes.object,
	google:React.PropTypes.object, //is provided by wrapper
	mapStyle:React.PropTypes.object,
	handleReturnedMarkers:React.PropTypes.func,
	insertMarker:React.PropTypes.bool,
	onMarkerClick:React.PropTypes.func,


}
GoogleMap.defaultProps={
	drawMode:true,
	mapConfig:{
		zoom:14,
		lat:41.384279176844764,
		lng:2.1526336669921875,

	},
	mapStyle:{
		height:'600px',
		width: '600px',
	},
	polygonOptions:{
		fillColor: '#455A64',
		fillOpacity: 0.3,
		strokeColor:'#455A64',
		strokeWeight:3,
		clickable: true,
		editable: true,
		zIndex: 1
	},
	markers:[],
}

Development (src, lib and the build process)

NOTE: The source code for the component is in src. A transpiled CommonJS version (generated with Babel) is available in lib for use with node.js, browserify and webpack. A UMD bundle is also built to dist, which can be included without the need for any build system.

To build, watch and serve the examples (which will also watch the component source), run npm start. If you just want to watch changes to src and rebuild lib, run npm run watch (this is useful if you are working with npm link).

License

MIT

Copyright (c) 2017 Miguel Gimenez.