Bring up to date some of my old PRs#125
Conversation
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
%s needs to be in quotes: '%s'
|
|
||
| def write_points(self, f): | ||
| def write_markers(self, f): | ||
| for point in self.points: |
There was a problem hiding this comment.
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", {}) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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,
};| 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 | ||
|
|
There was a problem hiding this comment.
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.
| 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]) |
There was a problem hiding this comment.
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.
| f.write(' new google.maps.LatLng(%f, %f),\n' % self._fitBounds[:2]) | ||
| f.write(' new google.maps.LatLng(%f, %f));\n' % self._fitBounds[2:]) |
There was a problem hiding this comment.
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.
|
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. |
|
it's free to be picked up, thanks! |
|
Here's the state of this PR's changes:
|
cca6a3a to
0410fbd
Compare
cd41a93 to
1c3aef3
Compare
They are all related and build on top of each other, hence a single PR; can be re-worked/split if necessary or clarify