javascript - Loading specific markers by checkbox? -
I'm loading this marker from a database to display it on a Google map below. It's working fine, But I want to apply the option by pressing on a particular button elsewhere on the page, and then the map will dynamically change to show only clicked markers.
Actually, I would like to filter in my database by the 'type' column, but still keep looing by default in every way. like. Shows page loads, map loads and all types, the user clicks on a button, due to which the map is visible only to the marker, which shows type 1 as value in DB. Like toggle with a check box like
There is no idea to move forward with it, I do not think it is the most effective way to reload markers with DB, should I just hide markers Can I have this property for whom?
Map = New google.maps.Map (document.getElementById ("google_map"), googleMapOptions); // load markers from XML file, check (map_process.php) $ .get ("map_process.php", function (data) {$ (data) .find ("marker"). Each (function () {var name = $ (This) .attr ('name'); var address = '& lt; p & gt;' + $ (this) .attr ('address') + '& lt; / p & gt;' var type = $ (This) .attr ('type'); var Description = '& lt; p & gt;' + $ (this) .attr ('description') + '& lt; / p & gt;'; var points = New google.maps.LatLng (parseFloat ($ (this) .attr ('lat'), parseflot ($ (this) .attr ('lng')) var icon1 = customIcons [type] || {}; Create_marker (point, name, address, false, false, false, icon1.icon); "http://sanwebe.com/assets/google-map-save-markers-db/icons/pin_blue.png");}) ;});
You can not hide certain markers according to your tag or type, you can Hide them / delete them first and then add people you need on your map
Here are the functions you need:
all_markers = []; Var show_markers = []; Function set marker (map) {for (var i = 0; i & lt; show_markers.length; i ++) {show_markers [i] .setMap (map); }} Show show markers (type) {set markers (null); Show_markers = [] for (var i = 0; i & lt; all_markers.length; i ++) {if (all_markers [i]. Type == type) {show_markers.push (all_markers [i])}} setMarkers (Map); }
This idea is: Load all your markers in all_makers
, markers should be equal to the first shipments of show_markers
All_markers
. To show a specific marker, the button will trigger the showmarkers
function to kill the button, which will clean up your map and only reload the specific person
Comments
Post a Comment