I have a Map with custom style and its working great,
I was wondering if I can somehow control the location of the map using some links in my page,
suppose I have 2 locations, I want to have
Location1
&
Location2
Then when I click on Location 1 map goes to that location , and same story for location 2, is it possible with jquery?
It would also be great if I can add a custom marker to each location too.
Thanks.
Yes, you can even do it without jquery, the panto method is what you want to use, https://developers.google.com/maps/documentation/javascript/reference#Map basically, just add a call to a predefined function into your anchor onclick event (or use a click handler in jquery to wire it up).
using jquery, you would need something like:
$("#location1").click(function(){
var pos = new google.maps.LatLng(-25.363882, 131.044922),
g_map.panTo(pos); //reference to globally defined google maps object
});
Here is a simple example from the google api documentation that can easily be retrofitted using the hints I have provided above:
https://google-developers.appspot.com/maps/documentation/javascript/examples/event-simple
if your instance of map is named "map", you can use:
Location1
Related
2 files map plugin -github
I'm above to give up please help... noob here.
Created custom style google map with generated code from googles style map wizard site thing
Followed the instructions and various tutorials, jsfiddles, and all sorts and am just so confused.
I put the code into GitHub so you can see what I'm working with. On my site the scripts.js is inside the folder, (first time on GitHub/new to JS and PHP and can't figure how to move the js file into a folder on GitHub lol)
Have confirmed that All the scripts are loading in the head - YAY
The is loading on my page
The CSS is loading #put-map {height:300px; width:300px;}
But the actual map isn't
API is working from local host (tested static html page with apu and custom style map)
No error in browser just doesn't display the actual map.
Is it the event listener - addDomListener - perhaps something there isnt right - I have no idea.
I am trying to create simple ultra lite base map plugin, that I can just replace style or location code for when I want to use maps, I am relying too much on Elementor sites getting really clunky, so trying to expand my knowledge to be less dependent on visual page builders... REALLY appreciate any offers to help with this,
This is my first js project, I'm guessing I've just missed something small, or am COMPLETELY OFF… Anyway I've only included the JS here, as I'm 95% sure the php is fine, but the link to the whole thing is above
Cheers Ness
jQuery.noConflict();
// JS for Google Map with Custom Style obtained https://mapstyle.withgoogle.com/
// Function to create the map
function initMap() {
// create variable themap and define the element id for use in html ie to be used like: <div id="put-map"></div>
var themap = document.getElementById( 'put-map' );
// create variable mapOptions and define options and information for the map to display
var mapOptions = {
// Generated long and lat from https://www.latlong.net/
center: {
lat: -37.345,
lng: 144.146
},
zoom: 12,
// Disable all the controls https://developers.google.com/maps/documentation/javascript/controls
// in this case i don't want the use to have any options to change the map position or zon in etc.
disableDefaultUI: true,
//******************************************************************************
//
// Custom map visual styling
// Styles applied from wizard https://mapstyle.withgoogle.com/
// - Cut and paste JSON Code from below //**** to above next //****
//******************************************************************************
styles: [
{
"elementType": "geometry",
"stylers": [
{
"color": "#f5f5f5"
}
]
},
more style code is here but cut it to keep it shorter i cut and past from JSON off google between the stars
]
//******************************************************************************
//end of Style part
}; //end of Map Options
// create a new map using the information and options defined in the variables themap and mapOptions
var map = new google.maps.Map( themap, mapOptions );
} //ends function initMap
// Create a DOM event to tell the site to load the createmap function when it finds <div id="mymap"></div> on the web page
google.maps.event.addDomListener( window, 'load', initMap );
Thanks again.
OHHHH SOOO EXCITED I was way overcomplicating it... and I think I had most of the right bits but in the wrong places, I was pretty close. I also think that I might have been updating the script.js file outside my activated plugin so the changes were not actually reflecting on the page - Rookie error eh, either way I've cleaned it all up and its working.
Eventually I found this awesome video hidden amongst all the how to use Google Maps with HTML embed/iframes or how to get an API :( but this video actually shows you step by step Google Maps JavaScript API Tutorial by Traversay Media enough to get the right idea... I only needed the first few minutes as the video goes on to tutorial how to add markers and other fancy features, that i didnt need.
I have a GitHub repository (new to Git too) and in the code I have over commented to explain what (I think) is happening in the PHP/JS, what resources I used to generate bits of code from googles map wizards, where certain variables and names need to be the same and also where you need to make changes. There are no instructions on getting your JavaScript Map API there are plenty of these around.
The plug in consists of 3 very short files, so I'm sure there are different ways of presenting some parts of the code, or some ways of doing it more efficiently, please remember I'm still learning this is my first plugin, first finished bit of real PHP, and very first use of JavaScript
Really happy that I resolved from resources I found myself, was really exciting. I hope this helps others.
GitHub - Googlemap-wp by Vanessa
I have GeoJSON features that consists of many little features. When I hover over one of them, I want the whole layer to be selected and not only a part of my layer.
I don't know where to start to achieve that... anyone can help me ?
This is my code for the moment:
var hoverClick = new ol.interaction.Select({
condition: ol.events.condition.pointerMove,
});
select = hoverClick;
olMap.addInteraction(select);
Thanks
Instead of using an ol.interaction.Select, you could listen to the map pointermove event and use the ol.Map#forEachFeatureAtPixel method. If there's a feature (from your layer) at the location of the pointer, then apply the wanted style to the layer.
I'm currenlty working with OpenLayers and I want to make something similar to a infoWindow.
I read this example : http://openlayers.org/en/v3.11.2/examples/popup.html , but I see it as a "dirty" solution, comparing to the older version of OpenLayers, which had a class for PopUp and you created the object directly in javascript, and I was wondering if there is another solution in the current version.
Thanks in advance
Did you see https://github.com/walkermatt/ol3-popup? It can be as easy as:
var popup = new ol.Overlay.Popup;
map.addOverlay(popup);
// to show something
popup.show(coord, html);
// hiding
popup.hide();
I know how to add a layer with markers, which I can toggle on/off and how to add GeoJSON layer to my map.
But I can't mix these functions.
I need to create a toggling layer from GeoJSON (polyline layer).
Is it possible to get what I need without any external plug-ins or scripts?
GeoJSON Layers and Markers can be used together without problem.
To be able to toggle your layers, you need to catch some sort of click event from something you can click on, for example a button.
From my research what I found is if you need a custom button, it is not so quick to implement yourself, so you might need to use one of the available plugins.
If you still do not want to build a button or use a plugin, you could for example set a click event on the map itself, which toggles the GeoJSON layer on and off.
I took the GeoJSON example from the leaflet website and changed it so it toggles the GeoJSON layer on and off:
var geoLayer = L.geoJson([
// ...
]);
map.on('click', function() {
if(map.hasLayer(geoLayer)) {
map.removeLayer(geoLayer);
} else {
map.addLayer(geoLayer);
}
});
Hope that helps..
Edit:
I changed the example to use the layer control of leaflet.js
which is much better...
var baseLayers = {
"Markers": markerLayer,
"GeoJSON": geoLayer
};
L.control.layers(baseLayers).addTo(map);
Didn't know about this ;)
If you want checkboxes instead of radiobuttons, use this instead
L.control.layers(null, baseLayers).addTo(map);
http://codepen.io/anon/pen/qEaEBg
I'm using the Google Maps v3 library, with the Multi-Marker library which extends the functionality of Google Maps for super fast adding of map marker icons to a map.
I can't figure out how to remove a single, individual map marker using the multi-marker library linked above.
Does anyone have any ideas how I'd do this using the multi-marker library (and/or Google Maps)? I've tried contacting the lead developer of the project but am not getting a response.
Thanks for any help.
Also, linked is more information on this library
http://blog.redfin.com/devblog/2010/07/introducing_multimarker_the_fastest_way_to_add_many_hundreds_or_thousands_of_markers_on_google_maps.html
UPDATE:
I have linked example code of what I'm doing. I want to dynamically remove specific map marker icons (overlays) but am struggling on how to do that. Any advise would be very appreciated. Thanks
Live example:
http://multimarker.googlecode.com/svn/trunk/fast-marker-overlay/maps-v3/example/clickable.html
Normaly, using only the google maps api, to remove an overlay from the map you would need to call the setMap(null) method on the overlay.
As I can see, the Multi-Marker library uses an array to hold all the markers and creates an overlay to show on the map, an overlay that contains the markers. To remove one, it should work to remove the marker from the array (you need to know its position in the array) and redraw the overlay.
Edit:
You need something similar to function clearOverlays() { var i = overlays.length; while (i--) { var overlay = overlays[i]; if (overlay) overlay.setMap(null); delete overlays[i]; } }
But you'll need to know the position in the array of the marker you want to delete. The function will look like this:
function clearOneOverlay(var position) { var overlay = overlays[position]; if (overlay) overlay.setMap(null); delete overlays[position]; }
try this: remember which marker you click and then remove it later
consider following code(Google Maps v2)
var current_marker;
GEvent.addListener(marker, "click", function() {
current_marker = marker;
});
//remove later
current_marker.setMap(null);