I am displaying a heatmap generated with geoserver on my google map.
It work pretty fine but the heatmap is tiled, even if the call to the wms is specifically "tiled=false".
Geoserver doc say "Rendering transformations may not work correctly in tiled mode, unless they have been specifically written to accomodate it."
The style to create heatmap in geoserver is copied from https://docs.geoserver.org/stable/en/user/styling/sld/extensions/rendering-transform.html#heatmap-generation
The overlap in my js script is something like
var url = "http://localhost:8080/geoserver/test/wms?";
url += "&service=WMS"; //WMS service
url += "&version=1.1.0"; //WMS version
url += "&request=GetMap"; //WMS operation
url += "&layers=test%3Aglobal_points"; //WMS layers to draw
url += "&styles=heatmap"; //use default style
url += "&format=image/png"; //image format
url += "&TRANSPARENT=TRUE"; //only draw areas where we have data
url += "&srs=EPSG:4326"; //projection WGS84
url += "&bbox=" + bbox; //set bounding box for tile
url += "&width=256"; //tile size used by google
url += "&height=256";
url += "&tiled=false";
So, there's a way to fix it?
You are requesting tiles:
url += "&bbox=" + bbox; //set bounding box for tile
url += "&width=256"; //tile size used by google
url += "&height=256";
even if you set tiled=false - make a request for the whole map and with width and height set to the size of the window.
Even then your heat map will change on each move of the map as more or less points come into view, if you must use a heat map then calculate it once for the whole data set and serve it as a raster layer.
Here is your obligatory XKCD on heatmaps:
Related
Needing some help migrating my flying functionality from the Google Earth plugin to Cesium. Basically in ge I create a lookAt and called setAbstractView like below
var ge = google.earth.createInstance('map3d')
var lookAt = TVV.mapObject.createLookAt('');
lookAt.set(
21.2765107698755,
-157.825362273258,
0,
ge.ALTITUDE_RELATIVE_TO_GROUND,
20.1690873648706,
74.9605580474674,
764.534479411941
);
ge.getView().setAbstractView(lookAt);
That was my code for google earth plugin. In cesium following the migration guides I do:
// fly to code that works with cesium (but a little bit off)
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees(-157.825362273258, 21.2765107698755, 764.534479411941),
orientation : {
heading : Cesium.Math.toRadians(20.1690873648706),
pitch : Cesium.Math.toRadians(74.9605580474674 - 90.0),
roll: 0
}
})
That code goes to almost the right place. I have to drag it down over to the right to see my placemark that I previously set (so the view is not exactly what it was in Google earth).
So I tried this code I also found.
// code that works with cesium
var center = Cesium.Cartesian3.fromDegrees(-157.825362273258, 21.2765107698755);
var heading = Cesium.Math.toRadians(20.1690873648706);
var pitch = Cesium.Math.toRadians(74.9605580474674);
var range = 764.534479411941;
viwer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range));
That code looks MUCH closer to the previous google earth plugin view. However, of course, it does not fly the camera to the view. It only sets the view right away.
My question is, how can I fly the camera to the lookAt view in cesium, taking advantage of my lat, lng, heading, pitch, and range values?
Here are the relevant API docs from GE and Cesium should you find them useful.
GE createLookAt
https://developers.google.com/earth/documentation/reference/interface_g_e_plugin.html#a82f1b3618531a6bfab793b04c76a43e7
GE Camera Control (search for "Panning to an absolute location")
https://developers.google.com/earth/documentation/camera_control
Cesium lookAt
https://cesiumjs.org/Cesium/Build/Documentation/Camera.html#lookAt
Cesium flyTo
https://cesiumjs.org/Cesium/Build/Documentation/Camera.html#flyTo
I also found this but was unsure about how to integrate it. If anybody could provide a codepen/jsfiddle or something of the like that would be greatly appreciated!
https://groups.google.com/forum/#!topic/cesium-dev/r5rddMUeS80
Thanks to Hannah Pinkos from the Cesium Forum for the answer.
After creating an entity and using values for heading, pitch(tilt), and range from the google earth plugin, you can fly to the entity with an offset...
var heading = Cesium.Math.toRadians(20.1690873648706g);
var pitch = Cesium.Math.toRadians(74.9605580474674 - 90);
var range = 764.534479411941;
TVV.mapObject.flyTo(entity, {
offset: new Cesium.HeadingPitchRange(heading, pitch, range)
});
I'm trying to make some tasty live tile action for my windows phone 8 app. I've chosen to use the Cycle Tile template for some awesome gliding images but there is a problem: Microsoft seem to have kindly added a grey translucent filter to all the images so that the title text at the bottom is legible even in the case of a white image. This is annoying if the developer intends to make a metro style collage by using WritableBitmap. Whites come out as an off-white grey and the theme colour is a shade darker than all the other tiles:
The code (in a usercontrol in the visual tree):
const double TILE_H = 336;
const double TILE_W = 691;
Size TILE_SIZE = new Size(TILE_W, TILE_H);
const string FILEDIREC = "/Shared/ShellContent";
LayoutRoot.Height = TILE_H;
LayoutRoot.Width = TILE_W;
LayoutRoot.Clip = new RectangleGeometry() { Rect = new Rect(new Point(), TILE_SIZE) };
LayoutRoot.Background = new SolidColorBrush(
((Color)Application.Current.Resources["PhoneAccentColor"]));
TextBlock tb = new TextBlock();
Canvas.SetLeft(tb, 200.0);
tb.Text = "Why is this text grey? + lots more text";
tb.FontSize = 50;
tb.Width = 300;
tb.Foreground = new SolidColorBrush(Colors.White);
tb.TextWrapping = TextWrapping.Wrap;
LayoutRoot.Children.Add(tb);
var bmp = new WriteableBitmap((int)TILE_W, (int)TILE_H);
bmp.Render(LayoutRoot, null);
bmp.Invalidate();
var isf = IsolatedStorageFile.GetUserStoreForApplication();
var filename = FILEDIREC + "/tile.jpg";
if (!isf.DirectoryExists(FILEDIREC))
{
isf.CreateDirectory(FILEDIREC);
}
using (var stream = isf.OpenFile(filename, System.IO.FileMode.OpenOrCreate))
{
bmp.SaveJpeg(stream, (int)TILE_W, (int)TILE_H, 0, 100);
}
imageURIs.Add(new Uri("isostore:" + filename, UriKind.Absolute));
//similar process for other images used by CycleTileData
//these images then added to CycleTileData in the usual way
Any help, explanation, advise or workarounds to get degreying will be greatly appreciated. Thanks. I've tried using the images in different tile types, eg. the front of the flip tile has no issues.
I don't see any obvious issues with the code, but something I would try is to use the Isolated Storage Explorer and download the file and see what it looks like.
When generating custom tiles you may want to consider generating a PNG instead of a JPG. One of the benefits is that you then can generate a transparent image (which means your tile will always have the right theme background color) and PNG also uses a non-lossy compression scheme so there are no compression artifacts introduced.
Take a look at this answer where I describe how I generate tiles in one of my apps. Hopefully that will be of some use to you.
It is very simple to create a google map and center on a given location (see below). It is also similarity simple to create a google map and show markers on it by doing something like markers=color:blue%7Clabel:S%7C11211%7C11206%7C11222.
How would I just create a simple centered map like the below, but add a single marker in the very center? Thanks
<img alt="Map" src="http://maps.google.com/maps/api/staticmap?center=+AUBURN+WA+98001&zoom=14&size=400x400&sensor=false">
I guess that the map automatically will fit to show the specified markers,
here you will find
Marker Locations
Each marker descriptor must contain a set of one or more locations
defining where to place the marker on the map. These locations may be
either specified as latitude/longitude values or as addresses. These
locations are separated using the pipe character (|).
The location parameters define the marker's location on the map. If
the location is off the map, that marker will not appear in the
constructed image provided that center and zoom parameters are
supplied. However, if these parameters are not supplied, the Static
Map server will automatically construct an image which contains the
supplied markers. (See Implicit Positioning below.)
You could also add your own centered background image ontop if the map :)
background: url('yourmarker.png' ) center no-repeat, url(http://maps.google.com/maps/api/staticmap?center=AUBURN+WA+98001&zoom=14&&size=400x400);
here i am giving the code in step by step
NSString *strLat = [NSString stringWithFormat:#"%f",_message.latitude];
NSString *strLong = [NSString stringWithFormat:#"%f",_message.longitude];
NSString *strURL = [NSString stringWithFormat:#"%#center=%#,%#&zoom=15&size=200x200&markers=color:red%%7Clabel:C%%7C%#,%#&key=%#",https://maps.googleapis.com/maps/api/staticmap?,strLat,strLong,strLat,strLong,GOOGLE_API_BROWSER_KEY];
NSLog(#"strURL %#",strURL);
strURL = [strURL stringByReplacingOccurrencesOfString:#"%%" withString:#"%"];
now you have a image url
Google Static Maps Reference For Addresses:
https://developers.google.com/maps/documentation/maps-static/dev-guide#Addresses
Here's a JavaScript function that I've used recently to do this. The addressElements parameter passed to the function is an array of address elements e.g. ['10 Main St', 'Brownsville', 'MS', '27123', 'USA'].
You can see that I've commented out the center and zoom properties as you don't need those when you define a marker. To remove the marker, just uncomment those two lines and comment out the markers line.
You can obviously construct this image yourself, but I used the URLSearchParams to simplify parameter creation and have them URL encoded automagically.
function getGoogleMapsImage(addressElements) {
var image = Nucleus.element('img');
image.width = '256';
image.height = '256';
var joined = addressElements.join(',');
var params = new URLSearchParams();
//params.append('center', joined);
//params.append('zoom', '15');
params.append('size', '256x256');
params.append('maptype', 'roadmap');
params.append('key', 'YOUR_API_KEY_HERE');
params.append('markers', 'color:red|label:C|' + joined);
var url = 'https://maps.googleapis.com/maps/api/staticmap?' + params.toString();
image.src = url;
return image;
}
I have tried to draw Polygon using Drawing Manager and send the Polygon Coordinates to PHP script(to store in Database).
1)i have coded editable option as 'true' for polygon. But i am not to
edit the polygon.I am not to find what i did wrong?
2)Also i try to get
Polygon paths using getPaths method..it is returned as array..How do i
check this coordinates are correct. If i put in alert in displays as
'Object[] Object'.Please help me to solve these problems.
You need to set the drawing mode to true (to enable map interactions). the following code will do the trick :)
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(polygon) {
drawingManager.setDrawingMode(null);
});
with regards to the 2nd part im currently working on that now. use console.log instead of alert.
For the path:
var thisPath=polygon.getPath();
for(i=0;i<thisPath.length;i++){
var latlng=thisPath.getAt(i);
pathString= pathString+', '+ latlng.lat()+' - '+ latlng.lng()+'\n'
}
alert (pathString);
For part 2, sharingStuff code would work, I preferred for the path to be a json object,
vertices = this.polygon.getPath();
var points = [];
// Iterate over the vertices.
if(this.polygon.getMap() == null){
return false;
}
for (var i =0; i < vertices.length; i++) {
var xy = vertices.getAt(i);
points.push(xy.lat() +"," + xy.lng());
}
return JSON.stringify({points: points});
either method is fine, just thought I'd give you another option. :)
im a little stuck using the canvas element in html5, have scoured the net looking for a workable solution but to no avail!
the main issue is that I want to click a button and send just the canvas element on the page to the printer.
i have tried using toDataUrl() - but this just seems to be resulting in a blank white image which has none of the canvas content!
the other issue i am experiencing is that attempting to initiate any javascript functions using "onClick" attached to a form button seems to be being tempermental at best!
here is my current attempt - this works in the sense that it does open a new window and attempt to send it to printer and it does create a base64 string (tested this using the "dataUrl" output on the second lowest document.write line) but as previously mentioned the image appears to be completely blank! (the canvas itself is definitely filled, both with an imported image and some text)
function printCanv()
{
var dataUrl = document.getElementById('copy').toDataURL(); //attempt to save base64 string to server using this var
document.getElementById('testBox').value = dataUrl; //load data into textarea
//attempt open window and add canvas etc
win = window.open();
self.focus();
win.document.open();
win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
((image code is here but site will not let me post it for some reason?))
win.document.write(dataUrl);
win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
win.document.close();
win.print();
win.close();
}
note: the code from "win = window.open()" onwards is currently taken from a tutorial and not my own work!
it is currently being called using <body onload="printCanv";"> - for some reason I could not get this to work at all using a button (little chunk of code below is my attempt which seemed to fail)
<input type="button" id="test" value="click me" onClick="printCanv();"> </input>
apologies is this help request is all over the place! i haven't posted to a site like this before and it didn't like me posting some html/script!
thanks in advance for any help you may be able to offer :)
Edit: draw function:
function copydraw() { //function called "copydraw" (could be anything)
var testimage3 = document.getElementById('copy').getContext('2d'); //declare variable for canvas overall (inc paths)
var img3 = new Image(); //declare image variable called "img3"
var testVar = document.getElementById('userIn').value; //take value from userin box. only updating on browser refresh?
img3.onload = function(){ //when image has loaded (img.onload) run this function
testimage3.drawImage(img3,0,0); //draw "img" to testimage
testimage3.font = "30pt 'Arial'"; //font method varies font attrib (weight, size, face)
testimage3.fillStyle = "#000000"; //sets fill color
testimage3.fillText(testVar, 310, 360); //filltext method draws text (xup ydown)
}
img3.src = 'images/liecakeA4.jpg'; //source of image
}
This function works perfectly, it draws the object and adds text from the variable, but for some reason it seems to be preventing me from outputting it as an image. I'm really confused!
I'm not sure exactly what's wrong with your code, I suspect in your current version calling printCanv in the body load event will mean you're trying to print the canvas before it's drawn. Running it off the button should work better, I'm not sure why that wasn't working for you as there's no reason in principle why it shouldn't work.
To arrive at a working version I've modified your code slightly:
function printCanvas(el) {
var dataUrl = document.getElementById(el).toDataURL(); //attempt to save base64 string to server using this var
var windowContent = '<!DOCTYPE html>';
windowContent += '<html>'
windowContent += '<head><title>Print canvas</title></head>';
windowContent += '<body>'
windowContent += '<img src="' + dataUrl + '">';
windowContent += '</body>';
windowContent += '</html>';
var printWin = window.open('','','width=340,height=260');
printWin.document.open();
printWin.document.write(windowContent);
printWin.document.close();
printWin.focus();
printWin.print();
printWin.close();
}
This works for me in the Firefox 4.0 nightly.
One addition to the accepted-best-answer: It doesnt work here with Chrome 17.0.942.0 winvista, because the print-preview-dlg is shown within the website itself and printWin.close() will close the dlg too.
So printWin.close() must be delayed or initiated by the user, but those are no good solutions.
It would be best, if chrome printdlg could have a callback, sth. one knows, printing is done, and can close the window. If this is possible is another question.