Skip to content

Instantly share code, notes, and snippets.

@koriner
Last active August 29, 2015 14:01
Show Gist options
  • Save koriner/0b891d630b42dc2e54da to your computer and use it in GitHub Desktop.
Save koriner/0b891d630b42dc2e54da to your computer and use it in GitHub Desktop.
distriqt / NativeMaps 2.2 update notes and examples
/**
* __ __ __
* ____/ /_ ____/ /______ _ ___ / /_
* / __ / / ___/ __/ ___/ / __ `/ __/
* / /_/ / (__ ) / / / / / /_/ / /
* \__,_/_/____/_/ /_/ /_/\__, /_/
* / /
* \/
* http://distriqt.com
* -------------------------------------
*
* brief: Native Maps 2.2 Release Notes & Examples
* tag: distriqt.extension.nativemaps
*
*/
/**
* NativeMaps 2.2 Release
*
* New functionality:
* 1. Fixed support for displaying custom marker icons on retina displays
* 2. New events for map loading and rendering state changes
* 3. Added new map options for showing points of interest (on iOS) and showing buildings
* 4. Fixed a bug where the animation of the setCentre method had no effect on iOS
*
* See below for examples of these new features.
*/
package
{
public class NativeMap2_2Examples extends Sprite
{
public static const DEVELOPER_KEY : String = "your-dev-key";
public function NativeMap2_2Examples()
{
NativeMaps.service.init( DEVELOPER_KEY );
}
/**
* Example of using alternate map icons for retina displays
*/
public function retinaIconExample():void
{
// Create the normal marker icon at regular size
var bmp:Bitmap = new EmbeddedBitmap() as Bitmap; // This is some bitmap @ 64x64 pixels
var icon:CustomMarkerIcon = new CustomMarkerIcon( "myCustomIcon", bmp.bitmapData );
NativeMaps.service.addCustomMarkerIcon( icon );
// Create a second marker icon with a larger bitmap (should be 2x the size)
var bmp2x:Bitmap = new EmbeddedBitmap2X() as Bitmap; // This is another bitmap @ 128x128px for a retina screen
var icon2x:CustomMarkerIcon = new CustomMarkerIcon( "myCustomIcon2x", bmp2x.bitmapData, 2 );
NativeMaps.service.addCustomMarkerIcon( icon2x );
var myMarker:MapMarker = new MapMarker("myMarker");
myMarker.title = "Test marker";
myMarker.setPosition( new LatLng(-37, 144) );
// Switch here to determine which icon we need to assign
if (NativeMaps.service.isRetinaDisplay())
{
myMarker.customIconId = "myCustomIcon2x";
}
else
{
myMarker.customIconId = "myCustomIcon";
}
NativeMaps.service.addMarker( myMarker );
// Yay!
}
/**
* Example of the new map options
*/
public function newOptionsExample():void
{
// Turn off iOS map points of interest
NativeMaps.service.showPointsOfInterest( false );
// Turn off buildings
NativeMaps.service.showBuildings( false );
// Alternatively, you can use the MapOptions as well
var options:MapOptions = new MapOptions();
options.showMapkitPointsOfInterest = false;
options.showBuildings = false;
NativeMaps.service.setMapOptions( options );
}
/**
* Example of the new map events
*
* Note: these events will be dispatched very often, basically any time the map position
* or zoom level changes.
*/
public function newEventsExample():void
{
// Dispatched when the map begins loading tiles
// Should always be used on iOS6 or below
// on iOS7, use MAP_RENDER_START instead as it is more reliable.
NativeMaps.service.addEventListener( NativeMapEvent.MAP_LOAD_START, map_loadStartHandler );
// Dispatched when the map fails to load correctly
NativeMaps.service.addEventListener( NativeMapEvent.MAP_LOAD_FAILED, map_loadFailedHandler );
// Dispatched when the map finishes loading
// Should always be used on iOS6 or below
// on iOS7, use MAP_RENDER_START instead as it is more reliable.
NativeMaps.service.addEventListener( NativeMapEvent.MAP_LOAD_COMPLETE, map_loadCompleteHandler );
// iOS7+ and Android only
// dispatched when the map begins rendering
NativeMaps.service.addEventListener( NativeMapEvent.MAP_RENDER_START, map_renderStartHandler );
// iOS7+ and Android only
// dispatched when the map finishes rendering
NativeMaps.service.addEventListener( NativeMapEvent.MAP_RENDER_COMPLETE, map_renderCompleteHandler );
}
}
}
@M8Games
Copy link

M8Games commented May 22, 2014

Missing pixelScale property at the line:
var icon2x:CustomMarkerIcon = new CustomMarkerIcon( "myCustomIcon2x", bmp2x.bitmapData );

The correct code is:
var icon2x:CustomMarkerIcon = new CustomMarkerIcon( "myCustomIcon2x", bmp2x.bitmapData, 2 );

@koriner
Copy link
Author

koriner commented Sep 7, 2014

Thanks - fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment