Show route/track on OSM map (GPX or KML)

Phoca Maps - displaying maps in Joomla! CMS
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Show route/track on OSM map (GPX or KML)

Post by rogerco »

Hi Jan,
I'm replacing a wordpress site where I have an OSM plugin that enables me to display a map with a gpx tracklog overlaid in an article.

I've been trying to find out how to do this with PhocaMaps using an OSM base map on the new Joomla3 replacement site (I don't wish to use google maps) but I can't find how to do this.

Any clues please?

PS you can't search for KML or GPX in this forum because it says search terms have to be 4 chars :(

RogerCO

Tags:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Show route/track on OSM map (GPX or KML)

Post by Jan »

Hi, unfortunately, the KML feature only works with Google Maps in Phoca Maps. It is only Google Maps parameter.

Jan
If you find Phoca extensions useful, please support the project
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Re: Show route/track on OSM map (GPX or KML)

Post by rogerco »

Ah, thanks Jan.
Looking in the source code I see (aside from an awful lot of commented out, presumably legacy, blocks :roll: ) that you already have most of the required pieces in place.
You have leaflet.js loaded, and also the leaflet-omnivore plugin which will display both kml and gpx overlays (although I'd prefer to use the leaflet-gpx plugin which I think has some more interesting additional output options).

Indeed on a quick test a one line addition in the relevant helper file (phocamapsosm.php) displays a gpx file ok (hardcoded to the file location)

So 'all' that is needed is to make use of the map kml parameter to hold the gpx filename and probably add a separate function in the helper to add the gpx specifier to $this->output rather than embed it in the renderMap() function.

Probably also add a separate tab and fields in the form for the admin phocamapsmap view for OSM details matching the google specific one with a view to perhaps switching to leaflet-gpx and enabling fitting the map to the selected track, adding some additional info from the gpx (eg date recorded, distance, av speed, elevation gain/loss) and enabling multiple tracks on one map (all of which I would ideally like to have)

I'm guessing that you are actively busy on other components at present (you have a lot on your plate!) so if you are unlikely to get to this fairly soon I'll go ahead and produce a version using leaflet-omnivore for gpx (and maybe kml) on osm for my own us and pass it back to you if you wish.

Having done that I'd add in the use of leaflet-gpx (and possibly leaflet-kml) instead of leaflet-omnivore for displaying tracks on OSM maps.

Roger
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Show route/track on OSM map (GPX or KML)

Post by Jan »

Hi, yes, unfortunately, I am overloaded for now, but yes, if you can modify it, it would be great.

KML File path is stored in map table (`#__phocamaps_map`) under:

`kmlfile` varchar(255) NOT NULL default '',


So you can add another columns like:


`kmlfile_osm` varchar(255) NOT NULL default '',
`gpxfile_osm` varchar(255) NOT NULL default '',

This means, editing following file:

administrator\components\com_phocamaps\install\sql\mysql\install.utf8.sql (adding columns to map table)

Code: Select all

`kmlfile_osm` varchar(255) NOT NULL default '',
`gpxfile_osm` varchar(255) NOT NULL default '',
and adding upgrade file for next version, e.g.:

administrator\components\com_phocamaps\update\sql\mysql\3.0.12.sql

Code: Select all

ALTER TABLE `#__phocamaps_map` ADD COLUMN `kmlfile_osm` varchar(255) NOT NULL default '';
ALTER TABLE `#__phocamaps_map` ADD COLUMN `gpxfile_osm` varchar(255) NOT NULL default '';
Edited XML will be:
administrator\components\com_phocamaps\models\forms\phocamapsmap.xml
(kmlfile parameter can be used as source for both to copy it)

administrator\components\com_phocamaps\views\phocamapsmap\tmpl\edit.php can be edited as following:

add:

Code: Select all

'advanced_osm'		=> JText::_($this->t['l'].'_ADVANCED_SETTINGS_OSM_MAPS'),

Code: Select all

echo $r->startTab('advanced', $tabs['advanced']);
$formArray = array ('kmlfile_osm', 'gpxfile_osm');
echo $r->group($this->form, $formArray);
echo $r->endTab();
So adding this plus language string (COM_PHOCAMAPS_ADVANCED_SETTINGS_OSM_MAPS) will add the new form fields which will store the values to database and this can be used then when rendering the map.
etc.
...

Jan
If you find Phoca extensions useful, please support the project
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Re: Show route/track on OSM map (GPX or KML)

Post by rogerco »

OK, I have a basic version working now using the google kml parameter. I'll modify as you suggest to add separate parameters for osmkml and osmgpx.

The plugin of course also needs a small modification to render the track if it is enabled.

I'd like to be able to store the track files in a different folder rather than defaulting to /phocamapskml (eg in /phocadownload so I can easily upload tracks from the frontend) so if necessary I'll add the ability to specify a path for the file to override the default.

Do you use github? - if so message me the github address and I'll do a proper branch from there (I'm rogercreagh on github), otherwise let me know how best to get the changes to you.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Show route/track on OSM map (GPX or KML)

