Coder Social home page Coder Social logo

Comments (6)

bamnet avatar bamnet commented on April 28, 2024

It sounds like a component which exposed attributes with the latitude and longitude of the user would be much more reusable, might be worth checking out http://ebidel.github.io/geo-location/components/geo-location/.

from google-map.

MarcusJT avatar MarcusJT commented on April 28, 2024

Hmmmm, yes... geo-location component handles the querying and one of the examples shows its output plugged directly into the lon/lat parameters of google-map but maybe what's needed is a third component that renders a My Location UI control with three states - disabled + hidden, enabled + one-time My Location update, and enabled + My Location updates. It would also need to display a marker on the map for the enabled states.

Presumably this new "my-location" component would enable/disable the state of geo-location, set the state of geo-location's watchpos parameter, receive lon/lat parameters from geo-location, and add/remove/update a marker on google-map using the lon/lat parameters as needed?

However I don't fully understand how this can be done in such a way that any of the three components could be replaced by an equivalent component (without explicit dependencies/bindings between them) as this seems significantly more complex than just having one component receive parameters from another. Where can I find out more about how multiple components should work together like this? Also since geo-location doesn't have a parameter which stops it firing on load how could this be added without requesting it as a new feature by the developer?

from google-map.

MarcusJT avatar MarcusJT commented on April 28, 2024

Would it be something like this?

<geo-location latitude="{{geo-lat}}" longitude="{{geo-lng}}" disabled="{{my-disabled}}" watchpos="{{geo-watchpos}}"></geo-location>
<google-map>
  <geo-location-control latitude-in="{{geo-lat}}" longitude-in="{{geo-lng}}" latitude-out="{{my-lat}}" longitude-out="{{my-lng}}" disabled-state="{{my-disabled}}" live-updates="{{watchpos}}" ></geo-location-control>
  <google-map-marker latitude="{{my-lat}}" longitude="{{my-lng}}" title="My Location" hidden="{{my-disabled}}"></google-map-marker>
</google-map>

from google-map.

ebidel avatar ebidel commented on April 28, 2024

Definitely reusing components is the way to go. I actually had this exact demo in my IO session: http://polymer-change.appspot.com/#62. The demo is at http://polymer-change.appspot.com/demos/locator.html.

You could easily create a <polymer-element> that wraps this:

<geo-location latitude="{{lat}}" longitude="{{lng}}" watchpos></geo-location>
<google-map latitude="{{lat}}" longitude="{{lng}}" zoom="{{zoom}}">
  <google-map-marker latitude="{{lat}}" longitude="{{lng}}"></google-map-marker>
</google-map>

The <geo-location> element does most of what you want. If you don't want it declared when the page loads, you could dynamically stamp it:

<template if="{{!disablePos}}">
  <geo-location latitude="{{lat}}" longitude="{{lng}}" watchpos></geo-location>
</template>

from google-map.

MarcusJT avatar MarcusJT commented on April 28, 2024

Ah! I watched your inspiring talk only the other day (one of the reasons I'm now here asking these questions) but totally forgot that you had shown a demo very much like this, thanks for the reminder!

I recall you mentioned stamping in your talk but can't find anything useful about it in the Polymer site let alone an explanation or example of the dynamic stamping you cite.

For instance, in my query above I want to toggle geolocation on and off, so if disablePos toggles false and geo-location is dynamically stamped, does it become unstamped once disablePos toggles true again or is it there for the lifetime of the page, in which case how do I switch it off again?

from google-map.

ebidel avatar ebidel commented on April 28, 2024

I use the term "stamping" to refer to the process of polymer's data-binding system to dynamically create <template> instances (e.g. stamp out instances, mint instances, etc).

if disablePos toggles false and geo-location is dynamically stamped, does it become unstamped once disablePos toggles true again

Yes. The data binding system will remove the node from the the dom. In the case of the geo-location element, if you leave it in the dom, just toggle the watchPos attribute. Toggling that attribute toggles the position watching: https://github.com/ebidel/geo-location/blob/master/geo-location.html#L136

I've filed a bug for doing the same cleanup if the element is removed from the dom: ebidel/geo-location#3

from google-map.

Related Issues (20)

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.