Efficient/Proper way to add Images to MapControl - windows phone 8.1 - windows-runtime

I'm developing an App in which the map will be shown to user and I need to add around 10-12 images to the map at different GeoPoints each having 1KB of size.
I'm adding those images dynamically as per below:
Image img = new Image();
img.Height = 35;
img.Width = 35;
img.Source = new BitmapImage(new Uri("ms-appx:///Assets/myImage.png"));
img.RenderTransform = new CompositeTransform() { Rotation = item.bearing };
MapControl.SetNormalizedAnchorPoint(img, new Point(0.5, 0.5));
MapControl.SetLocation(img, new Geopoint(new BasicGeoposition() { Latitude = item.latitude, Longitude = item.longitude }));
myMap.Children.Add(img);
My Problem is
After I add those 12 images, my Map control becomes soo Laggy that while moving the map from one location to other, it hangs a lot.
So, is there any efficient way to add images to Map in windows phone 8.1 App.
Edit:
I've tried to add MapIcons to the Map, but in that case MapIcons were disappeared at specific zoom level, but i want to keep those MapIcons visible at any zoom level.
So is there any way I can make MapIcons visible for every zoom level?

You could use the MapIcon class instead, this would be handled better as the map is a native C++ control, so it has to do a lot of work to position XAML elements on the map. The MapIcon class is a native class so it renders much better. You will need to convert your image into a RandomAccessStream and then pass it into the MapIcon image property. This may help: https://blogs.msdn.microsoft.com/going_metro/2012/05/14/working-with-streams-creating-randomaccessstreamreference-from-image-downloaded-from-web/
You can then add the MapIcon's to the maps MapElements property.

Related

libGDX change tilemap

I am making an 2d rpg game with box2d. So, I've got a problem. When one of my bodies(the character) collides with another(a door) the map needs to change, should I just create new screens for maps and change them? Or is there a more simple solution?
You can change your current map on the same screen only. What you have to do is, Let's say your map variable name is testMap. Now let's say your player just collided with a door. Now let's say you will call a method called changeMap(). Here is what you will put inside changeMap() method. (Assuming you are using tiled maps, you can change logic accordingly here)
void changeMap() {
Gdx.app.postRunnable(() -> { //Post runnable posts the below task in opengl thread
testMap = new TmxMapLoader().load("someMap.tmx"); //load the new map
renderer.getMap().dispose(); //dispose the old map
renderer.setMap(testMap); //set the map in your renderer
});
}

OpenLayer Static Image Size

I am using Openlayer version 3 for some mapping process. My map source is static image for this reason I used ol.source.ImageStatic datasource type.
My problem is zoom level. How can find zoom level to show image actual size? When load high definition image, OpenLayer show it smaller.
Thanks.
Map resolution/zoom can be listen with:
map.getView().on('change:resolution', function(evt){
var resolution = evt.target.get(evt.key);
console.info(resolution);
});
You can also monitor your ol.layer.Image
your_image_layer.on('change:maxResolution', function(evt){
});
your_image_layer.on('change:minResolution', function(evt){
});

HTML5 Image quality after scaling bitmap is bad

