Get existing Google Maps V3 instance? - javascript

I am using a WordPress plugin for a Store Locator, and it does a lot of good things. But there are a few things that I need to tweak and I do not want to modify the plugin's code. I was wondering if there was any way to get ahold of the current map that it outputs and all of its settings so that I could manipulate them, or add to them? I would do this in my own JS file.
The ID of the div that contains the map is #wpsl-gmap and one thing I want to do is after loading the results I need to trigger a resize on the map because the area that it is loaded into increases and the tiles do not load for the new section. I would also like to center the map if possible.

Related

Adding static Directions/Save panel using Google Maps API

I'm trying to add a "static" panel on the top left of my map (like the image below)? I am using google.maps.Marker() to render a marker on the map and upon clicking the Marker the panel should update with the place. I've seen it in several sites, so I'm wondering if it's possible to do using the Maps API. I've tried looking through a bunch of things (including CustomSaveWidget) though it is not the same thing.

arcgis javascript how can i turn off layers

i am doing the tutorial for displaying the map in a web browser
https://developers.arcgis.com/javascript/3/jshelp/intro_agstemplate_amd.html
now I have the code, what if I don't want to display all the layers, and want to turn off the first layer?
i can do it by index of the layer, or can i use the layer name?
trying to understand i got to https://developers.arcgis.com/javascript/3/jsapi/arcgisdynamicmapservicelayer-amd.html but not sure how to use javascript
thanks guys.
If you want to turn off and on layers manually, I would use the layerlist widget script LayerList widget
or if you need the option to reorder the layers with the ability to turn layers on or off manually I would use the Reorder layers in map service

Convert Google Map to static image for download using jQuery

I have a div on my website in which I have created a GoogleMap. I've added markers and implemented MarkerClusterer.
I want to allow the user to click a button and download an image of the currently viewed map as they see it after any zooming or moving including markers:
I tried to use html2canvas and that doesn't work at all.
After searching for how to do this for the last hour, I've come up with absolutely nothing useful.
Is this even possible to capture the div as the user sees it? Or is creating a static google map and saving the image the only way to do this?
SOLUTION
I went with PhantomJS in the end. I created a Map view which takes input through the querystring and uses that data to add markers to a map. I then used PhantomJS to take screenshots from the map view. I then output the screenshot image as a Base64 string.
SnapshotControl is suggested by google in such situations. The limitation is that SnapshotControl supports only URL of upto 2048 characters. So it can be used if there are not much layers drawn on map.
For phantom js, when user clicks on download, the layer data drawn on map should be send to server (through say downloadServlet). This data will be passed to a JSP that can render a map and plot point. Phantomjs will be executed by downloadServlet passing the URL of this jsp.
I have used phantomjs in my application as I draw around 4-5 different layers at a time. Only thing to note here is that the server where phantomjs would be executed needs to have internet connectivity otherwise maps will not be drawn.
Your best solution is Static Google Maps.
See https://developers.google.com/maps/documentation/static-maps/intro for plenty of examples.
Create an image in your div, I would then recommend using concatenation to produce a dynamic url from your marker/LatLng/Polyline etc variables. Then use JS to set the image's src equal to that url.
Following that, there are plenty of JS libraries that will allow the user to download the image.

Google Maps V3, how to get array of markers/overlays?

Now obviously if I was just adding them in a normal fashion I would just keep them in an array along the way but in my case the markers are being loaded in, but I am using a KML layer.
So after the KML loads and the markers show up I basically just want to know how many there are, and I can figure out some dumb hack for this (loading the KML file again with jQuery and counting it there or something), but ideally I just want something like myArray = map.getMarkers() or myArray = map.getOverlays(), does anything like that exist?
It seems such a simple task, not why it is taking me so long to find the answer. Maybe it just isn't possible?
There's no such thing, you have to keep an array and add the object IDs everytime you insert one.
I'm not sure if you're able to access the markers once you've added them in using a KLM layer. If you don't have that many markers, then I would say load them using the regular Marker class.
Maybe I didn't do it right, but last time I tried implementing markers using KLM layers I wasn't able to add any events to them, or access them at all.
If you only need to count them, then I would say load that same KML file using AJAX, and parse it as an XML and you can grab the elements from there to count them.
You can't access the markers in a KmlLayer (it is rendered as map tiles by Google's servers). You could use a FusionTableLayer (you can import KML into the FusionTable, then modify the query to that FusionTable to filter the markers) or a third party KML parser like geoxml3 or geoxml-v3 (which render the KML using native Google Maps v3 objects).
example using geoxml3
example using FusionTables

Google like customize and preview embedded map in my site?

i whant to have something similar like googles customize and preview embedded map. is it possible that users just find location on the map, type in the size they want and just copy the generated code?
What it sounds like is that you want to allow people to select and save a custom Google map of their own within your app.
A simple way to do so would be using Google maps APIto create a map inside a container dom element. You would then allow user to resize the container element which would essentially allow them to position the map and also their chosen size.
When the user is finished resizing and positioning, you would need to make another call to the API to get the current lat/long of the map as well as getting the dimensions of the container. With the lat/long and container dimensions saved, this should be enough information for you to save the users custom map.
Hope this helps.

Categories

Resources