astuder / lightroom-map-fix

Fixing the Map module in Lightroom Classic
125 stars 17 forks source link

Moar map hacks #31

Closed pbb72 closed 4 years ago

pbb72 commented 4 years ago

Okay, here we go, for those who want to push the Lightroom map further.

All replacements are done with patchluastr, as documented in the readme.

StreetView

This is quite radical; if we enable StreetView, then we can see our map pins in 3-D! It's not very precise, but it's just very cool.

Replace var streetViewControlEnabled = with var streetViewControlEnabled = true, dummy =, and replace var streetViewEnabled = with var streetViewEnabled = true, dummy2 =.

There is already code in place in the Lightroom file to enable StreetView, so apparently Adobe has been working on it, but maybe turned it off because it was not good enough.

We can't just replace false with true here, because the values are actually not there in the code, they're inserted at run-time. That is why if we want to force it to true, we need to introduce dummy variables that catch the run-time values.

Capture

Diagonal view

Some locations on earth offer aerial photos with a diagonal view (instead of a top-down view). We can enable this control. (Note: these photos are not very precise.)

Replace rotateControl: false with rotateControl: true.

Extended map selector

I don't think we can add more maps to the map style selector that Lightroom has underneath the map. But luckily Google Maps offers their own map style selector, which we just need to enable:

Replace mapTypeControl: false with mapTypeControl: true

I prefer the selector in the top left corner. (Interestingly, even though the map selector that is included with Google Maps was disabled, it is still configured in the code to be placed in the bottom.)

Replace google.maps.ControlPosition.BOTTOM with google.maps.ControlPosition.TOP_LEFT

I tend do add lots of custom maps when I get the chance, so a simple button bar will not suffice. I want a pull-down menu to hold my maps. We will add a configuration option to the map.

Replace mapTypeIds: with style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, mapTypeIds:

A few years ago, Google made the controls on the map a lot bigger, so they would be easier to operate with your fingers. But they forgot to increase the width of the pulld-down menu, so any map name longer that 10 characters will not fit. No problem for us, we'll fix that by adding a new CSS rule.

Replace #map_canvas with .gm-style-mtc div { width: 200px } #map_canvas

Now all this work is done, we need to add some extra maps, right? Let's take a simple one, ArcGIS satellite.

