Giter Site home page Giter Site logo

huasofoundries / ig_markerfactory Goto Github PK

View Code? Open in Web Editor NEW
3.0 10.0 0.0 1.52 MB

Uses canvas to dynamically generate marker images suitable for use with google maps

Home Page: http://huasofoundries.github.io/ig_markerfactory/

License: MIT License

JavaScript 84.75% Makefile 2.85% HTML 12.40%
icons canvas font jspm graphic-fonts javascript rollup

ig_markerfactory's Introduction

IG MarkerFactory

This is a zero dependencies library that uses a canvas element to generate valid google.maps.Marker Icons from graphic-fonts, such as Font-Awesome, Material-Icons or Fontello.

Travis Build Status Code Climate Codacy Badge npm Scrutinizer Build Scrutinizer Code Quality

Why?

Because some libraries, like google maps API, expect its Markers to have an valid google.maps.Icon to be shown on the map:

var mymarker = new google.maps.Marker({
	position: myMap.getCenter(),
	map: myMap
});

mymarker.setIcon({
	url: "/img/some_image.png",
	size: new google.maps.Size(54, 48),
	origin: new google.maps.Point(0, 0),
	anchor: new google.maps.Point(27, 24)
});

(Actually, it would be enough to set)

mymarker.setIcon("/img/some_image.png");

But still, you need an image. You'll need to host every icon and color combination thay might ever be.

With MarkerFactory, you generate those icons on the fly.

Example

See the example running at http://huasofoundries.github.io/ig_markerfactory/ and you'll be presented with three graphical fonts variations, both in their CSS render as well as their PNG rendering generated by IG_Markerfactory.

screenshot from 2016-07-06 12-00-51

Feel free to play with examples/example.js to see what happens when you try different colors, icons and scales.

Installation

Including it with a script tag

Include this package in your HTML file directly with a script tag using unpkg or jsdelivr

<script src="https://unpkg.com/ig_markerfactory/dist/markerfactory.min.js"></script>

or

<script src="https://cdn.jsdelivr.net/npm/ig_markerfactory/dist/markerfactory.min.js"></script>

Install with npm

Install it with npm like so:

npm install ig_markerfactory

Install with JSPM

Or include it in your JSPM/SystemJS project doing:

jspm install npm:ig_markerfactory

Usage

This is a simple example using AMD loading. It assumes you're using a font that's already present in the DOM.

AMD Style

define(["ig_markerfactory"], function(MarkerFactory) {
	var myIcon = MarkerFactory.autoIcon({
		label: "f1b9",
		font: "FontAwesome",
		color: "#CC0000",
		fontsize: 20
	});

	console.log(myIcon);
});

CommonJS Style

Require the library it with CommonJS format.

var MarkerFactory = require("ig_markerfactory");
var myIcon = MarkerFactory.autoIcon({
	label: "f1b9",
	font: "FontAwesome",
	color: "#CC0000",
	fontsize: 20
});

console.log(myIcon);

ES6 Style

If you're using an ES6 module bundler/transpiler (and you should!) import the ES6 version doing:

import { MarkerFactory } from "ig_markerfactory/dist/markerfactory.es6";

const myIcon = MarkerFactory.autoIcon({
	label: "f1b9",
	font: "FontAwesome",
	color: "#CC0000",
	fontsize: 20
});

console.log(myIcon);

You will see that myIcon object is a valid google.maps.Icon object, but of course you might want the image for other purposes so you can just use myIcon.url which is a data URI

ig_markerfactory's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ig_markerfactory's Issues

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.