Giter VIP home page Giter VIP logo

react-static-google-map's Introduction

react static google map

build status npm version license Vulnerability status

Overview

Show Google Map static images the React way.

yarn add react-static-google-map
import {
  StaticGoogleMap,
  Marker,
  Path,
} from 'react-static-google-map';

<StaticGoogleMap size="600x600" className="img-fluid" apiKey="YOUR_API_KEY">
  <Marker location="6.4488387,3.5496361" color="blue" label="P" />
</StaticGoogleMap>

<StaticGoogleMap size="600x600" apiKey="YOUR_API_KEY">
  <Marker.Group label="T" color="brown">
    <Marker location="40.737102,-73.990318" />
    <Marker location="40.749825,-73.987963" />
  </Marker.Group>
</StaticGoogleMap>

<StaticGoogleMap size="600x600" apiKey="YOUR_API_KEY">
  <Marker
    location={{ lat: 40.737102, lng: -73.990318 }}
    color="blue"
    label="P"
  />
  <Path
    points={[
      '40.737102,-73.990318',
      '40.749825,-73.987963',
      '40.752946,-73.987384',
      '40.755823,-73.986397',
    ]}
  />
</StaticGoogleMap>

Should render

<img class="img-fluid" src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&markers=size:normal%7Ccolor:blue%7Clabel:P%7C6.4488387,3.5496361&key=YOUR_API_KEY">

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&markers=size:normal%7Ccolor:brown%7Clabel:T%7C40.737102,-73.990318%7C40.749825,-73.987963&key=YOUR_API_KEY">

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&markers=size:normal%7Ccolor:blue%7Clabel:P%7C40.737102,-73.990318&path=weight:5%7C40.737102,-73.990318%7C40.749825,-73.987963%7C40.752946,-73.987384%7C40.755823,-73.986397&key=YOUR_API_KEY">

Documentation

All components must be rendered in the StaticGoogleMap container as children.

Marker Component

import { Marker } from 'react-static-google-map';

The Marker component allows you render markers on the image.

It takes the following props

  • size - (optional) specifies the size of marker from the set {tiny, mid, small}. If no size parameter is set, the marker will appear in its default (normal) size.

  • color - (optional) specifies a 24-bit color (example: color=0xFFFFCC) or a predefined color from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}

  • label - (optional) specifies a single uppercase alphanumeric character from the set {A-Z, 0-9}. Note that default and mid sized markers are the only markers capable of displaying an alphanumeric-character parameter. tiny and small sized markers are not capable of displaying an alphanumeric-character.

  • iconURL - (optional) specifies the icon for the Marker - rather than use Google's marker icons - using a URL (which should be URL-encoded). You can use URLs created by URL-shortening services such as https://goo.gl. Most URL-shortening services have the advantage of automatically encoding URLs.

  • anchor - (optional) sets how the icon is placed in relation to the specified markers locations. By default, the anchor point of a custom icon is the bottom center of the icon image. You can specify a different anchor point using the anchor descriptor in conjunction with your icon. Set the anchor as an x,y point of the icon (such as 10,5), or as a predefined alignment using one of the following values: top, bottom, left, right, center, topleft, topright, bottomleft, or bottomright

  • scale: (optional) useful when using a custom marker iconURL. The scale value is multiplied with the marker image size to produce the actual output size of the marker in pixels. Default scale value is 1; accepted values are 1, 2, and 4. Use marker scaling in conjunction with map scaling when displaying higher-resolution maps.

  • location - (required) defines the marker's location on the map. If the location is off the map, that marker will not appear in the constructed image provided that center and zoom props on the parent are supplied. However, if these props are not supplied, the Google Static Maps API server will automatically construct an image which contains the supplied markers ala Implicit Positioning.

Examples

<StaticGoogleMap
  center="Williamsburg,Brooklyn,NY"
  zoom="13"
  size="400x400"
>
  <Marker color="blue" label="S" location={[11211, 11206, 11222]} />
</StaticGoogleMap>

Would render

<img src="https://maps.googleapis.com/maps/api/staticmap?center=Williamsburg,Brooklyn,NY&zoom=13&size=400x400&markers=color:blue%7Clabel:S%7C11211%7C11206%7C11222&key=YOUR_API_KEY">
<StaticGoogleMap size="600x600">
  <Marker iconURL="https://goo.gl/1oTJ9Y" location="Canberra+ACT" />
  <Marker
    anchor="topleft"
    iconURL="http://tinyurl.com/jrhlvu6"
    location="Melbourne+VIC"
  />
  <Marker
    anchor="32,10"
    iconURL="https://goo.gl/5y3S82"
    location="Melbourne+VIC"
  />
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&markers=size:normal%7Cicon:https://goo.gl/1oTJ9Y%7CCanberra+ACT&markers=size:normal%7Canchor:topleft%7Cicon:http://tinyurl.com/jrhlvu6%7CMelbourne+VIC&markers=size:normal%7Canchor:32,10%7Cicon:https://goo.gl/5y3S82%7CMelbourne+VIC&key=YOUR_API_KEY">

