Add pois via javascript

Home Forums MapPress Support Add pois via javascript

Tagged: ,

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #18070
    nbdr
    Participant

    Hi Chris,

    I am currently creating a map via PHP, I want to add pois via javascript once the page is loaded. These pois are coming from another plugin, and saved as post meta data. I only want to put pois on the map for the currently viewable area, I have been able to get the current bounds after a move and zoom. Now I just need to know how to add pois after the move or zoom, the poi data will be collected via an ajax call based on the bounds. I don’t mind if pois stay on the map for an area not currently in the bounds.

    I also need to set the centre and zoom via javascript. Hints on this as well please.

    Thank you for your time.

    Kind Regards,
    Cameron

    #18071
    nbdr
    Participant

    Well this worked:

    var newPoi = new mapp.Poi({address: 'Address',body: 'Click Here',iconid: 'green-dot',point: {lat:xx.xxxxx,lng:xxx.xxxxx},title: 'Test',viewport: null});
    mapp0.insertPoi(newPoi);
    #18072
    nbdr
    Participant

    Ok, so the next question: Is there way to do this in bulk?

    #18075
    Chris
    Keymaster

    Hi,

    The javascript code isn’t an API for external use – it’s not documented and subject to change at any time. And it seems like reinventing the wheel – mashups already query based on their bounds, center, set POIs, etc.

    If you want to continue calling the javascript directly, you can use method ‘setPois’ to load POIs in bulk.

    Instead, I’d suggest using filter mappress_query_filter. Set up a mashup with a query like this:
    [mashup query="custom"]

    Then use the filter to set the mashup’s POIs to whatever you like before they are returned from the AJAX call. The call will repeat each time the map is moved. You can see the filter in file ‘mappress_query.php’.

    #18076
    Chris
    Keymaster

    Sorry – one other thought to further simplify this:

    If your external data is stored in custom fields, you can use the MapPress geocoding function to generate a map in each post from those fields. Maps can be bulk generated by publishing multiple posts from the WordPress posts list screen.

    Once the maps are generated, they can be displayed using the mashup tag without any custom code:

    [mashup query="all"]

    #18077
    nbdr
    Participant

    The trouble is, these are not regular posts, they are from a directory plugin, and while they show up as an option for mappress, it’s not something the person creating the listing gets to see as the directory listing form etc is handled by a plugin. Even the plugin doesn’t get map coordinates, I’ve added that in, and it’s automatic geocoding.

    So basically, a map isn’t turned on for the listing. Will a mashup still show the markers for posts which don’t have a map added?

    So if the plugin won’t work under these conditions, my next question is: How do I recenter the map from javascript when given lat/lng ?

    #18078
    nbdr
    Participant

    Ahhh, ok, after reading docs some more, perhaps I can generate the map because the fields for a post have been populated.. Will give that a go.

    #18079
    nbdr
    Participant

    Ok, changing the center is easy enough:

    mapp0.center.lat = xxxx;
    mapp0.center.lng = xxxx;
    mapp0.recenter();

    Now to play with mashups some more…

    #18080
    nbdr
    Participant

    How can I generate a mashup map from php?

    #18081
    Chris
    Keymaster

    There’s an example of creating a map using PHP do_shortocde(), you can do the same for a mashup – but why not just use the shortcode in your post instead?

    #18082
    nbdr
    Participant

    Because I am doing something else which you probably already take care of and I haven’t read about yet. I store the last point in a browser cookie, and restore the map to that point when the person loads the page again.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.