• Resolved samuel1mclean

    (@samuel1mclean)


    Hello everybody,
    I’m using wordpress to create a database research tool, with a relational database for naval deployment records.

    I’m using Custom pages- where everything put onto the page is in HTML-but it’s created when the page is loaded/echoed so it’s not actually in the “text box” of the page itself.

    as a result, when I put in the shortcode- it just shows up as

    `
    [leaflet-map]
    `
    I was wondering if it’s possible to use the plugin and shortcodes in this manner- obviously what I’m doing doesn’t work- but I’m not sure how to make it work? I don’t want to create one *standard* that shows up every time- basically when the page loads, it grabs a series of locations/lat/long coordinates from the database (and labels), and I run that through a foreach loop and spit out the [leaflet-marker (etc) things.

    So at the moment, they just show up as text in the html.

    also, do I need to put a [/leaflet-map] tag to end the list?

    I very much appreciate your help

Viewing 5 replies - 16 through 20 (of 20 total)
  • Plugin Author bozdoz

    (@bozdoz)

    On whitespace: Sounds like your php is echoing something unintended, or your template is rendering whitespace as paragraphs or breaks (likely). If that is the case, you might be able to solve this with this solution: https://stackoverflow.com/questions/5940854/disable-automatic-formatting-inside-wordpress-shortcodes

    On multiple clustered markers: Yes, you can add a leaflet plugin for marker clustering. It may be more work. Check out “How can I add another leaflet plugin” here: https://github.com/bozdoz/wp-plugin-leaflet-map#how-can-i-add-another-leaflet-plugin

    And the cluster plugin I’d recommend is: https://github.com/Leaflet/Leaflet.markercluster

    Thread Starter samuel1mclean

    (@samuel1mclean)

    *swears* I hate AJAX_ I’ve been trying to use it to do something else (using the medialibrary pop up for something inside the template) and I just hate the damn thing. But if I ever get that solved, I’ll certainly add the clustering plugin.

    I very, very, very much appreciate your help with all of this.

    Thread Starter samuel1mclean

    (@samuel1mclean)

    Hi, I very much appreciate your help-

    I’ve been thinking about how to deal with the overlapping/cluster of markers thing (where I have more than one ship in the same location, in my case). So I came up with something that would stagger markers so you don’t get two in the same place (except, I need to make sure that I don’t have two sets of lat/long that are the same)

    
    if (isset ($loc_tracking[$locs->station_key]))
    {
        if ($loc_tracking[$locs->station_key ][$lat_counter] == 4)
        {
    	$loc_tracking[$locs->station_key ][$lat_counter] = 0;
    	$loc_tracking[$locs->station_key ][$long_counter]++;
        }
        else
        {
    	$loc_tracking[$locs->station_key ][$lat_counter]++;
        }
    }
    else
    {
         $loc_tracking[$ship_line->line_number] = array($latcounter = 0,$longcounter = 0);
    }	
    						
    array_push($map_rows [$ship_line->line_number],($final[0]->location_latitude) + ($loc_tracking[$locs->station_key ][$lat_counter]*.0008));	
    array_push($map_rows [$ship_line->line_number],($final[0]->location_longitude) + ($loc_tracking[$locs->station_key ][$long_counter]*.0008));
    

    I thought I’d share this with you so you can either use it (I mean, I’ve not tested it, so it’s more pseudo than code, but it’s enough to get the gist)

    But anyways, what this does is – track whether a certain location has been used before for a marker- (in an array), and that array has a lat and long tracker for each- so that for each successive use of that location, an amount (in this case, set to roughly .05 nautical miles (as a portion of a degree of latitude- I’ve used the same number for longitude so of course as things get closer to equator, the longitudinal separation will be longer, and closer together as they get closer to the poles). Anyways, the idea is that the ticker will create rows of 5 markers. So it’s not useful for things that need absolute precision- but if people want to show clusters of things and approximation is fine- well then this might be useful to them.

    A much simpler solution would have been to dispense with the arrays etc and just- for every marker, have a random float added (on a value of -.0008 to .0008) to both the lat and long value just as part of the iteration through the array, but that would have a non-0 chance of markers still being on top of each other, so *shrug* I didn’t do that.

    I hope this is useful.

    Thread Starter samuel1mclean

    (@samuel1mclean)

    It wouldn’t let me edit my last post, but here is the code that actually works

    
    if (isset ($loc_tracking[$locs->station_key]))
    						{
    							if ($loc_tracking[$locs->station_key ]['lat_counter'] == 4)
    							{
    								$loc_tracking[$locs->station_key ]['lat_counter'] = 0;
    								$loc_tracking[$locs->station_key ]['long_counter']++;
    							}
    							else
    							{
    								$loc_tracking[$locs->station_key]['lat_counter']++;
    							}
    						}
    						else
    						{
    							$loc_tracking[$locs->station_key] = array('lat_counter' => 0,'long_counter' => 0);
    						}	
    						
    						array_push($map_rows [$ship_line->line_number],($final[0]->location_latitude) + ($loc_tracking[$locs->station_key]['lat_counter']*.0008));	
    						array_push($map_rows [$ship_line->line_number],($final[0]->location_longitude) + ($loc_tracking[$locs->station_key]['long_counter']*.0008));
    
    Plugin Author bozdoz

    (@bozdoz)

    Yeah kind of cool. This kind of touches on an issue that (as far as I know) really hasn’t been solved: markers that are in identical locations. The marker cluster does a pretty good job at minimizing markers that overlap, but doesn’t really address unique markers in identical locations.

    The example I’ve used in the past is a directory of dentists throughout a city: each dental office can have multiple dentists. The solution could be, instead, to have a directory of dental offices, but that might not make sense depending on the implementation or the data. But given that situation, what should be done with the marker, or the popup for the marker? Maybe the marker should become a number, and maybe the popup should be a list of popups. All said, an implementation like that doesn’t exist to my knowledge.

    Anyway, thanks for the feedback. Hope all is well. Open a new issue if you have any more problems.

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Using Leaflet on custom page’ is closed to new replies.