Geoserver WMS call not returning base map - javascript

I am working on a web application based on OpenLayers, Geoserver, Java and JavaScript.
The user needs to select an area on the map and that portion has to be downloaded as an image. I tried hitting the WMS using Ajax -
http://localhost:8080/geoserver/wms?request=GetMap&service=WMS&version=1.1.0&layers=geoworkspace:STRUCTURE,&styles=&srs=EPSG:27700&bbox=526274.1873390013,196214.08896841796,526277.1040062243,196217.2973028639&width=1200&height=1200&format_options=dpi:300;antialiasing:on&format=image%2Fpng8
As a result, I get all the required layers except for the underlying base map. Is there a way to get the base map too?
Is there an alternative approach to this requirement?

Enable CORS on server (GeoServer) for ajax
https://gist.github.com/essoen/91a1004c1857e68d0b49f953f6a06235

If your base layer is on the same server then you can request it in a single GetMap operation, by providing the layer name in a comma separated list as part of the layers request parameter. Note though that this creates a single image, that merges the layers, so you'll need to take care of the order you list the layers.
So
http://ogc2.bgs.ac.uk/cgi-bin/UGA_ARGI/ows?service=WMS&version=1.3.0&request=GetMap&width=700&height=450&styles=,&layers=ARTISAN,ARTISANC&format=application/openlayers&crs=EPSG:4326&bbox=-2.000000,29.000000,4.500000,37.000000&
The ARTISANC layer is drawn on top of the ARTISAN layer.
and
http://ogc2.bgs.ac.uk/cgi-bin/UGA_ARGI/ows?service=WMS&version=1.3.0&request=GetMap&width=700&height=450&styles=,&layers=ARTISANC,ARTISAN&format=application/openlayers&crs=EPSG:4326&bbox=-2.000000,29.000000,4.500000,37.000000&
The ARTISAN layer is drawn on top of the ARTISANC layer.
So in your case you'd want the base layer to be listed first.
Also note that as you have two layers, you should have two styles, so we have the styles request parameter like styles=,& or you could just have styles& to force the default.

Related

Is there a way to omit a certain route when using the mapbox directions API?

I'm using the MapBox directions API to show and calculate the distance between several waypoints. The thing is, this routes are for big trucks, and MapBox generates a route where big trucks can't go through (A tiny one way bridge). Legally, only cars can go through. Is there a way to tell the direction's API to skip that bridge and generate an alternative, longer route?
The only exclusion options currently available in the Mapbox Directions API are for ferries, tolls, and motorways. You can not exclude with waypoints or areas at this time. Where available, Alternative routes may be requested by passing the alternatives=true parameter. If you wish to create custom routes, use the Map Matching API to make a request that will snap your desired coordinates to parts of the network you wish to route on.

Can we increase the google map static URL character length to upto fifty thousand characters

Actually i am using Google static map API in Nodejs to get satellite image of Multi geometry path (3) and markers with custom style (400), but the length of created URL is beyond 45000 characters, so could you help me to find any other service which can allow this much URL length or any other implementation technique to get map satellite image with path and markers in such a big count of path and markers.
As per this doc,
Maps Static API URLs are restricted to 8192 characters in size.
And to answer your question, there's currently no way to increase this character limit.
But, we do have an existing feature request for this in our Google Issue Tracker. However, this entry was marked as a duplicate of another feature request to support KML layers in Static Maps API. To express your interest and to subscribe you to its latest updates, I suggest that you star this entry: https://issuetracker.google.com/35817020
In the mean time, you might want to consider trying Maps Javascript API - Dynamic Maps as this service have an option to Draw on the Map and allows you to use the MarkerClusterer library which displays marker clusters instead of a large number of markers on a map. To know more on how marker clustering works, please check out this doc: https://developers.google.com/maps/documentation/javascript/marker-clustering

Google Maps JS API: Better to store data in markers or in JSON?

