Skip to content

Bring up to date some of my old PRs#125

Open
sandrotosi wants to merge 6 commits intogmplot:masterfrom
sandrotosi:old_prs
Open

Bring up to date some of my old PRs#125
sandrotosi wants to merge 6 commits intogmplot:masterfrom
sandrotosi:old_prs

Conversation

@sandrotosi
Copy link
Copy Markdown
Contributor

They are all related and build on top of each other, hence a single PR; can be re-worked/split if necessary or clarify

Symbols are items like circles or arrows that can be used in other GMap objects,
but only after they have been defined. add_symbol() append a symbol to the
current map symbols list which you can then use in polylines/markers

Reference: https://developers.google.com/maps/documentation/javascript/symbols
the 'icons' parameters of Polyline allows you to add a symbol to the line.

Ref: https://developers.google.com/maps/documentation/javascript/symbols#add_to_polyline
The rename makes more explicit we are writing markers; the addition of a 'name'
optional argument is needed to support the (upcoming) info windows, as they
require to have a unique identifier for the marker they are associated with.
A info window is a marker with a message window associated to it, so that
clicking on the marker, that window is shown.

Ref: https://developers.google.com/maps/documentation/javascript/infowindows
markername = 'infowindow_marker_%i' % i
infowindowname = 'infowindow_%i' % i
self.write_marker(f, lat, lng, color='FF0000', name=markername)
f.write(' var %s = new google.maps.InfoWindow({\n' % infowindowname)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of whitespace indentation here doesn't match the tab indentation used everywhere else in this file. I think we should be consistent and stick to one method of indentation.

If you think it's worth going for whitespace indentation instead of \t, then I suggest creating a separate issue to change all uses of \t into whitespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err, are you sure about this? i dont see any tab (as it's supposed to be for every good python code) so i'm not sure what's going on here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to other lines in this file, like f.write('\t\ttitle: "%s",\n' % title) in function write_marker() above. That line has explicit \t characters that we write to the HTML file, while in write_infowindows() you've added the indentation as actual spaces.

content, lat, lng = infowindow
markername = 'infowindow_marker_%i' % i
infowindowname = 'infowindow_%i' % i
self.write_marker(f, lat, lng, color='FF0000', name=markername)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing title parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm gonna go thru your comments and fix them, just note all the changes are part of a working solution, which i've used in the past to create several maps; they are years old so i'm sure they need updating :)

i'll probably submit an additional commit for the fixes, as rebasing each commit with the fix is gonna be trouble, given all commits are built on top of each other so i'll have to go thru a list of infinite conflicts and merges. If you prefer, i can produce individual PRs for each change (but they will be 1st PR, gets approved and merge, 2nd PR, etc etc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think separating the PRs makes more sense; it'll keep the reviews shorter, but I really don't mind whatever approach you go for (all in one or separate PRs).

infowindowname = 'infowindow_%i' % i
self.write_marker(f, lat, lng, color='FF0000', name=markername)
f.write(' var %s = new google.maps.InfoWindow({\n' % infowindowname)
f.write(" content: %s\n" % content)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%s needs to be in quotes: '%s'


def write_points(self, f):
def write_markers(self, f):
for point in self.points:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also rename all mentions of point and self.points to marker and self.markers.

settings[key] = color

settings["closed"] = kwargs.get("closed", None)
settings["icons"] = kwargs.get("icons", {})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value should be [], not {}, since icons should always represent a list.

The same applies to settings.get('icons', {}) below.

f.write(' new google.maps.LatLng(%f, %f));\n' % self._fitBounds[2:])
f.write('map.fitBounds(rectBounds);\n')

def write_symbols(self, f):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another write_symbols() function already exists in this file; can we extend that function instead of creating a new one here?

(This also means that we call self.write_symbols(f) twice above.)

f.write('\n')
f.write('var %s = {\n' % name)
for k in self._symbols[name]:
f.write(' %s: %s,\n' % (k, self._symbols[name][k]))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second %s needs quotes around it, otherwise any properties that are actually strings will end up as the following in the HTML file:

var goldStar = {
    scale: 1,
    strokeWeight: 14,
    fillColor: yellow, // (error)
    path: M 125,5 155,90 245,90 175,145 200,230 125,180 50,230 75,145 5,90 95,90 z, // (error)
    strokeColor: gold, // (error)
    fillOpacity: 0.8,
};

Comment on lines +243 to +254
def add_symbol(self, name, properties):
"""
add a gmap symbol to the map objects, which can then be used in markers/polylines

name: the variable name (which you will reference in the other objects)
properties: a dictionary with the symbol properties

Ref: https://developers.google.com/maps/documentation/javascript/symbols
"""

self._symbols[name] = properties

Copy link
Copy Markdown
Contributor

@frslm frslm Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my write_symbols() comment below, there already exists an _add_symbol() function; can we also extend that instead of creating a new add_symbol() function?

Same goes for the already-existing self.symbols variable and the new self._symbols variable added here.

Comment on lines +406 to +411
for k in _icons:
# icon argument must not be in quotes
if k == 'icon':
icons += '%s: %s, ' % (k, _icons[k])
else:
icons += "%s: '%s', " % (k, _icons[k])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? If icons is the following...

icons=[
      {
        'icon': 'symbolOne',
        'offset': '0%'
      }, {
        'icon': 'symbolTwo',
        'offset': '50%'
      }, {
        'icon': 'symbolThree',
        'offset': '100%'
      }
    ]

...then k will be the first dict object (not the first key of the first dict object).

It looks like you'll need two loops here, something like:

for icon in _icons:
    # (add `{` to `icons` string)
    for property in icon:
        # (add formatted `property` to `icons` string)
    # (add `}` to `icons` string)

Don't forget to remove the braces ({ and }) from f.write('icons: [{%s}],\n' % icons) below; we've added them in the above for-loop.

Comment on lines +470 to +471
f.write(' new google.maps.LatLng(%f, %f),\n' % self._fitBounds[:2])
f.write(' new google.maps.LatLng(%f, %f));\n' % self._fitBounds[2:])
Copy link
Copy Markdown
Contributor

@frslm frslm Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is flipped; the first value should be the SW point, while the second should be the NE point, as per Google Maps.

@frslm frslm linked an issue Apr 24, 2020 that may be closed by this pull request
@sandrotosi sandrotosi removed their assignment May 18, 2020
@frslm
Copy link
Copy Markdown
Contributor

frslm commented May 23, 2020

Hey @sandrotosi, is this something that you'd still like to work on, or is it free to be picked up? Just asking since you've unassigned yourself.

@sandrotosi
Copy link
Copy Markdown
Contributor Author

it's free to be picked up, thanks!

@frslm frslm removed a link to an issue Jun 1, 2020
@frslm
Copy link
Copy Markdown
Contributor

frslm commented Jun 1, 2020

Here's the state of this PR's changes:

@frslm frslm self-assigned this Jun 7, 2020
@frslm frslm removed the request for review from vgm64 June 7, 2020 19:29
@frslm frslm added the awaiting changes Review waiting on the author for changes. label Jun 7, 2020
@frslm frslm force-pushed the master branch 4 times, most recently from cca6a3a to 0410fbd Compare June 8, 2020 00:10
@frslm frslm force-pushed the master branch 2 times, most recently from cd41a93 to 1c3aef3 Compare June 15, 2020 01:01
@frslm frslm removed the awaiting changes Review waiting on the author for changes. label Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants