Code Monkey home page Code Monkey logo

px-map's Introduction

px-map Build Status

See demos and API documentation on the Predix UI website.

Overview

px-map is a lightweight framework for building interactive maps with web components and Polymer. The framework includes a base mapping component (<px-map>) that can be used with many different subcomponents to solve common mapping UI problems, like plotting geographic data.

Usage

Example: Basic map

Below is a simple example with little configuration that will display a map centered on Tokyo, Japan:

<px-map lat="35.6895" lng="139.6917" zoom="12" style="width: 500px; height: 300px;">
  <px-map-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"></px-map-tile-layer>
  <px-map-control-zoom position="bottomright"></px-map-control-zoom>
</px-map>

This example uses the <px-map> base component to draw a map and center it on a specific location when it first loads.

If we stopped there and didn't add any subcomponents, the map would load, draw itself, and center on Tokyo, but we would only see a gray background. The map needs a base layer — some underlying imagery that shows road networks or satellite imagery or terrain information. In this example, we use the <px-map-tile-layer> subcomponent to load imagery from an OpenStreetMap tile layer service showing the road network and other points of interest.

Finally, we use the <px-map-control-zoom> subcomponent to add a zoom control that lets the user click or tap buttons to zoom in and out of the map.

Example: Visualizing geospatial data

Plotting geospatial data on the map is easy — just choose the right subcomponent to show the information you have. For example, we can plot two points-of-interest in Tokyo using static markers:

<px-map fit-to-markers style="width: 500px; height: 300px;">
  <px-map-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"></px-map-tile-layer>
  <px-map-control-zoom position="bottomright"></px-map-control-zoom>

  <px-map-layer-group name="Landmarks">
    <px-map-marker-static lat="35.6763976" lng="35.6763976">
      <px-map-popup-info title="Meiji Jingu" description="Shinto shrine dedicated to the Emperor Meiji and Empress Shoken."></px-map-popup-info>
    </px-map-marker-static>
    <px-map-marker-static lat="35.6654861" lng="139.7706668">
      <px-map-popup-info title="Tsukiji Market" description="Sprawling wholesale fish market with an array of seafood & viewing areas for a popular tuna auction."></px-map-popup-info>
    </px-map-marker-static>
  </px-map-layer-group>
</px-map>

This example sets up a <px-map> base component that will automatically set its location and zoom level to fit the markers we added. It adds a basic tile layer (<px-map-tile-layer>) and zoom control (<px-map-zoom-control>).

To plot related points of interest, we use the <px-map-layer-group> and give it a descriptive name. We add markers with geographic data that describes their location using <px-map-marker-static>. To give users more information about each point, we add popups to both markers with the name and description of the place they represent using <px-map-popup-info>.

What you can do with px-map

Out of the box, px-map includes the basic things needed to draw and plot data on an interactive map. It is also extensible — development teams are encouraged to build their own subcomponents that add features needed for their application.

The following components are available:

Base map

  • <px-map>: Draws the underlying map, sets location/zoom and notifies updates when the user interacts with the map, enables and disables interactions, orchestrates subcomponents

Tile layers

  • <px-map-tile-layer>: Calls a tile service API to fetch underlying tile images for the map

Overlay/visualization layers

  • <px-map-layer-group>: Groups related overlays together to allow for bulk interactions (e.g. hide all in the group)
  • <px-map-marker-static>: Creates a marker that shows the state of a point/asset (e.g. with color)
  • <px-map-marker-symbol>: Creates a marker with an icon that shows the state of a point/asset
  • <px-map-marker-locate>: Creates a marker that represents the user's location
  • <px-map-marker-group>: Draws many markers in clusters, useful for visualizing thousands of points that can be dynamically updated

UI components

  • <px-map-popup-info>: Binds a popup that can include text or an image to markers
  • <px-map-popup-data>: Binds a popup that can include text and key/value data to markers

Controls

  • <px-map-control-zoom>: Adds zoom buttons the user can tap to zoom in or out
  • <px-map-control-scale>: Adds a scale that shows the distance of an area on the map in miles/kilometers
  • <px-map-control-locate>: Adds a button the user can tap to locate themselves on the map and center the map on their location

The current major release (v1.X) is focused on providing essential controls, tile layer API support, and on plotting point-based data (e.g. markers) and updating the point data in real time. Support for drawing lines, polygons, and other geospatial data representations hasn't been added to the framework and will require some extensions if needed. New subcomponents will be added over time.

What's under the hood

The current major release of px-map uses the open source Leaflet library to support displaying a map with base tiles and geospatial overlays. Future iterations of the component may offer the ability to use a different library in place of Leaflet, while keeping the same basic API.

Prerequisites

  1. node.js
  2. npm
  3. bower
  4. webcomponents-lite.js polyfill

Node, npm and bower are necessary to install the component and dependencies. webcomponents.js adds support for web components and custom elements to your application.

Getting Started

First, install the component via bower on the command line.

bower install px-map --save

Second, import the component to your application with the following tag in your head.

<link rel="import" href="/bower_components/px-map/px-map.html" />
<link rel="import" href="/bower_components/px-map/px-map-tile-layer.html" />

Finally, use the component in your application:

<px-map lat="35.6895" lng="139.6917" zoom="12">
  <px-map-tile-layer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"></px-map-tile-layer>
</px-map>


Documentation

Read the full API and view the demo here.

The documentation in this repository is supplemental to the official Predix documentation, which is continuously updated and maintained by the Predix documentation team. Go to http://predix.io to see the official Predix documentation.

Local Development

From the component's directory...

$ npm install
$ bower install
$ gulp sass

From the component's directory, to start a local server run:

$ gulp serve

Navigate to the root of that server (e.g. http://localhost:8080/) in a browser to open the API documentation page, with link to the "Demo" / working examples.

GE Coding Style Guide

GE JS Developer's Guide



Known Issues

Please use Github Issues to submit any bugs you might find.

px-map's People

Contributors

dave-fox avatar davidrleonard avatar evanjd avatar hannav95 avatar hanzge avatar karljaxon avatar katemenkhaus avatar mdwragg avatar ollie-sims avatar randyaskin avatar talimarcus avatar williamchang314 avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

px-map's Issues

fit to markers doesn't always fit all the markers.

This could be just unclear requirements, but when fit-to-markers is used as an attribute and also a zoom level is set, looks like the zoom level wins.
Unclear if this is the requirement?

Screenshots:
Initial View on load:

screen shot 2017-03-23 at 1 04 02 pm

Zoomed out one level to find the other marker:

screen shot 2017-03-23 at 1 04 21 pm

Code Snippet:

  <px-map zoom="8" fit-to-markers flex-to-size>

/cc @davidrleonard

stacking order of scale vs. map controls

Stacking order of scale vs. Controls should match the design and be placed at the bottom of the controls. Also unclear if the stacking order is or should be configurable?

Design Screenshot:
screen shot 2017-03-16 at 4 24 57 pm

Current Stacking Order:
screen shot 2017-03-16 at 4 25 10 pm

/cc @davidrleonard

static marker misbehaving when mixed with clusters on the map

Added a static marker with popup to a map with clusters as type important.
At the initial zoom level, the marker shows properly with the popup working fine.

However, when you zoom in, the marker is changed to blue (info) and the popup stops working.

No errors in console log.
Browser: Chrome

Screenshots

Initial

screen shot 2017-03-21 at 4 54 47 pm

Zoomed in one level:

screen shot 2017-03-21 at 4 45 37 pm

/cc @davidrleonard

Popup-info box formatting issues in certain cases

In popup-info, if you just have a title and don’t have a description attribute or the description is not long enough (10+chars), the content is chopped off.

Screenshot:

screen shot 2017-03-22 at 1 31 26 pm

Code Snippet:

<px-map-marker-static lat="37.7016" lng="-121.8909" type="important" show-badge>
              <px-map-popup-info title="Drinks" description="testing"> </px-map-popup-data>
</px-map-marker-static> 

/cc @davidrleonard

Locate control fail state should be more informative

When the location action fails after the user presses the px-map-control-locate button, the following things should happen:

  • The button should be set to the disabled state so it cannot be clicked, with a visual indicator that is disabled
  • A tooltip should show up when the user hovers over the disabled button with text that describes the error causing it to fail

Note: These styles can all be applied by setting them in the class .px-map-control-locate-button--error.

Locate control progress/locating state should be more informative

When the user presses the px-map-control-locate button, some time will elapse between the button click and the location event succeeding (and the map responding to it) while the browser responds to the location request and looks up the location. Progress could be instant or take 10-30s depending on many factors.

After the button is pressed, but before the location is found, the following things should happen:

  • The button should show a progress indicator like a spinner so the user knows the location event is in progress
  • The button should be set to the disabled state so it cannot be clicked, with a visual indicator that it is disabled

When the location is found, the button should return to its initial state (initial icon and non-disabled state).

Note: These styles can all be applied by setting them in the class .px-map-control-locate-button--locating.

Cluster pie slice turns black when icon-type is unknown.

In geojson data file:
If you set the icon-type to an unsupported type, say "alert" or "information", it results in the cluster with a black pie slice. Zooming into the cluster, the marker is rendered as an info marker.

No warnings/errors in console log.

Screenshots:
screen shot 2017-03-16 at 12 29 51 pm

Zoomed into the cluster:
screen shot 2017-03-16 at 12 30 03 pm

/cc @davidrleonard

px-map raising console errors in IE11

This is using IE version 11.0.9600.18617.

When navigating to https://www.predix-ui.com/#/components/px-map/, the map isn't shown. When opening the page with the developer console on (F12), an error is raised:
PxMapBehavior is undefined.

Full snippet:

Polymer({
    is%3A 'px-map'%2C
    behaviors%3A [PxMapBehavior.LeafletRoot]
  })%3B

%2F%2F%23 sourceURL%3Dhttps%3A%2F%2Fwww.predix-ui.com%2Fpx-map%2Fpx-map%2Fpx-map.html.js

Alongside that, the console produces three errors about missing :'s:
Expected ':'
File: px-map-behavior-element.es6.js, Line: 16, Column: 19

File: px-map-behavior-layer.es6.js, Line: 20, Column: 13

File: px-map-behavior-root.es6.js, Line: 66, Column: 12

Instantiating the map on our own app produced the same console errors when loaded in IE11, but none when loaded in Chrome.

Error selecting individual marker in a cluster

Clusters: selecting the individual marker in a cluster:

  • FF: generates a typerror: evt.srcElement.getVisibleMarkers is not a function.
  • Safari: generates a typerror: evt.srcElement is undefined.
  • Chrome: no errors

Zooming out from the individual marker in a cluster, generates the same error as above.

/cc @ppeyro

In IE11, the `px-map-move` event object doesn't have a `getVisibleMarkers` method

When binding a listener to the px-map-move event and normalizing the event with Polymer.dom(e), the rootTarget does not have a getVisibleMarkers method defined.

Example code:

  <script>
    function handleMapMove(evt) {
      var markers = Polymer.dom(evt).rootTarget.getVisibleMarkers();
      console.log('There are ' + markers.length + ' markers visible on the map.');
    }

    var map = document.querySelector('px-map');
    map.addEventListener('px-map-moved', handleMapMove.bind(this));
  </script>

/cc @ppeyro

close-on-control-interact timing issue

Close on control interact doesn't work properly due to a timing issue.
_Map and _maptoAdd are at times undefined causing the interaction to fail by not closing out the popup.

Uncommenting

<script src="../webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="../polymer/polymer-mini.html" />

Will slow it down enough for the close on interact to work.

Screenshot:

screen shot 2017-03-22 at 3 20 16 pm

Layer Picker implementation

This is a tracking issue.
In the original feature ticket, there was a requirement for a
"Layer picker – show/hide base layers and overlay layers"

Should be investigated/implemented?
Marking this issue as a future enhancement.

/cc @davidrleonard

Enable disable-scroll-zoom and disable-touch-zoom in demos.

We should consider adding disable-scroll-zoom or disable-touch-zoom to the demo pages.

It's very easy to activate the cursor on the map and with any slight cursor movement, the demo map starts panning and/or zooming. Also, since most of the demos don't have the control zoom illustrated, to get back to the initial state of the map inthe demo, the whole page has to be refreshed.

"name" attribute doesn't seem to work in marker-locate

Setting the name attribute in marker-locate is supposed to show on hover over the marker but doesn't seem to work.

Code Snippet:

<px-map-marker-locate name="This is You" lat="{{location.lat}}" lng="{{location.lng}}" accuracy="{{location.accuracy}}" ></px-map-marker-locate>

Finish demos and documentation for v1

What needs to happen for each

  • Every subcomponent needs a demo/ page with:
    • Description blurb at top
    • Basic configurable demo with props
  • Every subcomponent needs documentation
    • API description block
    • Usage block
    • Style variables block
  • Every API property needs a description (if possible)

A list of subcomponents to finish

  • px-map-control-info.html
  • px-map-control-locate.html
  • px-map-control-scale.html
  • px-map-control-zoom.html
  • px-map-layer-group.html
  • px-map-marker-group.html
  • px-map-marker-locate.html
  • px-map-marker-static.html
  • px-map-marker-symbol.html
  • px-map-popup-data.html
  • px-map-popup-info.html
  • px-map-tile-layer.html

Final checks

  • Check to make sure all the examples/ are cleaned up, consistent

API doc updates

px-map Updates:

screen shot 2017-03-29 at 10 00 01 am
screen shot 2017-03-29 at 9 54 22 am
screen shot 2017-03-29 at 9 56 08 am
screen shot 2017-03-29 at 10 01 30 am

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-static-marker: And px-map-symbol-marker:

screen shot 2017-03-29 at 10 10 18 am
screen shot 2017-03-29 at 10 11 35 am

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-marker-group

api doc should be updated with more info about:

  • clusterConfig
  • iconFns
  • colorsbytype section looks incomplete

Screenshot:
screen shot 2017-03-27 at 12 22 31 pm

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-marker-locate

screen shot 2017-03-29 at 10 59 19 am

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-popup-info

screen shot 2017-03-29 at 12 31 43 pm

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-control-scale

screen shot 2017-03-29 at 1 01 09 pm

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

px-map-control-locate

screen shot 2017-03-29 at 1 12 20 pm

/cc @davidrleonard

Individual markers inside a marker group should be able to bind popups

Similar to marker binding, px-map-marker-group features should be able to bind popups.

A feature in a feature collection with a bound marker and popup would be set up like this:

    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          "-117.24042573",
          "32.67445793"
        ]
      },
      "properties": {
        "title": "Cabrillo National Monument",
        "marker-icon": {
          "icon-base": "static-icon",
          "icon-type": "warning",
          "icon-with-badge": true
        },
        "marker-popup" : {
          "popup-base": "info-popup",
          "popup-title": "Cabrillo National Monument",
          "popup-description" : "Lorem ipsum dot sit amet, colloquas..."
        }
      },
      "id": "10001"
    },

Popups should only be bound to individual markers, not to marker clusters.

Marker group clusters should have a "show only [x state] color"

Marker clusters should be configured to draw with the following color options:

  • Show all colors in a donut pie chart, each pie arc should be relative to the # of that color group in the cluster
  • Show the dominant color in the cluster (i.e. show the color of the largest color group of markers)
  • Show a specific color if it exists in the cluster (i.e. if ANY important red color group markers exist, show that color to alert about the cluster)

Stacked controls should expose a method/attribute to allow for dynamic ordering

See #29 for the precursor to this request.

Right now, controls are stacked in the same position in reverse DOM order automatically. If it seems useful for developers, we should expose an explicit order attribute or some other way to allow developers to dynamically re-stack controls on the map without detaching and re-attaching them.

Cluster errors in IE

Clusters: IE: getting a second script error (in addition to the above) about object not supporting 'getVisibleMarkers'

/cc @ppeyro

px-control-locate's attribute "move-max-zoom" doesn't set the max zoom level.

In px-control-locate, if move-max-zoom is set to a different zoom value, it doesn't make any difference on the zoom level. It seems locate always defaults to the highest zoom level.

Screenshot:
screen shot 2017-03-28 at 2 49 27 pm

Code Snippet:

<px-map-control-locate
              position="bottomright"
              move-to-location
              last-found-location={{location}}
              move-max-zoom = "6"
              on-px-map-control-locate-error="handleerror"
            >
          </px-map-control-locate>