Marker.Group

There is also a Marker.Group component that renders markers with the same style in different locations

This component removes all other props expect location from its children.

<StaticGoogleMap size="600x600">
  <Marker.Group iconURL="https://chart.apis.google.com/chart?chst=d_map_pin_icon%26chld=cafe%257C996600">
    <Marker location="224+West+20th+Street+NY" />
    <Marker location="75+9th+Ave+NY" />
    <Marker location="700+E+9th+St+NY" />
  </Marker.Group>
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&markers=size:normal%7Cicon:https://chart.apis.google.com/chart?chst=d_map_pin_icon%26chld=cafe%257C996600%7C224+West+20th+Street+NY%7C75+9th+Ave+NY%7C700+E+9th+St+NY&key=YOUR_API_KEY">

Path Component

import { Path } from 'react-static-google-map'

The path component allows you render paths on the image

It takes the following props

  • weight - (optional) specifies the thickness of the path in pixels. If no weight parameter is set, the path will appear in its default thickness (5 pixels).
  • color - (optional) specifies a color either as a 24-bit (example: color=0xFFFFCC) or 32-bit hexadecimal value (example: color=0xFFFFCCFF), or from the set {black, brown, green, purple, yellow, blue, gray, orange, red, white}.
  • fillcolor - (optional) indicates both that the path marks off a polygonal area and specifies the fill color to use as an overlay within that area.
  • geodesic - (optional) indicates that the requested path should be interpreted as a geodesic line that follows the curvature of the earth. When false, the path is rendered as a straight line in screen space. Defaults to false.
  • points - (required) In order to draw a path, the path prop must be passed two or more points. The Google Static Maps API will then connect the path along those points, in the specified order.

Examples

<StaticGoogleMap size="600x600">
  <Path
    color="0xff0000ff"
    weight="5"
    points={[
      { lat: 40.737102, lng: -73.990318 },
      '40.749825,-73.987963',
      { lat: 40.752946, lng: -73.987384 },
      { lat: 40.755823, lng: -73.986397 },
    ]}
  />
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&path=color:0xff0000ff%7Cweight:5%7C40.737102,-73.990318%7C40.749825,-73.987963%7C40.752946,-73.987384%7C40.755823,-73.986397&key=YOUR_API_KEY">

You can also render encoded polyline paths

<StaticGoogleMap scale="2" zoom="4" size="600x600">
  <Path
    weight="6"
    points="enc:_fisIp~u%7CU}%7Ca@pytA_~b@hhCyhS~hResU%7C%7Cx@oig@rwg@amUfbjA}f[roaAynd@%7CvXxiAt{ZwdUfbjAewYrqGchH~vXkqnAria@c_o@inc@k{g@i`]o%7CF}vXaj\h`]ovs@?yi_@rcAgtO%7Cj_AyaJren@nzQrst@zuYh`]v%7CGbldEuzd@%7C%7Cx@spD%7CtrAzwP%7Cd_@yiB~vXmlWhdPez\_{Km_`@~re@ew^rcAeu_@zhyByjPrst@ttGren@aeNhoFemKrvdAuvVidPwbVr~j@or@f_z@ftHr{ZlwBrvdAmtHrmT{rOt{Zz}E%7Cc%7C@o%7CLpn~AgfRpxqBfoVz_iAocAhrVjr@rh~@jzKhjp@``NrfQpcHrb^k%7CDh_z@nwB%7Ckb@a{R%7Cyh@uyZ%7CllByuZpzw@wbd@rh~@%7C%7CFhqs@teTztrAupHhyY}t]huf@e%7CFria@o}GfezAkdW%7C}[ocMt_Neq@ren@e~Ika@pgE%7Ci%7CAfiQ%7C`l@uoJrvdAgq@fppAsjGhg`@%7ChQpg{Ai_V%7C%7Cx@mkHhyYsdP%7CxeA~gF%7C}[mv`@t_NitSfjp@c}Mhg`@sbChyYq}e@rwg@atFff}@ghN~zKybk@fl}A}cPftcAite@tmT__Lha@u~DrfQi}MhkSqyWivIumCria@ciO_tHifm@fl}A{rc@fbjAqvg@rrqAcjCf%7Ci@mqJtb^s%7C@fbjA{wDfs`BmvEfqs@umWt_Nwn^pen@qiBr`xAcvMr{Zidg@dtjDkbM%7Cd_@"
  />
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&zoom=4&scale=2&format=png&maptype=roadmap&path=weight:6%7Cenc:_fisIp~u%7CU}%7Ca@pytA_~b@hhCyhS~hResU%7C%7Cx@oig@rwg@amUfbjA}f[roaAynd@%7CvXxiAt{ZwdUfbjAewYrqGchH~vXkqnAria@c_o@inc@k{g@i`]o%7CF}vXaj\h`]ovs@?yi_@rcAgtO%7Cj_AyaJren@nzQrst@zuYh`]v%7CGbldEuzd@%7C%7Cx@spD%7CtrAzwP%7Cd_@yiB~vXmlWhdPez\_{Km_`@~re@ew^rcAeu_@zhyByjPrst@ttGren@aeNhoFemKrvdAuvVidPwbVr~j@or@f_z@ftHr{ZlwBrvdAmtHrmT{rOt{Zz}E%7Cc%7C@o%7CLpn~AgfRpxqBfoVz_iAocAhrVjr@rh~@jzKhjp@``NrfQpcHrb^k%7CDh_z@nwB%7Ckb@a{R%7Cyh@uyZ%7CllByuZpzw@wbd@rh~@%7C%7CFhqs@teTztrAupHhyY}t]huf@e%7CFria@o}GfezAkdW%7C}[ocMt_Neq@ren@e~Ika@pgE%7Ci%7CAfiQ%7C`l@uoJrvdAgq@fppAsjGhg`@%7ChQpg{Ai_V%7C%7Cx@mkHhyYsdP%7CxeA~gF%7C}[mv`@t_NitSfjp@c}Mhg`@sbChyYq}e@rwg@atFff}@ghN~zKybk@fl}A}cPftcAite@tmT__Lha@u~DrfQi}MhkSqyWivIumCria@ciO_tHifm@fl}A{rc@fbjAqvg@rrqAcjCf%7Ci@mqJtb^s%7C@fbjA{wDfs`BmvEfqs@umWt_Nwn^pen@qiBr`xAcvMr{Zidg@dtjDkbM%7Cd_@&key=YOUR_API_KEY">

Path.Group

There is also a Path.Group component that renders different paths with the same style

This component removes all other props expect points from its children.

<StaticGoogleMap size="600x600">
  <Path.Group color="0x00000000" weight="5" fillcolor="0xFFFF0033">
    <Path points="8th+Avenue+%26+34th+St,New+York,NY" />
    <Path points="8th+Avenue+%26+42nd+St,New+York,NY" />
    <Path points="Park+Ave+%26+42nd+St,New+York,NY,NY" />
    <Path points="Park+Ave+%26+34th+St,New+York,NY,NY" />
  </Path.Group>
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x600&scale=1&format=png&maptype=roadmap&path=color:0x00000000%7Cweight:5%7Cfillcolor:0xFFFF0033%7C8th+Avenue+%26+34th+St,New+York,NY%7C8th+Avenue+%26+42nd+St,New+York,NY%7CPark+Ave+%26+42nd+St,New+York,NY,NY%7CPark+Ave+%26+34th+St,New+York,NY,NY&key=YOUR_API_KEY">

Direction Component

import { Direction } from 'react-static-google-map';

This is a syntatic sugar around the Path Component that uses the Google Directions API to render a Path on the map.

This component by default requires that the Google Maps JavaScript Client Side API be loaded.

Add <script src="https://maps.googleapis.com/maps/api/js?key="></script> to your index.html

It takes the following props as well as props from Path Component

  • origin - (required) specifies the start location from which to calculate directions. This value may be specified as a String (for example, "Chicago, IL"), as a LatLng value
  • destination - (required) specifies the end location to which to calculate directions. The options are the same as for the origin field described above.
  • travelMode - (optional) specifies what mode of transport to use when calculating directions. Valid values are driving (Default), bicycling, transit, and WALKING
  • requestStrategy - (optional) A function that takes origin, destination, and travelMode as parameters and returns a string promise of the encoded polyline path to draw on the map.

Also see the cache and onCacheUpdate props on the StaticGoogleMap component.

Examples

<StaticGoogleMap size="600x400">
  <Direction
    origin="6.503296599999999,3.3589658"
    destination="6.6142085,3.3580775000000003"
  />
</StaticGoogleMap>

would render

<img src="https://maps.googleapis.com/maps/api/staticmap?size=600x400&scale=1&format=png&maptype=roadmap&path=weight:5%7Cenc:eduf@i`oSa@pAoAzEc@~A[v@k@j@sA`A]`@{@k@e@OkASkDk@cEs@eG_AoAIk@@qBNw@@WCsEaAmBe@D]RiAhAgFRg@Zm@Z_@r@k@`@_@V_@Rc@|@uFh@eEHm@Fi@BKQAoAUoD}@kCm@iBYK?MBG@{GsAmHcBsDu@aCm@}@Y_Ac@w@e@aBuAwBqBkA}@YMs@[SGu@GwB?kGFoH@eIByOHmKLuPDsH@ui@^_NH}PL{QFqVJ{NLsGDqDFiIAcOJwKFuGD_E?}DI{E]eD_@_Ca@yCo@}C}@yAi@cCcAmDgByCkBkQgLuCmBsNgJwE}CmD}B{ViPsH}EeG_EkHwE{GqEeDuBc@YIi@{AcAYy@AWF[La@RQXMRE`@?d@LZVFNJ^@^Qv@UPe@\e@\iAz@eExCcD|BmCnB_@N]`@Ub@g@`@uA`AsOxKmFvD{EjDeJtGyAfAmBtAV^jCcBnByApBwA|EqDv@i@^Kb@Yh@Yx@URARBNHbArAzAnBj@v@J\GNUTqChBeFvDqCnBmEdCyBlAq@^{JrGeG`EuHpE]RaCtAwExC}OdJaJpFiC|An@nANb@@ZHLZWZOLG\CJBRDRLTVpCjE\l@fAfBbAfBx@pAbBpC|BnD_EhDcG~Ee@[UWi@i@XSKMQa@l@g@QW&key=YOUR_API_KEY">

Static Google Map

  import { StaticGoogleMap } from 'react-static-google-map'

This is the container component all other components should be rendered in.

It takes the following props

  • rootURL: (optional) The root url in which all params will be serialized and appended to. Defaults to https://maps.googleapis.com/maps/api/staticmap.
  • as: (optional) The element for the URL to be rendered in. Defaults to img
  • onGenerate: (optional) function called with the generated image URL
  • size: (required) defines the rectangular dimensions of the map image. This parameter takes a string of the form {horizontal_value}x{vertical_value}. For example, 500x400 defines a map 500 pixels wide by 400 pixels high. Maps smaller than 180 pixels in width will display a reduced-size Google logo. This parameter is affected by the scale parameter; the final output size is the product of the size and scale values.
  • scale: (optional) affects the number of pixels that are returned. scale=2 returns twice as many pixels as scale=1 while retaining the same coverage area and level of detail (i.e. the contents of the map don't change). This is useful when developing for high-resolution displays, or when generating a map for printing. The default value is 1. Accepted values are 2 and 4 (4 is only available to Google Maps APIs Premium Plan customers.)
  • format: (optional) defines the format of the resulting image. By default, the Google Static Maps API creates PNG images. There are several possible formats including GIF, JPEG and PNG types. Which format you use depends on how you intend to present the image. JPEG typically provides greater compression, while GIF and PNG provide greater detail.
  • maptype: (optional) defines the type of map to construct. There are several possible maptype values, including roadmap, satellite, hybrid, and terrain.
  • language: (optional) defines the language to use for display of labels on map tiles. Note that this parameter is only supported for some country tiles; if the specific language requested is not supported for the tile set, then the default language for that tileset will be used.
  • region: (optional) defines the appropriate borders to display, based on geo-political sensitivities. Accepts a region code specified as a two-character ccTLD ('top-level domain') value.
  • visible: (optional) specifies one or more locations that should remain visible on the map, though no markers or other indicators will be displayed. Use this parameter to ensure that certain features or map locations are shown on the Google Static Maps API.
  • style: (optional) defines a custom style to alter the presentation of a specific feature (roads, parks, and other features) of the map. This parameter takes feature and element arguments identifying the features to style, and a set of style operations to apply to the selected features. See Using the DOM style attribute for more information.
  • center: (required if markers not present) defines the center of the map, equidistant from all edges of the map. This parameter takes a location as either a comma-separated {latitude,longitude} pair (e.g. "40.714728,-73.998672") or a string address (e.g. "city hall, new york, ny") identifying a unique location on the face of the earth.
  • zoom: (optional if markers not present) defines the zoom level of the map, which determines the magnification level of the map. This parameter takes a numerical value corresponding to the zoom level of the region desired.
  • apiKey: (optional) allows you to monitor your application's API usage in the Google API Console
  • signature: (recommended) is a digital signature used to verify that any site generating requests using your API key is authorized to do so.
  • client: (optional) By using your client ID (instead of an API key) to authenticate requests, you can: Add the channel parameter to requests so you can view more detailed usage reports.
  • channel: (optional) used to provide additional reporting detail, by grouping different channels separately in your reports. Refer to the Premium Plan Reporting Overview for more information.
  • cache: (optional, default: true) Only used when rendering a Direction component. Because the Direction component is async and will attempt to fetch directions on each render, setting this prop to true will keep an internal cache of requests. This saves calls to the directions service as well as prevents the component from flashing as it fetches new directions. You can also initialize the cache by passing it an object.
  • onCacheUpate: (optional) Only used when rendering a Direction component. This function will be called everytime a new entry is added to the internal cache. It can be used to save the cache to localStorage, for example. This is helpful to intilialize the cache prop from storage.

Using the DOM style attribute

You may have noticed that the style prop is used as a Google param, rather than passed to the <img style={...}>. This is because Google has a style param and this lib aims to have parity with the Google params. If you need to add a style DOM attribute, use the as prop. For example,

<StaticGoogleMap as={props => <img {...props} style={...yourStyles} />}>
  <Marker location="x" />
</StaticGoogleMap>

URL Size Restriction

Google Static Maps API URLs are restricted to 8192 characters in size. In practice, you will probably not have need for URLs longer than this, unless you produce complicated maps with a high number of markers and paths.

License

MIT.

react-static-google-map's People

Contributors

bondz avatar daddywarbucks avatar dashue avatar dependabot[bot] avatar jello10298 avatar mattmccutchen avatar meinstein avatar midnightdesign avatar ocean90 avatar renovate-bot avatar renovate[bot] avatar sators 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

Watchers

 avatar  avatar

react-static-google-map's Issues

How to style my map?

Hi, I'd like to know how to style my map?

I know there is the style= props but I don't understand, when I go on https://mapstyle.withgoogle.com/ to style my map and then export the JSON from there and put in in the style props of my component it doesn't change anything.

Error while using latest version

I have this error when I use your package. It comes from react-promise package.

Cannot find module /node_modules/react-promise/dist/react-promise.cjs.js'. Please verify that the package.json has a valid "main" entry

code: 'MODULE_NOT_FOUND', path: '/node_modules/react-promise/package.json', requestPath: 'react-promise'

Please check this and try to fix it.

Marker iconURL param potentially not working as expected?

Hello!

I have the following code:

 <StaticGoogleMap
      apiKey={process.env.NEXT_PUBLIC_GMAP_API_KEY}
      size="600x480"
      maptype="satellite"
    >
      {field.features.map((feature, index) => {
        if (feature.geometry.type === 'LineString') {
          const coordinates = feature.geometry.coordinates.map(([lng, lat]) => ({ lat, lng }));

          return <Path key={index} weight={3} points={coordinates} />;
        }
        if (feature.geometry.type === 'Point') {
          const [lng, lat] = feature.geometry.coordinates;

          return (
            <Marker
              key={index}
              location={{ lat, lng }}
              anchor="center"
              size="tiny"
              iconURL="https://bit.ly/3zzfT5J" // --------------------> still showing default google pin despite having this in
              scale={0}
            />
          );
        }
      })}
    </StaticGoogleMap>

Even though the iconURL param is there and is a valid shortened image URL I'm still getting the default pin marker.
Looking at the resulting image URL I can see there's no icon query param/url field:

https://maps.googleapis.com/maps/api/staticmap?size=600x480&scale=1&format=png&maptype=satellite&key=AIzaSyBGyEm6p-yJfrl1_yvxm7gGGwcPsSzAKVk&path=weight:3%7C55.96434739875626,-2.645312103197652%7C55.96562429067907,-2.6409330619403493%7C55.96573569535842,-2.6410708639383382%7C55.964407387910754,-2.6454345938619994%7C55.965864238821375,-2.6411780432700116%7C55.964484516686525,-2.645557084527263%7C55.96594993422572,-2.641269911268018%7C55.96458735481619,-2.6457561318569427%7C55.96603562944032,-2.64134646793335%7C55.96471590209266,-2.645939867853897%7C55.966198449824894,-2.6414383359322975%7C55.9648701582618,-2.6460623585182446%7C55.96649838031999,-2.6412086659363276%7C55.96499870459881,-2.6462767171805734%7C55.966592643708815,-2.6413617792669912%7C55.9651272505099,-2.6464910758438944%7C55.96674689239686,-2.641453647264972%7C55.96523865662022,-2.646628877841858%7C55.96683258584652,-2.641545515263004%7C55.96536720173315,-2.6467973025051963%7C55.96692684842229,-2.6416067605956357%7C55.96547003751714,-2.6469351045031604%7C55.96702111076733,-2.6417598739262993%7C55.96559001225142,-2.647103529166524%7C55.96714108069372,-2.6417751852599407%7C55.96568427785414,-2.6471647744991555%7C55.96721820402202,-2.6418517419252727%7C55.96576997365707,-2.6472719538308036%7C55.9673210348859,-2.6419895439222696%7C55.96584709971815,-2.6473791331615097%7C55.967381019430675,-2.642142657252933%7C55.96594136469353,-2.6475016238267735%7C55.967423865476505,-2.642402949915245%7C55.96599278185622,-2.6476547371574375%7C55.9673210348859,-2.643336941231825%7C55.96607847697592,-2.6477159824891277%7C55.96732960411257,-2.6435972338941367%7C55.96616417190585,-2.647869095819766%7C55.967295327195565,-2.644071885219744%7C55.96626700557188,-2.6479609638187394%7C55.96726961948811,-2.6446996498750477%7C55.966361269525414,-2.6480528318167713%7C55.96723534251797,-2.6452202351996705%7C55.96644696382908,-2.648114077149403%7C55.96716678848652,-2.645740820523276%7C55.9665669355345,-2.6480987658157615%7C55.96712394215605,-2.6462767171805734%7C55.9642788396084,-2.645266169198661

At this point I'm not sure if i'm doing something wrong or the iconURL param is being ignored? Help?

Later edit: was looking at the wrong image URL. Sorry for that.

Below is a url that contains the image param (even though I'm still getting the default google marker):

https://maps.googleapis.com/maps/api/staticmap?size=600x480&scale=1&format=png&maptype=satellite&key=AIzaSyBGyEm6p-yJfrl1_yvxm7gGGwcPsSzAKVk&path=weight:3%7C55.96434739875626,-2.645312103197652%7C55.96562429067907,-2.6409330619403493%7C55.96573569535842,-2.6410708639383382%7C55.964407387910754,-2.6454345938619994%7C55.965864238821375,-2.6411780432700116%7C55.964484516686525,-2.645557084527263%7C55.96594993422572,-2.641269911268018%7C55.96458735481619,-2.6457561318569427%7C55.96603562944032,-2.64134646793335%7C55.96471590209266,-2.645939867853897%7C55.966198449824894,-2.6414383359322975%7C55.9648701582618,-2.6460623585182446%7C55.96649838031999,-2.6412086659363276%7C55.96499870459881,-2.6462767171805734%7C55.966592643708815,-2.6413617792669912%7C55.9651272505099,-2.6464910758438944%7C55.96674689239686,-2.641453647264972%7C55.96523865662022,-2.646628877841858%7C55.96683258584652,-2.641545515263004%7C55.96536720173315,-2.6467973025051963%7C55.96692684842229,-2.6416067605956357%7C55.96547003751714,-2.6469351045031604%7C55.96702111076733,-2.6417598739262993%7C55.96559001225142,-2.647103529166524%7C55.96714108069372,-2.6417751852599407%7C55.96568427785414,-2.6471647744991555%7C55.96721820402202,-2.6418517419252727%7C55.96576997365707,-2.6472719538308036%7C55.9673210348859,-2.6419895439222696%7C55.96584709971815,-2.6473791331615097%7C55.967381019430675,-2.642142657252933%7C55.96594136469353,-2.6475016238267735%7C55.967423865476505,-2.642402949915245%7C55.96599278185622,-2.6476547371574375%7C55.9673210348859,-2.643336941231825%7C55.96607847697592,-2.6477159824891277%7C55.96732960411257,-2.6435972338941367%7C55.96616417190585,-2.647869095819766%7C55.967295327195565,-2.644071885219744%7C55.96626700557188,-2.6479609638187394%7C55.96726961948811,-2.6446996498750477%7C55.966361269525414,-2.6480528318167713%7C55.96723534251797,-2.6452202351996705%7C55.96644696382908,-2.648114077149403%7C55.96716678848652,-2.645740820523276%7C55.9665669355345,-2.6480987658157615%7C55.96712394215605,-2.6462767171805734%7C55.9642788396084,-2.645266169198661&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96523618697987,-2.6444917917251587&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96539531609522,-2.6440197229385376&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.9655124106867,-2.6436012983322144&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96563250733553,-2.6431721448898315&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96575260361165,-2.642855644226074&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96586369233521,-2.6426035165786743&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96595076165236,-2.642260193824768&markers=size:tiny%7Canchor:center%7Cicon:https://bit.ly/3zzfT5J%7C55.96604984029219,-2.6420027017593384 

Any idea why this might be?

Bump and publish new NPM version

There has been two new features added:

There have also been some minor version updates on dependencies via renovatebot and dependabot.

There has also been various README updates

  • Include rootUrl property docs
  • remove the actual <img> tags and replace them with markup. Because Google no longer allows free Maps keys, we need to display the markup rather than a broken img.

@bondz We should publish a new NPM version. The current version on NPM is 0.5.2, the current version in package.json is 0.5.1. I believe this is a patch so 0.5.3.

Incorrect types in index.d.ts

I have a static map component in typescript that I'm trying to render but it is complaining that size, color, iconUrl, label and anchor for the marker component are missing even though in the README.md it is specified as optional. Simple changing these props to be optional like this

interface MarkerGroup {
    size?: 'tiny' | 'mid' | 'small' | 'normal';
    color?:
      | 'black'
      | 'brown'
      | 'green'
      | 'purple'
      | 'yellow'
      | 'blue'
      | 'gray'
      | 'orange'
      | 'red'
      | 'white'
      | number;
    iconURL?: string;
    label?: string;
    scale?: '1' | '2' | '4' | 1 | 2 | 4;
    anchor?:
      | 'left'
      | 'right'
      | 'center'
      | 'topleft'
      | 'topright'
      | 'bottomleft'
      | 'bottomright'
      | string;
  }

should fix it.

Issue finding react-promise in 0.5.5

> Build error occurred
Error: Cannot find module 'C:\dev\tattoohq\ui-next\node_modules\react-static-google-map\node_modules\react-promise\dist\react-promise.cjs.js'. Please verify that the package.json has a valid "main" entry
    at tryPackage (internal/modules/cjs/loader.js:319:19)
    at Function.Module._findPath (internal/modules/cjs/loader.js:703:18)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:967:27)
    at Function.Module._load (internal/modules/cjs/loader.js:862:27)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (C:\dev\tattoohq\ui-next\node_modules\react-static-google-map\dist\react-static-google-map.cjs.js:10:29)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32) {
  code: 'MODULE_NOT_FOUND',
  path: 'C:\\dev\\tattoohq\\ui-next\\node_modules\\react-static-google-map\\node_modules\\react-promise\\package.json',
  requestPath: 'react-promise'
}

It seems to be looking for the commonjs version.
The files I have in that folder:

react-promise.es.js
react-promise.js
react-promise.umd.umd.js

My tsconfig

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "experimentalDecorators": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "downlevelIteration": true
  },
  "exclude": [
    "node_modules"
  ],
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ]
}

Using nextjs 9, with the command "next build"

Add a `style` prop to the <img>

The style prop is currently reserved to inform Google Maps of the map style to use.

I would like to add some sort of componentStyle prop that would allow the user to add a style tag to the image such as

<Component { ...componentProps } style={this.props.componentStyle}/>

This is rather easy to do. But I want to be careful of naming conventions. Up to this point, we have not had any prop name clashes except this one. All of the "google props" are not used for the DOM element...except style. I don't really love componetStyle because it's not like we have componentClassname, etc. But it is very straightforward, easy to implement, and backwards compatible.

Any thoughts?

Is there any way I can change the color or mode for map?

I want to show the night mode for static map. So I am not able to figure out any solution for this yet.

Here is my source code:
<StaticGoogleMap scale={4} className="static-map" size="600x200" apiKey="XYZ"> <Marker.Group size={'tiny'}> <Marker location="18.5204,73.8567" /> <Marker location="8.4657,-13.2317" /> <Marker location="38.9072,-77.0369" /> <Marker location="6.3156,10.8074" /> <Marker location="4.4419,15.2663" /> </Marker.Group> </StaticGoogleMap>

Is there any property or styling that I can add here to achieve night mode for map?

react-hot-loader causing issue in rendering of static map

Description - With react-hot-loader, every component is wrapped with ProxyFacade, and thus switch of finding child component like Marker, Direction and matching them with component definition inside library is not happening properly