I am visualizing some government data using Google Maps JS API. Currently every time the user changes a filter value it grabs the entirety of the JSON data again, filters it, and creates a marker for each row that passes the filter validation. This is slow because it's re-downloading the JSON every time you change the form the filters are located in.
There are two ways to approach caching and displaying the data dynamically: storing the received JSON once and destroying/recreating markers based on the filter, or by creating all the markers at once and only displaying those that match filters.
Is there a performance difference between these two options? Both make sense to me, I'm just not sure how to tell whether one is better than the other. How can I assess how 'heavy' google maps markers are for the user?
The suggested 2 approaches are definitely going to be faster than the original strategy where the JSON data is re-fetched on each filter change.
I guess there are advantages and disadvantages to each method.
If you are not going to retrieve the JSON data on each filter change then essentially the data could be out of data but if the use case is that the JSON data rarely gets updated then this consideration can be dropped.
Having the JSON data cached and creating all of the markers upfront would cause the map to take a bit longer than usual to load at start, as you will need to create all markers first whereas the other way round is that you only create a subset of the markers - hence quicker.
I guess it all comes down to how many markers are there? What is the typical using pattern of the map.
If there is a million markers and the typical filter would cause 100,000 markers to be regenerated on change, then you better off generating the markers upfront and just tweak their visibility accordingly.
Similarly if you have a million markers and the typical filter would only cause 1 or 2 markers to appear out of the million, then probably destroying and recreate would be faster.
Anyway, as a user I would rather have the map take a bit longer to load at the start, probably sacrificing 1-2 seconds. Then have the markers changes instantaneously when I'm playing with the filters. Hope this helps.

Google map static api url length is exceeding 2048 char is there any solution ? aim is to save as image

so far I used google map api in javascript as well as in php, I had no problem in creating thousands of markers using these api, but my final aim is to save them as image, so finally I came to know that I have to use static make api, in order to save it as image., so tried static map api with few markers, I could able to save, but when tried with 1000's of markers I did not succeed, through many search on this forum I came to know that url limit is exceeding 2048 char, yes that is true.
So is there any alternate way to save map with thousands of markers ? in case of googlemap api in javascript/php I can see all markers, but nowhere I found solution for how to save them locally ?
whether anyone here found solution to save ? something like screen shot or you can say writing a content of map division to png / jpeg/ gif file ?
Please someone help me.
Thanks.
OK first let's talk TOS. As a couple commenters have pointed out you're not allowed to save maps offline. The specific section 10.1.1(h) which forbids you from using static maps outside of a web based app except in a couple specific situations. Print is not one of those - just in case. Section 10.1.3 also says "No Pre-Fetching, Caching, or Storage of Content" which means you can't take a map and just store it somewhere for later use. Caching for performance reasons is fine.
Now assuming you're OK with both of those things, the static Maps Image API is useful but not really useful for your specific use case. While you can encode polylines using the special encoding function, you can't put on a bunch of markers like you're intending.
One thing you could do is to download the static maps API image without markers. You know the physical dimensions of the image and the bounding box in lat/long. It's trivial to convert that to degrees/pixel. You could use an the PHP image functions to convert the lat/lng to x/y pixels and manually place the markers on the image.
As long as you use the subsequent image output back in your webpage and only cache the image for a specific short period of time (a.k.a performance reasons) you should have no problems with the Maps TOS.
Please note that now (September 2016) the URL limit has been changed to 8192 characters in size.
https://developers.google.com/maps/documentation/static-maps/intro#url-size-restriction
Here is the corresponding feature request.

Choropleth with fixed polygons and updateable region values

I'm trying to make a choropleth map visualization with fixed polygon regions, but variable data for each region that depends on a query. Currently I have the polygon coordinates in KML and SHP format, and I could convert it to GeoJSON if needed.
Basically what I want it to do is to load a map with those regions once, and be able to update the values + fill colors of those regions whenever new data is requested / received through an AJAX callback. The most important is it doesn't unnecessarily reload the region polygons, i.e. I could just supply a JSON object of region id's and their new values).
I already tried using the Google Maps API, but I can't seem to bypass generating an entire new KML file each time I want to load new values. This forces me to unnecessarily reload the region shapes as well, although they never change. I tried caching the KML clientside in a JS object, updating it's values each time new data is received and then re-setting the map (using geoxml3), but this seems to perform rather slow (since the entire KML is being iterated and since it's a pretty large file including all the region coordinates). FusionTables didn't work for me either because I need to fetch the data from my own database, and from what I understand using FusionTables you can only query a FT table.
As far as I know the Gmaps API probably isn't going to work for me. Which other solution could suit my needs best?
Google just added GeoJSON support to the Maps API. This example does something similar to what is described above:
https://developers.google.com/maps/articles/combining-data

Categories