Git Product home page Git Product logo

nepalmap's Introduction

NepalMap

nepalmap allows you to embed a clickable svg map of Nepal.

Installing

npm i nepalmap

Add script

import NepalMap from "nepalmap";

How to use it?

HTML

<div id="root"></div>

Javascript

const Map = new NepalMap();

Now inorder to paint the Map in the website use the setRoot method. It expects the id of the element that you want to set as root as an argument. The setRoot method returns a promsie so you must use await or .then/catch.

await Map.setRoot("root");

Set size of Map

You can use setSize method to set the size of the Map.

Map.setSize("500px", "500px");

Get lists of districts

let districts = Map.DistrictLists;

Set map property

Set property of the map using the setMapProperty

Map.setMapProperty({
  fill: "green",
});

Options

Attribute Description Example Value
fill Set fill(color) of the svg map "green"
stroke Set stroke(border color) of map "black"
cursor Set cursor "pointer"
hoverColor Set hover color "blue"
clickEvent Provide a callback function to fire on click function(){}

Set Property of an individual district

Map.setTarget({
  targets: ["dhading", "kathmandu"],
  fill: "blue",
});

Options

Attribute Description Example Value
targets Provide the target districts to set the property ["kavre","kathmandu"]
fill Set fill (color) "red"
stroke Set stroke (border color) "black"
cursor Set cursor "pointer"
hoverColor Set hover color "blue"
clickEvent Provide a callback function to fire on click(has event as first argument and placename as second argument) function(event,placename){}

Remove Map

You can remove the map from the dom using the removeMap() method

Map.removeMap();

Markers

Add markers in the Map.

You can add marker with createMarker method. It expects the marker location as first argument and options as second argument.

let marker = Map.createMarker("assets/marker.svg", {
  addOnClick: true,
});
Attribute Description Example Value
addOnClick Accepts boolean. Add marker when clicked on districts true
width width of marker "15px"
height height of marker "15px"
allowedToMark Specifies which districts are allowed to mark ["kavre","kathmandu"]

Add mark by place name

marker.addMarkWithName(["kavre", "kathmandu"]);

nepalmap's People

Contributors

abhishektimalsina avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.