google-map icon indicating copy to clipboard operation
google-map copied to clipboard

Support for GeoJSON

Open surma opened this issue 10 years ago • 10 comments

The Google Maps API has support for GeoJSON. I was wondering, if there’s any interest for having it in the <google-map> component (or if there is a particular reason that it wasn’t implemented).

surma avatar Jun 09 '15 18:06 surma

Can't recall. Probably just a priority issue.

@brendankenny didn't we discuss at some point?

ebidel avatar Jun 09 '15 23:06 ebidel

I think it was a matter of element architecture. I think there was an idea for GeoJSON child elements or something? I wasn't a fan of that one, personally, but I think this should absolutely be supported. If you have geographical data these days, odds are it's already in GeoJSON.

I think whatever the solution ends up being it should map as simply as possible to the Data Layer. Right now it's trivial to add GeoJSON to a <google-map> element: you can just go mapElement. map.data.loadGeoJson('https://somegeojsonurl.json');.

That could easily be exposed via an attribute or something, but you're left with questions about how to add more than one GeoJSON file to a single map (common occurrence) and removing the features from the map if the bound URL changed (probably less common).

Syling is a harder problem. Simple JSON-based styling is available, but note that the more useful general styling, while still declarative, is not valid JSON and has to be executed.

brendankenny avatar Jun 10 '15 00:06 brendankenny

That's right. The discussion was around supporting this feature as a child element...which I also don't think is the right way to go.

I can see easily adding a src or geo-json-src attribute to pass a URL. Basic geo json first.

ebidel avatar Jun 10 '15 03:06 ebidel

PR was submitted for this a while back: https://github.com/GoogleWebComponents/google-map/pull/87

ebidel avatar Jun 15 '15 16:06 ebidel

I’ll gladly take a look a look/a part once I’m at peace with my current project

surma avatar Jun 15 '15 16:06 surma

My take: Every <google-map> has <google-map-data> object, exposed as property called 'data'.

<google-map-data> is a wrapper for google.maps.Data class. It exposes raw data, and provides convenience methods for loading geoJson, etc.

Hypothetical multiple geoJson example:

google-map-data
  property: {
    geoJsonUrls: {
      type: object
      observer: _geoJChanged
    }
  }

 _geoJChanged: function {
    syncs already loaded geoJsons and geoJsonUrls.        
}

atotic avatar Jun 15 '15 21:06 atotic

sounds like a behavior would be good for this. It could contain useful properties and methods for working with data.

ebidel avatar Jun 15 '15 21:06 ebidel

You'd end up with <google-map> with a very large list of methods.

This architecture keeps us in sync with Maps API. They also separate data and the Map. They could have kept it together. For example, data has contains() method. Having that method on a Map would be confusing.

atotic avatar Jun 15 '15 21:06 atotic

Good point. We should consider this an opt-in somehow. The vast majority of people won't use these advanced features. <google-map> is already fairly large as is.

ebidel avatar Jun 15 '15 21:06 ebidel

any update to this?

jparish3 avatar Sep 06 '17 01:09 jparish3