Socket
Socket
Sign inDemoInstall

measuretool-googlemaps-v3

Package Overview
Dependencies
0
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    measuretool-googlemaps-v3

A handy measurement widget for Google Maps API v3. The functionalities are implemented as close as to what current Google Maps offers.


Version published
Maintainers
1
Install size
363 kB
Created

Readme

Source

Measurement Tool for Google Maps API V3

A handy measurement widget for Google Maps API v3. The functionalities are implemented as close as to what current Google Maps offers.

Demo

Visit demo page

demo screen shot

Developer usage

Dependency

Make sure the geometry library is referenced in the Google Maps JavaScript API loading script.

libraries=geometry
Basic use

To create the measurement widget, pass in a Google Map instance.

var measureTool = new MeasureTool(map);
Pass in MeasureToolOptions

You could also pass in a MeasureToolOptions as the second argument to customize to your preference.

var measureTool = new MeasureTool(map, {
  showSegmentLength: true,
  unit: MeasureTool.UnitTypeId.IMPERIAL // or just use 'imperial'
});
Bind to your own UI

The MeasureTool comes with a context menu out of box for saving your time to create your own. However, if you'd like to bind the MeasureTool to your own UI, you could specify contextMenu to false when constructing the MeasureTool. The MeasureTool exposes two public methods start() and end() to start and end measuring. For example,

<button onclick="measureTool.start()">start</button>
<button onclick="measureTool.end()">end</button>
var measureTool = new MeasureTool(map, {
  contextMenu: false
  // some other options...
});

User usage

  1. To start measuring, right click the map and choose Measure distance.
  2. Left click the map, and the measurement between the two locations will display. Keep clicking to add more measurement waypoints.
  3. To remove a waypoint, left click on the waypoint (the first point cannot be removed).
  4. To insert a waypoint on the measurement line, click the line. Waypoints can be moved by clicking and dragging them.
  5. When the first point and the last point are close enough, the area will display.
  6. To end measuring, right click the map and choose Clear measurement.

API

MeasureTool class

ConstructorDescription
MeasureTool(map:google.maps.Map, opts?:MeasureToolOptions)Creates a new measure tool for the google.maps.Map instance.
MethodsDescription
addListener(eventName: string, handler:Function)Return Value: None - addes the given listener function to the given event name.
end()Return Value: None - ends measuring.
removeListener(eventName: string)Return Value: None - removes the given listener.
start()Return Value: None - starts measuring.
setOption(option: string, value: string)Return Value: None - updates a confirguration option and re-generates the drawn shape.
PropertiesDescription
areaType: number - the total area of the enclosed polygon, the unit is for metric unit and ft² for imperial unit.
areaTextType: string - the formatted total area with unit of the enclosed polygon.
lengthType: number - the total length of the path drawn, the unit is m for metric unit and ft for imperial unit.
lengthTextType: string - the formatted total length with unit of the path drawn.
EventsDescription
measure_changeArguments: MeasureEvent - This event is fired when a measure step is completed
measure_endArguments: MeasureEvent - This event is fired when the user ends measuring
measure_startArguments: None - This event is fired when the user starts measuring

MeasureToolOptions object specification

PropertiesDescription
showSegmentLengthType: boolean - display segment length along the path. Enabled by default.
tooltipType: boolean - display tooltip when hover the drawing path. Enabled by default.
unitType: UnitTypeId - the unit type to use for the measured length and area. Defaults to MeasureTool.UnitTypeId.METRIC.

MeasureEvent object specification

PropertiesDescription
resultType: MeasureResult - The result of the measuring.

MeasureResult object specification

PropertiesDescription
areaType: number - the total area of the enclosed polygon, the unit is for metric unit and ft² for imperial unit.
areaTextType: string - the formatted total area with unit of the enclosed polygon.
lengthType: number - the total length of the path drawn, the unit is m for metric unit and ft for imperial unit.
lengthTextType: string - the formatted total length with unit of the path drawn.

UnitTypeId constants

Identifiers for common UnitType. Specify these by value, or by using the constant's name. For example, 'metric' or MeasureTool.UnitTypeId.METRIC.

ConstantDescription
IMPERIALThis unit type shows measured length in US foot (ft) and mile (mi), and area in US square foot (ft²) and square mile (mi²).
METRICThis unit type shows measured length in meter (m) and kilometer (km), and area in square meter (m²) and square kilometer (km²).

Keywords

FAQs

Last updated on 20 Feb 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc