Coder Social home page Coder Social logo

ember-g-map's Introduction

Ember-g-map Build Status Ember Observer Score Coverage Status Code Climate

An ember-cli add-on for easy integration with Google Maps. Each object displayed on map is inserted via child component, so you can easily declare which marker and when to display on map using {{#if}} and {{#each}} on template level.

Installation

  • ember install ember-g-map

Configuration

You must define the size of the canvas in which the map is displayed. Simply add something similar to this to your styles:

.g-map-canvas {
  width: 600px;
  height: 400px;
}

In case you want to make the google map to have full width and height as the parent div, you can do the following:

.g-map{
  height: 100%;
}
.g-map-canvas {
  width: 100%;
  height: 100%;
}

In config/environment.js you can specify:

  • additional Google Maps libraries to be loaded along with this add-on (check the full list here),
  • optional API key or client ID for your application (additional info could be found here),
  • optional channel,
  • optional version number,
  • optional exclude parameter, which prevents the addon from injecting the google maps api script tag into your app's index.html. This is useful if you need a custom strategy for loading the google maps script.
  • optional language for map localization,
  • optional explicit protocol setting.
ENV['g-map'] = {
  exclude: true,
  libraries: ['places', 'geometry'],
  key: 'your-unique-google-map-api-key',
  client: 'gme-your-unique-google-client-id',
  channel: 'my-google-map-api-channel',
  version: '3.26',
  language: 'ru',
  protocol: 'https'
}

Loading Google Maps API In China

The default Google Maps API library does not load in China, if your app needs to work in China you will need to implement a custom loading strategy for the Google Maps API.

Usage

Simple map

{{g-map lat=37.7833 lng=-122.4167 zoom=12}}

Map with custom options

Any custom options (except for center and zoom to avoid conflicts) could be set for Google Map object on creation and updated on change.

{{g-map lat=37.7833 lng=-122.4167 zoom=12 options=customOptions}}

Map with Markers

Mandatory context attribute ties child-elements with the main g-map component. You can also set optional attributes:

  • simple title appearing on hover using title attribute,
  • marker label using label,
  • draggable boolean option,
  • onClick action to track all click events on that marker,
  • onDrag action to track all dragend events on that marker (callback receives new lat and lng in attributes).
  • viewport optional google.maps.LatLngBounds, provides an optimized map viewport for the marker. This is generally provided by the google geocoder
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{g-map-marker context lat=37.7933 lng=-122.4167 onClick=(action "handleClick")}}
  {{g-map-marker context lat=37.7833 lng=-122.4267 onClick="handleClick" title=titleForSecondMarker}}
  {{g-map-marker context lat=37.7733 lng=-122.4067 draggable=true onDrag=(action "handleDrag") label="3" title="Marker #3"}}
{{/g-map}}

Custom Marker Images

You can assign custom images to your markers by pointing the icon attribute to an image file (jpg, png, svg, etc.)

{{g-map-marker context lat=lat lng=lng icon="/assets/images/driver-icon.svg" }}

Complex Marker Icons

You can also create a complex marker icon by defining an icon object and passing it to the icon attribute

myIcon: {
  url: "/assets/images/driver-icon.svg",
  size: new google.maps.Size(30,30),
  scaledSize: new google.maps.Size(20,20),
  anchor: new google.maps.Point(15, 15),
  origin: new google.maps.Point(0, 0),
  labelOrigin: new google.maps.Point(30, 15),
}
{{g-map-marker context lat=lat lng=lng icon=myIcon }}

Map with Info Windows

These Info Windows will be open right after component is rendered and will be closed forever after user closes them. You can specify optional onOpen action to trigger anything you need to when the Info Window opens. The infowindow is passed as the only argument to the onOpen action. You can specify optional onClose action to tear down anything you need when Info Window has been closed by user.

Available options (see details in docs):

  • disableAutoPan,
  • maxWidth,
  • pixelOffset
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{#g-map-infowindow context lat=37.7733 lng=-122.4067}}
    <h1>Info Window with Block</h1>
    <p>Text with {{bound}} variables</p>
    <button {{action "do"}}>Do</button>
  {{/g-map-infowindow}}
  {{g-map-infowindow context lat=37.7733 lng=-122.4067
                     title="Blockless form" message="Plain text."}}
  {{g-map-infowindow context lat=37.7733 lng=-122.4067
                     title="With action set"
                     onOpen="myOnOpenAction"
                     onClose="myOnCloseAction"}}
  {{g-map-infowindow context lat=37.7733 lng=-122.4067
                     title="With closure action set"
                     onOpen=(action "myOnOpenAction")
                     onClose=(action "myOnCloseAction")}}
{{/g-map}}

Map fits to show all initial Markers

markersFitMode attribute overrides lat, lng, zoom settings. markersFitMode value can be one of:

  • 'init' - which will make the map fit the markers on creation.
  • 'live' - which will keep the map keep fitting the markers as they are added, removed or moved.
{{#g-map markersFitMode='live' as |context|}}
  {{g-map-marker context lat=37.7933 lng=-122.4167}}
  {{g-map-marker context lat=37.7833 lng=-122.4267}}
  {{g-map-marker context lat=37.7733 lng=-122.4067}}
{{/g-map}}

Map with Markers and bound Info Windows

Markers can have bound Info Windows activated on click. To properly bind Info Window with Marker you should call g-map-marker in block form and set context of Info Window to the one provided by Marker.

You can optionally setup custom openOn/closeOn events for each Info Window, available options are: click, dblclick, rightclick, mouseover, mouseout. By default openOn is set to click and closeOn is set to null. When openOn and closeOn are the same, Info Window visibility is being toggled by this event.

{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{#g-map-marker context lat=37.7833 lng=-122.4267 as |markerContext|}}
    {{#g-map-infowindow markerContext openOn="mouseover" closeOn="mouseout"}}
      <h2>Bound Info Window</h2>
    {{/g-map-infowindow}}
  {{/g-map-marker}}
  {{#g-map-marker context lat=37.7833 lng=-122.4267 as |markerContext|}}
    {{g-map-infowindow markerContext openOn="click" closeOn="click" title="Blockless form 1"}}
  {{/g-map-marker}}
  {{#g-map-marker context lat=37.7833 lng=-122.4267 as |markerContext|}}
    {{g-map-infowindow markerContext openOn="dblclick" title="Blockless form 2"}}
  {{/g-map-marker}}
{{/g-map}}

Grouped Markers with Info Windows

Additionally you can specify parameter group which ensures that only one Info Window is open at each moment for Markers of each group.

{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}

  {{#g-map-marker context group="cats" lat=37.7833 lng=-122.4167 as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      <h2>Cat #1</h2>
    {{/g-map-infowindow}}
  {{/g-map-marker}}
  {{#g-map-marker context group="cats" lat=37.7433 lng=-122.4467 as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      <h2>Cat #2</h2>
    {{/g-map-infowindow}}
  {{/g-map-marker}}

  {{#g-map-marker context group="dogs" lat=37.7533 lng=-122.4167 as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      <h2>Dog #1</h2>
    {{/g-map-infowindow}}
  {{/g-map-marker}}
  {{#g-map-marker context group="dogs" lat=37.7733 lng=-122.4467 as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      <h2>Dog #2</h2>
    {{/g-map-infowindow}}
  {{/g-map-marker}}
{{/g-map}}

Marker bound to address query

Proxy g-map-address-marker component takes address string as parameter and translates it to lat/lng/viewport under the hood. The viewport is used internally to fit the map and can be passed as optional parameter.

Optional onLocationChange action hook will send you back coordinates of the latest address search result and the raw array of google.maps.places.PlaceResult objects provided by places library.

Other optional parameters are the same as for g-map-marker. Requires places library to be specified in environment.js.

ENV['g-map'] = {
  libraries: ['places']
}
actions: {
  onLocationChangeHandler(lat, lng, results) {
    const { viewport } = results[0].geometry;
    Ember.Logger.log(`lat: ${lat}, lng: ${lng}`);
    Ember.Logger.log(`viewport: ${viewport}`);
    Ember.Logger.debug(results);
  }
}
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{g-map-address-marker context address="San Francisco, Russian Hill"}}
  {{#g-map-address-marker context address="Delft, The Netherlands" as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      Works in block form too.
    {{/g-map-infowindow}}
  {{/g-map-address-marker}}

  {{g-map-address-marker context address=searchedAddress
                         onLocationChange=(action "onLocationChangeHandler")}}
  {{g-map-address-marker context address=anotherSearchedAddress
                         onLocationChange="onLocationChangeHandler"}}
{{/g-map}}

Map with route between 2 locations

Using Google Maps Directions service.

You can optionally set travel mode with travelMode attr:

  • walking
  • bicycling
  • transit
  • driving (default)

You can optionally set following custom polyline options as attributes:

  • strokeColor
  • strokeWeight
  • strokeOpacity
  • zIndex
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{g-map-route context
                travelMode='driving' strokeColor='red'
                originLat=37.7933 originLng=-122.4167
                destinationLat=37.7733 destinationLng=-122.4167}}

  {{g-map-route context
                travelMode='bicycling' strokeColor='blue' zIndex=10
                originLat=37.7933 originLng=-122.4167
                destinationLat=37.7733 destinationLng=-122.4167}}
{{/g-map}}

Route bound to address queries

Proxy g-map-address-route component takes 2 address strings as parameters and translates them to lat/lng pairs under the hood.

Optional onLocationChange action hook will send you back coordinates of the latest address search result and the raw array of google.maps.places.PlaceResult objects provided by places library.

Other optional parameters are the same as for g-map-route. Requires places library to be specified in environment.js.

ENV['g-map'] = {
  libraries: ['places']
}
actions: {
  onLocationChangeHandler(lat, lng, results) {
    Ember.Logger.log(`lat: ${lat}, lng: ${lng}`);
    Ember.Logger.debug(results);
  }
}
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{g-map-address-route context
                        originAddress="Los Angeles, California"
                        destinationAddress="San Francisco, California"}}

  {{g-map-address-route context
                        originAddress=searchedAddress
                        destinationAddress=anotherSearchedAddress
                        onLocationChange=(action "onLocationChangeHandler")}}

  {{g-map-address-route context
                        originAddress=searchedAddress
                        destinationAddress=anotherSearchedAddress
                        onLocationChange="onLocationChangeAction"}}
{{/g-map}}

Route with waypoints

You can add optional waypoints to both {{g-map-route}} and {{g-map-address-route}}. Waypoints could be added using {{g-map-route-waypoint}} or {{g-map-route-address-waypoint}} components.

{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{#g-map-address-route context
                         originAddress="Los Angeles, California"
                         destinationAddress="San Francisco, California"
                         as |routeContext|}}
    {{g-map-route-address-waypoint routeContext address="New York City, New York"}}
    {{g-map-route-waypoint routeContext lat=37.7933 lng=-122.4167}}
    {{g-map-route-address-waypoint routeContext address="Dallas, Texas"}}
  {{/g-map-address-route}}
{{/g-map}}

Map with Polylines

You can optionally set following custom polyline options as attributes:

  • strokeColor
  • strokeWeight
  • strokeOpacity
  • zIndex
  • clickable
  • draggable
  • geodesic
  • icons
  • visible
  • path
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{#g-map-polyline context
                    strokeColor="green" strokeWeight="10" strokeOpacity="0.3"
                    geodesic=true draggable=true onDrag=(action "onPolylineDrag") as |coordinateContext|}}
    {{g-map-polyline-coordinate coordinateContext lat=37.7833 lng=-122.4667}}
    {{g-map-polyline-coordinate coordinateContext lat=37.7933 lng=-122.4567}}
    {{g-map-polyline-coordinate coordinateContext lat=37.7933 lng=-122.4667}}
  {{/g-map-polyline}}

  {{g-map-polyline context path=decodedPolyline}}
{{/g-map}}

For both the onClick and onDrag actions, the arguments are event and polyline:

actions: {
  onPolylineDrag(event, polyline) {
    const bounds = new window.google.maps.LatLngBounds();

    polyline.getPath().forEach((e) => bounds.extend(e));
    polyline.map.fitBounds(bounds);
  }
}

Demo

http://asennikov.github.io/ember-g-map/

Planned Features

  • Polygons
  • Google Maps events
  • Better DEMO app

Linting

  • npm run lint:hbs
  • npm run lint:js
  • npm run lint:js -- --fix

Running tests

  • ember test โ€“ Runs the test suite on the current Ember version
  • ember test --server โ€“ Runs the test suite in "watch mode"
  • ember try:each โ€“ Runs the test suite against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

License

This project is licensed under the MIT License.

ember-g-map's People

Contributors

andrewmoore10 avatar asennikov avatar blackening999 avatar bonroyage avatar bschaufler avatar ember-tomster avatar estese avatar gnazarkin avatar hbrysiewicz avatar ivanjolic95 avatar jmccartie avatar mansona avatar mike-north avatar moeabm avatar ofridagan avatar seawatts avatar sebastian-misiewicz avatar sprocketc avatar steveszc avatar superjova avatar thoresuenert avatar wortzel 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

Watchers

 avatar  avatar  avatar

ember-g-map's Issues

Question: Accessing the map context from other components

I need to access the google map object from another component so I can set zoom level and bounds when a user selects a marker from my dropdown component. How can I access the map from another component?

application template:
{{my-map model=items customOptions=customOptions}}

my-map component template:

<div id="floating-panel">
    {{!-- side panel to display information about the marker --}}
    {{side-panel}}
</div>

{{#g-map id="map" options=customOptions class="embed-responsive embed-responsive-4by3"  markersFitMode='live' as |context|}}

    {{#each model as |item index|}}{{item.address.geo.lng}}
        {{#g-map-marker context lat=item.address.geo.lat lng=item.address.geo.lng onClick=(action "handleClick" item context) as |markerContext|}}
        {{/g-map-marker}}
    {{/each}}

{{/g-map}}

<div class="mapMarkerSelector">
    {{!-- dropdown to select markers --}}
    {{marker-selector model=model }}
</div>

Lazily load google map API

In one of my apps, I only need the google maps API on a few pages. It would be great to not pay the overhead of loading the API unless (and until) it's really necessary.

This would entail making a few things "promise aware" because there's the possibility that the google.* stuff hasn't been loaded yet, and will need to be fetched "just in time".

Uncaught Error

I have installed
ember install ember-g-map

In confg/environment

ENV.contentSecurityPolicy = {
'default-src': "'none'",
'script-src': "'self' 'unsafe-eval' *.googleapis.com maps.gstatic.com",
'font-src': "'self' fonts.gstatic.com",
'connect-src': "'self' maps.gstatic.com",
'img-src': "'self' *.googleapis.com maps.gstatic.com csi.gstatic.com data:",
'style-src': "'self' 'unsafe-inline' fonts.googleapis.com maps.gstatic.com assets-cdn.github.com"
};

if (environment === 'production') {
ENV.baseURL = '/ember-g-map';
}

i am using

ember-cli version 2.5.1
npm version 3.9.2
OS Linux Fedora 20

The following error is coming

ember.debug.js:16591 Uncaught Error: Assertion Failed: Must be inside {{#g-map}} component with context set

Complex Marker Icons error

When I implement this
openIcon: {
url: "/assets/images/pin-icon_open.svg",
size: new google.maps.size(30,30),
scaledSize: new google.maps.size(20,20),
anchor: new google.maps.point(15, 15),
origin: new google.maps.point(0, 0),
labelOrigin: new google.maps.point(30, 15)
},

I get Uncaught TypeError: google.maps.size is not a constructor

It seams that I am missing an import...

Making google map height responsive using flexbox

Hello guys, I am trying to make my google map responsive, say, the map fits my div when I resize. Here is what I did:

.flex-container{
    display: flex;
    flex-direction:column;
    height:100%;
}
.g-map-canvas {
    width:100%;
    height: 100%;
}
<div class="flex-container">
    <div style="flex:1" >
      {{#g-map  markersFitMode="init" as |context|}}
      {{/g-map}}
    </div>
    <div style="flex-basis:256px">
       something goes here
    </div>
</div>

But the result is, I see nothing because the <div id="ember589" class="ember-view g-map" > has height = 0.

The problem is fixed when I set the .g-map height = 100%, but that sounds a bit hacky to me, since the way we should set the map should be using g-map-canvas.

Is there any better way to achieve my result rather than this hacky method? Thanks.

Possible to make markers draggable

Hi,

Is it possible to make the markers draggable and get the latitude and longitude when dropped?

Because I prefer this addon over ember-cli-g-maps but I really need draggable markers.

Add polygons

I noticed this was listed on the README as a desired feature request. It also is something that ember-cli-g-maps was covered for. I would like to potentially work on implementing this.

Cap on the number of routes?

First off, thanks so much for your work on this addon, we are loving using it.

I've noticed at most I'm only able to show 3 routes at a time. Is this an imposed limitation? Or am I doing something wrong?

    {{#g-map markersFitMode='live'
             classNames='fde-logistics-planning_gmap'
             options=customOptions as |context|}}
      {{#each driverAllocations as |driverAllocation|}}
          {{g-map-address-route context
                                travelMode='driving'
                                strokeColor=driverAllocation.color
                                strokeWeight=(ternary (eq order selectedOrder) '5' '3')

                                originAddress=order.restaurantLocation.gmapsAddress
                                destinationAddress=order.clientLocation.gmapsAddress
          }}
      {{/each}}
    {{/g-map}}

We've got a paid gmaps key, is it perhaps a question of rate limiting?

What is the correct nesting for g-map-infowindow?

Trying the example template code on the readme section, Marker bound to address query, the browser doesn't seem to like g-map-infowindow being nested in the g-map-address-marker block.
The error in the browser console is,
Uncaught Error: Assertion Failed: Must be inside {{#g-map}} or {{#g-map-marker}} components with context set

g-map-address-route fails in component integration test due to calling set on a destroyed component

Using this component can easily cause a parent component integration test to fail.

This is due to the Places api callback trying to call set on the destroyed component, in this case: g-map-address-route

Just create a bare component, put a gmap inside it and then a g-map-address-route:

{{#g-map
    markersFitMode='live'
    as |context|}}
  {{g-map-address-route context
    originAddress="Some address 1"
    destinationAddress="Some address 2"
  }}
{{/g-map}}

Run the integration test.

This also causes issues when quickly opening and closing a pane which contains one of these, since the component destroys before the places api returns.

Setting default map type

How do I set the map type to satellite by default? I understand there are custom options you can configure, but I'm not sure about its exact location and syntax.

Open info window on 'mouseover'

Thanks for great plugin!

Would be great to open info window on mouse hover... Any ideas if that is possible? I can try submitting a PR, though need some help to start.

No markers, no routes :(

Hello!

I just have tried your awesome library, however I don't see markers nor routes working :(
I tried with example from README.

What I'm doing wrong?

ENV['g-map'] = {
    libraries: ['places', 'geometry', 'visualization', 'drawing'],
    key: '**key'
  }
{{#g-map lat=37.7833 lng=-122.4167 zoom=12 as |context|}}
  {{g-map-marker context lat=37.7933 lng=-122.4167}}
  {{g-map-marker context lat=37.7833 lng=-122.4267 title=titleForSecondMarker}}
  {{g-map-marker context lat=37.7733 lng=-122.4067 label="3" title="Marker #3"}}
{{/g-map}}

Uncaught Error

I have installed
ember install ember-g-map

In confg/environment

ENV.contentSecurityPolicy = {
'default-src': "'none'",
'script-src': "'self' 'unsafe-eval' *.googleapis.com maps.gstatic.com",
'font-src': "'self' fonts.gstatic.com",
'connect-src': "'self' maps.gstatic.com",
'img-src': "'self' *.googleapis.com maps.gstatic.com csi.gstatic.com data:",
'style-src': "'self' 'unsafe-inline' fonts.googleapis.com maps.gstatic.com assets-cdn.github.com"
};

if (environment === 'production') {
ENV.baseURL = '/ember-g-map';
}

i am using

ember-cli version 2.5.1
npm version 3.9.2
OS Linux Fedora 20

The following error is coming

ember.debug.js:16591 Uncaught Error: Assertion Failed: Must be inside {{#g-map}} component with context set

Enhance support for Markers

There are quite a few Marker properties, events, and methods that are present in the Google Maps API but absent from the g-maps-marker component. Its probably not feasible to fully re-implement the Google Maps API for Markers, but the following list seems like a good place to start, and many of these API features such as drag events and opacity are implemented on other components in this addon, such as the g-maps-polyline component.

  • Complex Icon: Currently a url may be provided as a marker's icon property to set a custom marker image, but there is no support for an icon object containing a url, anchor, labelOrigin, origin, scaledSize, or size. Some of these properties may be necessary when using a custom marker image. For instance, a custom marker may need to be anchored to the map in the center of the icon, rather than the default bottom-center. (edit: this is supported but undocumented)
  • animation
  • anchorPoint
  • Opacity
  • draggable/dragStart/drag/dragEnd

Deprecation in Ember 2.1

Hi, I get the following deprecation:

DEPRECATION: The `initialize` method for Application initializer 'register-google' should take only one argument - `App`, an instance of an `Application`. [deprecation id: ember-application.app-initializer-initialize-arguments] See http://emberjs.com/deprecations/v2.x/#toc_initializer-arity for more details.

Do you want me to open a PR for this?

Marker Clustering

I am implementing clustering support using Marker-Clusterer.

I will create a pull request if you are interested. If not, i will publish a separate ember-addon that extends yours.

[Feature request] DrawManager component

I've done some work with the DrawManager with the google maps api directly but think it would be nice to have it emberized within this component. I would potentially like to work on this feature.

Getting the latitude and longitude out of a marker in the map

I'm creating a bit of a make shift search by binding an input field with the address of a {{g-map-address-marker}}

{{paper-input label="Address" value=address}}
{{#g-map markersFitMode='live' zoom=12 as |context|}}
  {{g-map-address-marker context address=address}}
{{/g-map}}

I'm wondering once it is using the right place how do I get the marker details out of the {{g-map-address-marker}} so I can save the lat long on my model and put it in the database?

Route color

While working on #35 I tried to add color option to route component but I couldn't make it work.

I suppose this should be added to rendererOptions for direction renderer in g-map-route component:

let color = this.get('color');
...
polylineOptions: {
  strokeColor: color
}

For some reason it didn't work. Can you please look into it? Thanks!

Populating map from collection

I'm sure I'm missing something simple, but I can't seem to iterate over a collection to populate the map. Here's what I'm trying:

      {{#g-map markersFitMode='init' as |context|}}
        {{#each model as |campground| }}
          {{g-map-marker context lat=campgrond.latitude lng=campground.longitude}}
        {{/each}}
      {{/g-map}}

Map is showing as a blank gray square. Is there another way to loop? I can add some sample code to the README... Thank you!!!

Extending GMapAddressMarkerComponent

Hi,
Ember-noob question I was hoping someone could help me out with. I'm having some trouble figuring how to make an extension. To illustrate, I have a rather staightforward use in my template right now. Just an address marker with an info window with some custom content:

{{#g-map markersFitMode="live" as |context|}}
  {{#g-map-address-marker context address=shop1.address as |markerContext|}}
    {{#g-map-infowindow markerContext}}
      <h5>{{shop1.name}}</h5>
      <p>{{shop1.address}}, {{shop1.postalCode}}, {{shop1.city}}</p>
    {{/g-map-infowindow}}
  {{/g-map-address-marker}}

  {!-- and lots more of such g-map-address-markers but with a different model --}

{{/g-map

Basically I have a whole list of shops/studios/etc on the map, and it would be nice to make a component that just takes a model as the source of the information so I don't have to repeat that code and structure it better. So I make my own component mp-map-location with the following code:

import Ember from 'ember';
import GMapAddressMarkerComponent from 'ember-g-map/components/g-map-address-marker';

export default GMapAddressMarkerComponent.extend({
  address: Ember.computed('location.address', 'location.postalCode', 'location.city', function() {
    this.get('location.address') + ', ' + this.get('location.postalCode') + ', ' + this.get('location.city');
  })
});

And the following template

{{#g-map-infowindow markerContext}}
  <h5>{{location.name}}</h5>
  <p>{{address}}</p>
{{/g-map-infowindow}}

Which I was naively hoping would allow me to simply use the following template code:

{{mp-map-location location=shop}}

Now in the original code there's {{#g-map-address-marker context address=general.address as |markerContext|}} which seems to do some essential context binding, and I'm just clueless on how to ensure that still happens with my extension. It's probably also why currently I get the error:

Uncaught Error: Assertion Failed: Must be inside {{#g-map}} or {{#g-map-marker}} components with context set

Sorry if this is not the best place to ask this but since it seemed pretty specific to this addon architecture. Any help on how to get this started is much appreciated!

Marker as function of address (in addition to lat/long)

Hi!

I was wondering if something like this is possible:

{{g-map-marker context address="Delft, The Netherlands"}}

That would be a more user friendly way of entering a location in a lot of use cases (anything urban).

Thanks so much for making a working Google Maps component! I first stumbled (probably like most) upon https://github.com/huafu/ember-google-map, but sadly seems to have fallen out of maintenance. Perhaps you guys can work together on maturing your component?

Open infowindow programatically

I'm in a situation where I have a sidebar and the map displayed in the main area. I would like to open a given marker infowindow whenever I click in one of the items in the sidebar. Is it possible to create an action that programmatically opens the infowindow of a given marker context?

Advanced marker issue?

I am having an issue using the advanced marker, but I am not sure how to troubleshoot.

Using the standard icon="path/to/img" works fine.

When I use the example of the advanced marker, I know the object is being read on map render, but nothing changes and there are no errors (added a stop in the console inside the object). It feels like I am missing something, Is there an import I need to do in my controller/route?

Im using Ember 2.8

Reference map object from within controller?

Hi there,

Just wondering if you would know how to reference the map object from within a controller?

So I can use code like service = new google.maps.places.PlacesService(map); and map.getBounds()

Many Thanks!

Jacob

Also I am not sure if this is the right place to be asking questions but worth a try

Display Location

I am trying to popup location and near by hospitals in a g-map

image

image

when i click on the submit button on the above form after entering location. The enterd location should be display In the g-map and also display near by hospitals with icon.

i am not getting how to display entered location and hospitals.in a g-map

Make google map have 100% width and height as parent div

Hello guys, I have a div which has dynamic width and height, and the dimensions are determined after the webpage is loaded. In order to make my google map take to full width and height of the div, I need to do the following:

.g-map{
    height:100%;
}
.g-map-canvas {
    width:100%;
    height: 100%;
}

Which is not the mentioned as the readme file. Should we add this into readme file? Or am I using a wrong approach to solve this problem?
Please give me some help on this. Thank you.

resize map when "g-map" box resized

Here is my example code:

<div class="wrapper" style="display: flex">
    <div class="g-map" style="flex: 7"></div>
    <div class="neighbour" style="flex: 0; min-width: 350px">
        <button>hide/show</button>
        {{ other content }}
    </div>
</div>

When i click a button - my neighbour's min-width become "0" and my "g-map" container width grows as it should, but map is needed to resize it to loads over all available space.
How can I call google.maps.event.trigger(map, 'resize'); as recommended by google to resize my map.
Here is my example images:

with opened sidebar:
screen shot 2017-04-17 at 12 11 24

with closed sidebar:
screen shot 2017-04-17 at 12 07 05

All I need is resize this map by code mentioned previously. How can I do it?
(May be you know how to renew map in other way?)

Can I use custom markers?

I'm trying to use markers with custom colors. To do this in my current app (non-Ember), I'm doing this:

function add_marker(item, point) {
  var pinImage = new google.maps.MarkerImage("https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=|" + item.iconcolor,
      new google.maps.Size(21, 34),
      new google.maps.Point(0,0),
      new google.maps.Point(10, 34));

  var marker = new google.maps.Marker({ map: map, position: point, clickable: true, icon: pinImage });
  return marker;
}

This sets a customer marker color. Any way to pass a pinImage when using g-map-marker ?

Move to Data-down, Actions-up architecture

As discussed in #84 there are opportunities to transition to a data-down actions-up architecture from the current architecture that prefers methods as API between components.

Considerations:

  • maintain backwards compatibility
  • account for syncing of state between g-map components and the underlying google.map object
  • account for google.map state management that is shared between g-map components

Cannot get markers to display

Using Ember 2.3.0. The map is showing the right area but I do not see the marker on the map

<div class="col-xs-12 col-md-8">
    {{#g-map lat=40.0403816 lng=-76.2205305 zoom=14 as |context|}}
        {{g-map-marker context lat=37.7933 lng=-122.4167 label="1" title="Locust Grove"}}
    {{/g-map}}
</div>

Now I have not added anything to the environment.js. Not sure if that is the reason

Zoom Level on "Markers bound to address query"

I'm trying to use the Markers bound to address query feature and I would really like the zoom level to stay fixed even when I update the search query

Here is how i'm using it:

{{paper-input label="Address" value=address}}
{{#g-map markersFitMode='live' zoom=12 as |context|}}
  {{g-map-address-marker context address=address}}
{{/g-map}}

I have the address bound to an input but I would really like it to stay at a set zoom level when I search for a new address. What is the best way to do this?

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.