403 error for signed Static maps API

<StaticGoogleMap size="1000x600" className="img-fluid" apiKey="YOUR APIKEY" signature="Your secret"> <Marker location="6.4488387,3.5496361" color="blue" label="P" /> </StaticGoogleMap>

I was using the example code to render a static google maps image with a signature. But it keeps throwing a 403 error. Is there something I am doing wrong?

Struggling with custom component Marker

Hey I'm trying to use a custom marker component but constantly end up with "Component is not a function".

I've tried looking into the source and it seems the check for whether something is a class is failing on prototype.isReactComponent check and perhaps defaulting to render as a function component?

This is my code:

import { Component, Fragment } from 'react';
import { StaticGoogleMap } from 'react-static-google-map';

import { GoogleMapsKey } from './map';
import { MapType } from './types';

type MarkerProps = {
    inGroup: boolean;
    lat: number;
    lng: number;
    type: MapType;
    filtered: boolean;
    title: string
};

class Marker extends Component<MarkerProps> {
    render() {
        const { inGroup, title, type, filtered } = this.props;

        const className = inGroup
            ? `marker marker--grouped marker--${type}${filtered ? '-filtered' : ''}`
            : `marker marker--ungrouped marker--${type}${filtered ? '-filtered' : ''}`;

        return (
            <div className={className} title={title} >
                <span style={{ textTransform: 'uppercase', transform: `scale(0.55)` }}>{type}</span>
            </div>
        );
    }
}

