Home › Forums › MapPress Support › Add pois via javascript
Tagged: javascript, pois
- This topic has 9 replies, 2 voices, and was last updated 5 years ago by
Chris.
-
AuthorPosts
-
November 17, 2018 at 11:11 am #18070
nbdr
ParticipantHi 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,
CameronNovember 17, 2018 at 11:11 am #18071nbdr
ParticipantWell 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);
November 17, 2018 at 11:11 am #18072nbdr
ParticipantOk, so the next question: Is there way to do this in bulk?
November 17, 2018 at 11:17 am #18075Chris
KeymasterHi,
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’.
November 17, 2018 at 11:23 am #18076Chris
KeymasterSorry – 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"]
November 18, 2018 at 1:40 pm #18077nbdr
ParticipantThe 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 ?
November 18, 2018 at 1:41 pm #18078nbdr
ParticipantAhhh, 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.
November 18, 2018 at 1:41 pm #18079nbdr
ParticipantOk, changing the center is easy enough:
mapp0.center.lat = xxxx; mapp0.center.lng = xxxx; mapp0.recenter();
Now to play with mashups some more…
November 18, 2018 at 1:41 pm #18080nbdr
ParticipantHow can I generate a mashup map from php?
November 18, 2018 at 1:42 pm #18081Chris
KeymasterThere’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?
November 20, 2018 at 3:38 am #18082nbdr
ParticipantBecause 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.
-
AuthorPosts
- You must be logged in to reply to this topic.