Git Product home page Git Product logo

js-map-label's Introduction

Please note: This repository is not currently maintained, and is kept for historical purpose only.

Map Label โ€“ A Google Maps JavaScript API utility library

A library that adds well-styled, customizable text to a particular location in a Google Maps JavaScript API v3 map.

Note that browser <canvas> support is required for the label to be displayed. Analytics

Reference documentation

Migrated from the Google Maps JavaScript API utility libraries on Google Code.

Live Demo

MapLabel Screenshot

Example page

Contributing

Want to contribute? Check out the contributing guide!

License

Copyright 2014 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

js-map-label's People

Contributors

brendankenny avatar broady avatar markmcd avatar skaree avatar stephenmcd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-map-label's Issues

Support the asynchronous maps API.

At present the script requires the core map code to be already present in the page which prevents asynchronous loading of maps whilst using the MapLabel function.

https://github.com/googlemaps/js-map-label/blob/gh-pages/src/maplabel.js#L44

It would be better, in my opinion, if the prototypical properties were copied from OverlayView on first
instance of the constructor getting initialised. That would allow someone to asynchronously load the map script and instantiate inheritance when calling new MapLabel for the first time.

function MapLabel(opt_options) {

    if (!MapLabel.prototype.setValues) {
        // Copy the properties over.
        for (var prop in google.maps.OverlayView.prototype) {
            MapLabel.prototype[prop] = google.maps.OverlayView.prototype[prop];
        }
    }

    this.set('fontFamily', 'sans-serif');
    this.set('fontSize', 12);
    this.set('fontColor', '#000000');
    this.set('strokeWeight', 4);
    this.set('strokeColor', '#ffffff');
    this.set('align', 'center');

    this.set('zIndex', 1e3);

    this.setValues(opt_options);
}

Multiline / Wrap Text Support

To get multiline support, add this:

MapLabel.prototype.wrapText = function(context, text, x, y, maxWidth, lineHeight) {
  var words = text.split(' ');
  var line = '';

  for(var n = 0; n < words.length; n++) {
    var testLine = line + words[n] + ' ';
    var metrics = context.measureText(testLine);
    var testWidth = metrics.width;
    if (testWidth > maxWidth && n > 0) {
      context.strokeText(line, x, y);
      context.fillText(line, x, y);

      line = words[n] + ' ';
      y += lineHeight;
    }
    else {
      line = testLine;
    }
  }
  context.strokeText(line, x, y);
  context.fillText(line, x, y);
};

In drawCanvas_, change

    if (strokeWeight) {
      ctx.lineWidth = strokeWeight;
      ctx.strokeText(text, strokeWeight, strokeWeight);
    }

    ctx.fillText(text, strokeWeight, strokeWeight);

to

    if (strokeWeight) {
      ctx.lineWidth = strokeWeight;

    }

    this.wrapText(ctx, text, strokeWeight, strokeWeight, *ADD MAX WIDTH*, *ADD LINEHEIGHT*);
    //e.g.  this.wrapText(ctx, text, strokeWeight, strokeWeight, 200, 14);

This code is an extension of:
http://www.html5canvastutorials.com/tutorials/html5-canvas-wrap-text-tutorial/

Support Retina Displays

If you add this lines to MapLabel.prototype.onAdd

canvas.width = 500;
canvas.height = 500;
canvas.style.width = "250px";
canvas.style.height = "250px";

You can support hi-res displays. Otherwise the labels look blurry.

This dependency was not found

js-map-label is already installed why I got that message

This dependency was not found:

  • js-map-label in .//babel-loader/lib!.//vue-loader/lib/selector.js?type=script&index=0&bustCache!./src/views/search/Se
    archMap.vue

To install it, you can run: npm install --save js-map-label

Text doesn't always fit into the canvas

Hi guys,
First of all thanks for implementing this almost the moment where I actually needed it ;)

Unfortunately the canvas seems to be fixed size with a width of 300px. This means, that bigger labels might not fit into the canvas and simply get cut off (no wrapping -.-)

Could we at least have an option to control the width?

Or, as I fixed it for now, set the canvas.width to 1000px. For labels which are centered, the works just fine.

Thanks
M

What are the differences between git repository and googlecode repository?

It seems that there are differences between git repository (this) and googlecode repository.

I'd noticed the difference by the difference between the labeled marker object name in both repositories (googlecode repository - MarkerWithLabel, git repository - MapLabel).
Also, there is a difference in the object interaction with the map (googlecode repository - Constructing MarkerWithLabel object instead of google.maps.Marker object, git repository - bind constructed google.maps.Marker object to constructed MapLabel object).

I would really like to know who is the newest and most supported by the contributors, are they providing the same solution to the users marker requirements?

Thank you.

How to remove label from map

I want to remove label from google map same as we remove marker from google map like marker.setMap(null). Thank you.

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.