Post by Jan »

Hi, you can find the projects here:

https://github.com/PhocaCz/PhocaMaps
https://github.com/PhocaCz/PhocaMapsPlugin

As I have specific script to build the component, I can take the modified source and build it on my server as new version (I don't use merge or similar functions as the component is built with specific script but that is no problem I can download your modifications and merge on my server)

/phocamapskml - then maybe the easiest way will be creating new parameter in options for storing the kml/gpx files - the folder path where the phocamapskml will be set as default (so the backward compatibility will be not broken)

Jan
If you find Phoca extensions useful, please support the project
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Re: Show route/track on OSM map (GPX or KML)

Post by rogerco »

OK, here you go:
https://github.com/rogercreagh/PhocaMaps

See https://github.com/rogercreagh/PhocaMap ... s3.0.12.md for a summary of the changes

There are three new fields in the maps table - I've allowed multiple gpx and kml files to be specified for a map - they are entered as a comma separated list in the OSM Advanced tab on the map settings. You can add line breaks between them to make the textarea more readable. Colours for tracks are specified in a separate textarea in the same order as the files. Again comma separated with optional line feeds for legibility.

There is also a fit map to first track option which overrides any coordinates and zoom level set on the general tab for the map.

If no path (relative to site root) is specified with the gpx/kml file then it defaults to /phocamapskml folder, but if you specify a path then that will be used instead. I haven't added an option to set a default folder for now.

I'll do the plugin tomorrow.

For now I'll be using this version on my migrated ex-wordpress site. Since I am not using Google maps at all I'm inclined when I next fancy a side project to produce an OSM only version with some further enhancements and tidying up - and making it 3.10/4.0 compatible - which I think will be a fair chunk of work and it might digress significantly from the existing code base - if I do get round to it you'd be welcome to take it back as a PhocaOSM component if you wish. (I'll develop it separately if I do)

RogerCO
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Show route/track on OSM map (GPX or KML)

Post by Jan »

Hi, please let me know when you ready with the plugin.

I will try to merge the changes and release 3.0.12 Beta for testing. If everything will be OK, I can release stable.

Joomla 4:
I am overwriting extensions step by step for J4, so the same will be with Phoca Maps.

Yes, if you will fork the component for OSM only and improve with new features, will be great. There is no problem to develop both extensions so user can select which one will fit his/her needs more.

Thank you, Jan
If you find Phoca extensions useful, please support the project
rogerco
Phoca Member
Phoca Member
Posts: 47
Joined: 18 Sep 2011, 16:17

Re: Show route/track on OSM map (GPX or KML)

Post by rogerco »

Hi Jan
Plugin is here https://github.com/rogercreagh/PhocaMapsPlugin

Very simple mod - just adding two bits of new code from views/map/view.html.php and tmpl/default.php at lines 537 and 670 in the plugin.
Working ok for me

Cheers
RogerCO
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48402
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Show route/track on OSM map (GPX or KML)

Post by Jan »

Hi, OK, thank you very much, I need to release Phoca Cart and Phoca Gallery now and then I will take a look at Phoca Maps.

Thank you, Jan
If you find Phoca extensions useful, please support the project
Post Reply