export class StaticMap extends Component<{ lat: number, lng: number, title: string, type: MapType }> {

    render() {
        const { lat, lng, title, type } = this.props;

        return <Fragment>
            <StaticGoogleMap size='600x600' apiKey={GoogleMapsKey} >
                <Marker inGroup={false} filtered={false} lat={lat} lng={lng} title={title} type={type} />
            </StaticGoogleMap>
            {/*
            <StaticGoogleMap size='600x600'>
                <Marker location='6.4488387,3.5496361' color='blue' label='P' />
            </StaticGoogleMap>
            */}
        </Fragment>;
    }
}

Direction Component with waypoints

I'm trying to utilise the Direction component to render a static image that goes from A -> D via B & C I can see the directions API supports this via the waypoints param but when i pass this to the direction component nothing happens is there a way to get this functionality currently with the Direction component?

Unfortunately i do need the route rather than path so using the path component to handle this is not sufficient

Update README to fix broken images

Since Google Maps moved to a new API key and payment system, it is no longer possible to render images without a key with a payment form associated. This means that the images in the README do not display.

Update the README to just wrap those image tags in backtics to display the code rather than the image itself.

Add <StreetViewGoogleMap /> component

Google supports a streetview image: https://developers.google.com/maps/documentation/streetview/overview

I am currently using this in two projects where I am hardcoding the URL, but I think this could be a nice addition to the library.

<StreetViewGoogleMap
  size="600x600"
  apiKey="***"
  location="6.4488387,3.5496361"
/>

Unlike StaticGoogleMap, I don't think this component has any children. At first, I thought this would be another child component/strategy of StaticGoogleMap but its not. This component has a different rootURL and also cannot be composed with other elements like markers, etc. It is its own "base" component I believe.

Any thoughts?

Markers not appended in Next.js apps

Hi there,
Thank you for this package. It's a breathe of fresh air in the forest of static google map renditions ๐Ÿ‘

I came across what I think is an issue when trying this in a Next.js app. I'm guessing this has to do with SSR:


running yarn dev produces:
screen shot 2018-01-23 at 09 37 51

running yarn build and yarn start (what see in the live version):
screen shot 2018-01-23 at 09 38 56

Looking at the generated image url of the live version you can see that the marker coordinates are not being appended to the url: https://maps.googleapis.com/maps/api/staticmap?size=100x100&scale=1&format=png&maptype=roadmap&key=xxx&

When first running yarn dev and refreshing the browser I get this in the terminal console:

Warning: setState(...): Can only update a mounting component. This usually means you called setState() outside componentWillMount() on the server. This is a no-op.