/cc @davidrleonard

Zooming in/out a few consecutive times causes an error.

This is in all 3 browsers(chrome,ff, safari) although easier to reproduce in safari and FF.
Started noticing this on a map with multiple markers, but stripped those out and now even on a simple map with no markers, if you start zooming out/in using the controls 3 times in a row after the map loads, you get an image corrupt/truncated error in the log. Also, when this happens one or 2 tiles might go missing but most times the image tiles stay intact.

Screenshot:
screen shot 2017-03-16 at 4 52 23 pm

/cc @davidrleonard

Proper handling of multiple markers/popups at the same location.

In a situation where there are multiple markers/popups at the same lat+lng coordinates, only the last/top marker/popup is viewable and all other markers/popups are completely hidden.

Should the popups & static markers be stacked or tagged or in some way identified to have multiple items underneath them?

Screenshot:

2 ovelaid markers+popups/only the second one is visible:

screen shot 2017-03-17 at 1 00 56 pm

/cc @davidrleonard

locate doesn't seem to work.

Locate doesn't seem to locate the location in the latest pull.

You can properly add the locate control to the map, but it doesn't seem to be functional. Selecting the icon indicates it's trying to locate(turning to disable momentarily), but then the icon turns back to blue but the location is not pinpointed.
No errors in console log either.
This is on all browsers.

screen shot 2017-03-21 at 3 15 03 pm

/cc @davidrleonard

Fix syntax checks for zoom-in-text/ locate-text to accept both single and double quotes.

In control-zoom: zoom-in-text will work if the string is enclosed in single quotes and not in double quotes.
In control-locate: it's the reverse, the same syntax won't work unless the string is in double quotes.

Code Snippet:

<px-map-control-zoom position="bottomleft" zoom-in-title ="Zoom it on me" zoom-in-text='<i class="fa fa-briefcase"></i>'></px-map-control-zoom>

<px-map-control-locate position="bottomright" locate-title="Locate Me" locate-text="<i class='fa fa-briefcase'></i>"></px-map-control-locate>

/cc @davidrleonard

Remove the `showBadge` feature from static markers

To reduce complexity and better match our design system, we should remove the showBadge attribute from all markers.

Instead, type warning and info markers should always show a badge. Other marker types should never show a badge.

This will require some non-trivial changes to the icon constructors (StaticIcon, SymbolIcon, etc.) and to the components that implement them (px-map-marker-static, px-map-marker-symbol, and px-map-marker-group which also uses it).

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.