Replace darkMapType ); with darkMapType );map.mapTypes.set('ArcgisSat',new google.maps.ImageMapType({ getTileUrl: function(coord,zoom){ return 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/' + zoom + '/' + coord.y + '/' + coord.x;}, tileSize: new google.maps.Size(256,256), name: 'ArcGIS sat', maxZoom: 20 })); to configure the map.

And replace TERRAIN, with TERRAIN, 'ArcgisSat', to add the map to our menu.

Clipboard Image (6)

pbb72 commented 4 years ago

I want to extend my greatest thanks to @astuder for making all this possible!

astuder commented 4 years ago

Haha :) Great hacking!

limex commented 4 years ago

@pbb72 : This is great! Will try this soon!

limex commented 4 years ago

@pbb72 If I got this right, than adding Openstreetmap in addition to adding ArcgisSat would be? ....

Replace darkMapType ); with darkMapType );map.mapTypes.set('ArcgisSat',new google.maps.ImageMapType({ getTileUrl: function(coord,zoom){ return 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/' + zoom + '/' + coord.y + '/' + coord.x;}, tileSize: new google.maps.Size(256,256), name: 'ArcGIS sat', maxZoom: 20 })); map.mapTypes.set('OpenStreetMap',new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { var tilesPerGlobe = 1 << zoom; var x = coord.x % tilesPerGlobe; if (x < 0) { x = tilesPerGlobe+x; } return 'https://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'; }, tileSize: new google.maps.Size(256, 256), name: 'OpenStreetMap', maxZoom: 19 }));to configure the map.

And replace TERRAIN, with TERRAIN, 'ArcgisSat','OpenstreetMap', to add the map to our menu.

pbb72 commented 4 years ago

That looks about right (haven't tested, just looked at your code). However, I would split it up, because it can get tedious to just make the command longer for every map you want to add.

Instead of replacing "x" with "xyz" (where "x" is the old code, and "y" and "z" are the code for additional maps) you could do two replacements: first "x" with "xy" and then "x" with "xz", the result of this is "xzy".

The additional benefit is that you can test the results halfway. Did it work with "xy"? Then you can continue on with "xz".

Hope this was at all understandable. 😁

limex commented 4 years ago

@pbb72 copy that. Agile Approach. Not Waterfall. :)

astuder commented 4 years ago

Providing the patch information in the command line is getting unwieldy. I plan to support text files to describe patches.

Peter-MI commented 4 years ago

Prima Idee, Danke!

On 21. May 2020, at 17:43, Adrian Studer notifications@github.com wrote:

 Providing the patch information in the command line is getting unwieldy. I plan to support text files to describe patches.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

astuder commented 4 years ago

Haven't tested it for real yet. But for the adventurous find attached an updated script that supports patch files.

patchluastr-new.zip

Usage:

patchluastr.py -p file.patch

The patch file format is:

[section name]
# comments
in=infile1
out=outfile1
# the string we search for
< nature
# the string we replace with
> street
# supports multiple patches per section
< google
> osm
# and multiple lines as replacement, will generate newline in output
< magic
> multi line 
> replacement

[another patch section]
# patch multiple Lua files with one patch file
in=anotherfile
# like in command line mode, fallback is to append `.patched` for the output filename
> moar
< patching
# ...
astuder commented 4 years ago

Re the extended map selector: I get duplicate entries for Dark at the bottom of the menu. Any ideas what I'm doing wrong?

image

# Enable map selector control
< mapTypeControl: false
> mapTypeControl: true
# Set selector position to top left
< google.maps.ControlPosition.BOTTOM
> google.maps.ControlPosition.TOP_LEFT
# Change control to a drop-down menu
< mapTypeIds:
> style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, mapTypeIds:
# Reduce size of control to be more appropriate for the task
< #map_canvas
> .gm-style-mtc div { width: 200px } #map_canvas

# Add a few custom map types 
< darkMapType );
> darkMapType );
# ArcGIS satellite
> map.mapTypes.set('ArcgisSat',new google.maps.ImageMapType({getTileUrl: function(coord,zoom){ return 'http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/' + zoom + '/' + coord.y + '/' + coord.x;}, tileSize: new google.maps.Size(256,256), name: 'ArcGIS sat', maxZoom: 20 }));
# OpenStreeMap
> map.mapTypes.set('OpenStreetMap',new google.maps.ImageMapType({ getTileUrl: function(coord, zoom) { var tilesPerGlobe = 1 << zoom; var x = coord.x % tilesPerGlobe; if (x < 0) { x = tilesPerGlobe+x; } return 'https://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'; }, tileSize: new google.maps.Size(256, 256), name: 'OpenStreetMap', maxZoom: 19 }));
# and append the custom maps to the drop-down
< TERRAIN,
> TERRAIN, 'ArcgisSat', 'OpenStreetMap',
astuder commented 4 years ago

PS: I have the same issue even when not adding custom map types. The first DARK entry will display the light map. Also, shouldn't there also be an entry for Terrain?

astuder commented 4 years ago

PS2: I merged and pushed the new patchluastr.py and documentation for the new hacks. See folder hacks for patch scripts.

pbb72 commented 4 years ago

Fantastic work on the patch input file support!!

Re the extended map selector: I get duplicate entries for Dark at the bottom of the menu. Any ideas what I'm doing wrong?

You're not doing anything wrong, it's a bug in the Lightroom code. It just doesn't normally show, because Lr doesn't use the Google Maps layer "names".

var styledMapOptions = {
    name: "Dark"
    // Note how they assign the name "Dark" in an object that is not related to 
    // either specific version of the map. That is asking for trouble...
};

// ...

var lightMapType = new google.maps.StyledMapType( lightStyle, styledMapOptions );
var darkMapType = new google.maps.StyledMapType( darkStyle, styledMapOptions );
// Oops there you go, now they're both named "Dark" 

The simple fix will be to replace lightStyle, styledMapOptions with lightStyle, { name: "Light" }.

(The styledMapOptions object is not used for anything else than to contain the name attribute, which Lr doesn't even use. I guess the developers half-way changed how they were going to implement the map in Lr, and forgot to clean up this code.)

Also, shouldn't there also be an entry for Terrain?

That is hidden as an option under the "Map" style. (Just like "Labels" is an option for "Satellite", "Terrain" is an option when you choose "Map".)

astuder commented 4 years ago

That fixed the duplicate entry. Thanks!

Closing this issue as all the hacks are now documented in the Readme.

astuder commented 1 year ago

@pbb72 do you still use LR 6? If so, any thoughts on issue #41 ?