Please check the code for the Async component.

I wonder if that has something to do with it. Appreciate any help.

Memoize or cache DirectionStrategy

Thanks for the work on this tool! It is really great and I have enjoyed using it, especially alongside react-google-maps, where the component API's are very similar.

I have noticed that whenever a component above a Direction causes a re-render that the Direction component flashes as it is using the Async component under the hood. I have also sussed out that there really is no way to use something like PureCompnent because the components themselves return null and are really just declarative ways of building a strategy which StaticGoogleMap renders as an image (which is really cool, btw).

But there has to be some way to memoize (or otherwise cache) the fetch call to the directions API. Have you thought about or experimented with this at all? I would like to open a PR but wanted to get someone's thoughts on it first.

After a quick look, I think that we could do something in this area:


Perhaps store the JSON.stringify(data) as the key in a Map/object with the result of the promise. And then later check to see if that key exists and if so return the stored path (not as a promise). Then I believe that as per
* All the parts should return a string if a component that does not return a promise isn't used

the StaticGoogleMap will just consume that and return the component instead of the async component.

Any thoughts?

Why are markers required?

First, thanks for this package!

I just want to display a map, centered in a location but I am getting "Component must have `Marker`, `Path` or `Direction` child" error

Google docs says that markers are optional
image

so, why are they required? can we please make them optional?

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.