Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm's 300,000 packages pre-installed, including easy-map with all npm packages installed. Try it out:

easy-map lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("easy-map/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

easy-map v1.0.3

This is a open source project to represent map in your web page easily.

easy-map

🌏 Render a map on browser easily.

installation

Just download the js and include it in your HTML.

<!-- add easy.map in your html -->
<script type="text/javascript" src="PATH/TO/easy-map.min.js"></script>

<!-- if you use AMD or CommonJS -->
<script>
  require(["PATH/TO/easy-map"], function (EasyMap) {
    // Do something..
  });

  /* or */

  var EasyMap = require("easy-map");
</script>

NPM

$ yarn add easy-map
# or
$ npm i easy-map

Demo

$ npm run demo
# then access http://localhost:8888

How to use

Prerequisite

Parameters

ParameterTypeRemarks
mapTypestringRequired (It must be included in ['google'])
elementDOM NodeRequired
keystringRequired
sourceobjectSpecific location's information
source.latnumberSpecific location's latitude
source.lngnumberSpecific location's longitude
source.markerobjectMarker on Specific location
source.marker.iconstringWrite icon image's path
source.marker.widthnumberMarker's width (px)
source.marker.heightnumberMarker's height (px)
source.marker.verticalAlignstringtop, bottom, middle
source.marker.horizontalAlignstringright, left, center
source.infoWindowobjectMarker's infoWindow
source.infoWindow.contentstringinfoWindow's content
source.infoWindow.maxWidthnumberinfoWindow's max width (px)
source.infoWindow.backgroundColorstringinfoWindow's background color (hex code or color name)
ONLY FOR NAVER
source.infoWindow.borderColorstringinfoWindow's border color (hex code or color name)
ONLY FOR NAVER
source.infoWindow.borderWidthnumberinfoWindow's border width (px)
ONLY FOR NAVER
source.infoWindow.anchorSizeobjectinfoWindow's anchor width
new naver.maps.Size(30, 30)
ONLY FOR NAVER
source.infoWindow.anchorSkewbooleaninfoWindow's anchor shape
ONLY FOR NAVER
source.infoWindow.pixelOffsetobjectinfoWindow's offset
new naver.maps.Point(20, -20)
ONLY FOR NAVER
coordsarraySet of coordinates
coords[n]objectSame as source
closeInfoWindowAutobooleanClose automately when click a marker
clickedNestedMarkerfunctionCallback function when click nested markers
=========
coords[n].infoWindow.contentstringIf you write {{distance m}}, you can get the distance between coores[n] and source
Available unites : [m, km, ft, yd]

Basic Usage

Google Map

const easyMap = new EasyMap({
  mapType: 'google',
  key: 'AIzaSyBL4Ugej1KvkfIrU2qOhoAkE85rKEcTApo',
  element: document.getElementById('map'),
  source: {
    lat: 37.5666103,
    lng: 126.9783882,
    marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 48, height: 48, verticalAlign: 'top' },
    infoWindow: { content: '<div class="info-window">Source Marker</div>', maxWidth: 50 }
  },
  coords: [
    {
      lat: 37.5658528,
      lng: 126.9779845,
      name: 'Marker 1',
      marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 36, height: 36, verticalAlign: 'middle' },
      infoWindow: { content: '<div class="info-window">Marker 1<br>distance is {{distance m}}</div>', maxWidth: 50 }
    },
    {
      lat: 37.5658528,
      lng: 126.9779845,
      name: 'Marker 2',
      marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 36, height: 36, verticalAlign: 'middle' },
      infoWindow: { content: '<div class="info-window">Marker 2<br>distance is {{distance km}}</div>', maxWidth: 50 }
    },
  ],
  closeInfoWindowAuto: true,
  clickedNestedMarker: function (cb, ids, strs) {
    let userInput = prompt(`You clicked nested markers! Select on.\n${ strs }`, '');

    cb(+userInput);
  },
});

easyMap.start();

Naver Map

const easyMap = new EasyMap({
  mapType: 'naver',
  key: 'ZINRRHtKwGpXNxXjcqwv',
  element: document.getElementById('map'),
  source: {
    lat: 37.5666103,
    lng: 126.9783882,
    marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 48, height: 48, verticalAlign: 'top' },
    infoWindow: { content: '<div class="info-window">Source Marker</div>', maxWidth: 50 }
  },
  coords: [
    {
      lat: 37.5658528,
      lng: 126.9779845,
      name: 'Marker 1',
      marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 36, height: 36, verticalAlign: 'middle' },
      infoWindow: { content: '<div class="info-window">Marker 1<br>distance is {{distance m}}</div>', maxWidth: 50 }
    },
    {
      lat: 37.5658528,
      lng: 126.9779845,
      name: 'Marker 2',
      marker: { icon: '//assets-cdn.github.com/images/modules/contact/heartocat.png', width: 36, height: 36, verticalAlign: 'middle' },
      infoWindow: { content: '<div class="info-window">Marker 2<br>distance is {{distance km}}</div>', maxWidth: 50 }
    },
  ],
  closeInfoWindowAuto: true,
  clickedNestedMarker: function (cb, ids, strs) {
    let userInput = prompt(`You clicked nested markers! Select on.\n${ strs }`, '');

    cb(+userInput);
  },
});

easyMap.start();

Browsers support

Google Maps

Naver Maps

Change log

1.0.0

  • Initial release

1.0.2

  • Add naver map
  • Bug fix

1.0.3

  • Bug fix
  • Change coding styles in switch-case (Use braces in switch-case).

Licence

Copyright (c) 2017 wonism

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free