I am creating my first game in HTML 5 for mobile.
I'm just using the library "Easeljs-0.7.0", nothing PhoneGap.
I made my images to canvas 2024x1024 pixels, then each image by setting the scaleX and scaleY. However when the scale is less than 0.5 makes all images with poor quality.
How to solve this?
var test = new createjs.Bitmap("test.png");
test.scaleX = 0.23456;
test.scaleY = 0.23456;
APP.stage.addChild(test);
APP.stage.update();
Unfortunately this is how Canvas renders the bitmap, and its not something that can be controlled by JavaScript. It is possible to get some results in various browsers using the `context.imageSmoothingEnabled' property, but currently it requires vendor prefixes. Check out this thread:
Canvas Image Smoothing
To do this with EaselJS, you need to get the canvas context, which is not currently available without manually accessing it:
var context = myStage.canvas.getContext("2d");
context.webkitImageSmoothingEnabled = context.mozImageSmoothingEnabled = true;

google maps using three.js and webgl

I have thousands of points that need to be plotted on google maps and got a very responsive maps using the example from https://github.com/ubilabs/google-maps-api-threejs-layer .
Did anyone have a play at this and wondering if it is possible to have different colored markers and possible marker click events?
Appreciate any pointers or examples online.
Millions of clickable data points can be painted on a google map using webgl.
A data point is represented by an x,y pair for a location on the canvas, an int for size, an off screen color, and an on screen color. These values are stored in separate typed arrays.
Each data point has a unique rgb color to act as a key in a lookup table of data point ids.
Create a texture to store the off screen colors and render it to an off screen buffer. On event, load the off screen buffer and use glReadPixels to retrieve the rgb color of the pixel clicked and then find the id in the lookup table. Points on the on screen buffer, what the user sees, can share a common color.
canvas.addEventListener('click', function(ev) {
# insert code to get mouse x,y position on canvas
pixels = new Uint8Array(4);
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
gl.readPixels(x, y, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
if (colorToId[pixels[0] + " " + pixels[1] + " " + pixels[2]]) {
# Pixel clicked is a data point on the map
}
});
Webgl code is lengthy, so only the click event is included.
Here is a live demo and a repo. (angular and coffeescript)
Here is a second example using plain js: webgl-picking-geo-polygons
Here is react-webgl-leaflet
The solution is based on Brendan Kenny's Google Maps + HTML5 + Spatial Data Visualization which explains some of the code in the excerpt above at the 30 min mark, and Displaying WebGL data on Google Maps.
The demo features less than ten data points, but you can just as easily paint over 16 million pickable data points using all combinations of rgb values.
I discovered OpenLayers this past week. Very, very impressive framework. I would strongly suggest taking a look at it. OpenLayers.org is an open source JavaScript web mapping library distinguished from other alternatives, like Leaflet or Google Maps APIs, because of its huge set of components.
I spent the entire weekend creating sample apps by integrating OpenLayers with API's such as MapBox, WebGL etc... After all was said and done, I was extremely impressed with OpenLayers - and I plan to make use of OpenLayers in an upcoming POC/Project.
Here is a link to my test harness. From there you can also download the code for all of the examples, too.
Updates for 2021!!
Google Maps JS now has a WebglOverlayView class and exposes the WebGL context.
const webglOverlayView = new google.maps.WebglOverlayView();
webglOverlayView.onAdd = () => {
// Do setup that does not require access to rendering context.
}
webglOverlayView.onContextRestored = gl => {
// Do setup that requires access to rendering context before onDraw call.
}
webglOverlayView.onDraw = (gl, coordinateTransformer) => {
// Render objects.
}
webglOverlayView.onContextLost = () => {
// Clean up pre-existing GL state.
}
webglOverlayView.onRemove = () => {
// Remove all intermediate objects.
}
webglOverlayView.setMap(map);
Additionally, #googlemaps/three extends this class for easier use with ThreeJS.
// instantiate a ThreeJS Scene
const scene = new Scene();
// Create a box mesh
const box = new Mesh(
new BoxBufferGeometry(10, 50, 10),
new MeshNormalMaterial(),
);
// set position at center of map
box.position.copy(latLngToVector3(mapOptions.center));
// set position vertically
box.position.setY(25);
// add box mesh to the scene
scene.add(box);
// instantiate the ThreeJS Overlay with the scene and map
new ThreeJSOverlayView({
scene,
map,
});
Here is a link to a jQuery/google map app. Not exactly what you are looking for; however you might find the example useful. Feel free to use - it can be downloaded from my site.
Link to app on my website
Click here to download the zip

Stop canvas flicker on re-render

I have written a jQuery plugin that will render four polygons onto a canvas and fill them with an image.
When you mouse over a polygon it is moved to a separate top layer and re-rendered so it expands and then contracts if you mouse out.
Is there any way to do this so that it doesn't flicker?
I've had a look a this question but don't quite understand what the accepted answer is doing (I know it draws the image on a seperate layer but I don't know how it checks if this has finished rendering before using it) or how to include it in my jsfiddle code
As it turns out it was because I was making a new image object everytime I made the drawing:
var imageObj = new Image();
imageObj.src = polyArray[4];
imageObj.onload = function () {
poly.setFillPatternImage(imageObj);
stage.draw();
}
I changed this so that these objects were created and cached into an array and then re-used. This enabled the re-rendering to run a lot faster and removed the flickering:
http://jsfiddle.net/peteng/KAkvX/10/