-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SeniorMobileDeveloper
authored and
SeniorMobileDeveloper
committed
Jan 24, 2017
0 parents
commit c6b5cee
Showing
9 changed files
with
1,446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
# MapKit plugin for iOS | ||
================================= | ||
|
||
You can install this plugin with cordova CLI | ||
|
||
cordova plugin add <Local Path to MapKit Plugin> | ||
|
||
Follow the instructions that are displayed after you install the plugin. | ||
|
||
|
||
Sample usage code | ||
----------------- | ||
```js | ||
var app = { | ||
showMap: function() { | ||
var pins = [ | ||
{ | ||
lat: 49.28115, | ||
lon: -123.10450, | ||
title: "A Cool Title", | ||
snippet: "A Really Cool Snippet", | ||
icon: mapKit.iconColors.HUE_ROSE | ||
}, | ||
{ | ||
lat: 49.27503, | ||
lon: -123.12138, | ||
title: "A Cool Title, with no Snippet", | ||
icon: { | ||
type: "asset", | ||
resource: "www/img/max.png", //an image in the asset directory | ||
pinColor: mapKit.iconColors.HUE_VIOLET //iOS only | ||
} | ||
}, | ||
{ | ||
lat: 49.28286, | ||
lon: -123.11891, | ||
title: "Awesome Title", | ||
snippet: "Awesome Snippet", | ||
icon: mapKit.iconColors.HUE_GREEN | ||
} | ||
]; | ||
var container = document.getElementById("map_canvas"); | ||
var options = { | ||
mapContainer: container | ||
}; | ||
mapKit.showMap(function(){ | ||
mapKit.addMapPins(pins, function() { | ||
console.log('adMapPins success'); | ||
}, function() { | ||
console.log('error'); | ||
}); | ||
}, function(err){ | ||
alert(JSON.stringify(err)); | ||
}, options); | ||
}, | ||
hideMap: function() { | ||
var success = function() { | ||
console.log('Map hidden'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.hideMap(success, error); | ||
}, | ||
clearMapPins: function() { | ||
var success = function() { | ||
console.log('Map Pins cleared!'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.clearMapPins(success, error); | ||
}, | ||
changeMapType: function() { | ||
var success = function() { | ||
console.log('Map Type Changed'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.changeMapType(mapKit.mapType.MAP_TYPE_SATELLITE, success, error); | ||
}, | ||
setCoordinate: function() { | ||
var success = function() { | ||
console.log('Map Camera Changed'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
var options = { | ||
coordinate: {lat: 49.27503, lon: -123.12138}, | ||
zoomLevel: 5, | ||
animated: true | ||
}; | ||
mapKit.setLocation(options, success, error); | ||
}, | ||
getCenterCoords: function() { | ||
mapKit.getCenterCoords(function(response) { | ||
alert(JSON.stringify(response)); | ||
}, function(err) { | ||
console.log(err); | ||
}); | ||
}, | ||
drawRegion: function() { | ||
var options = { | ||
coord: {lat: 49.27503, lon: -123.12138}, | ||
radius: 2000, | ||
lineColor: { | ||
red: 0, | ||
green: 255, | ||
blue: 0, | ||
alpha: 1, | ||
}, | ||
fillColor: { | ||
red: 0, | ||
green: 0, | ||
blue: 255, | ||
alpha: 0.6 | ||
} | ||
}; | ||
var success = function() { | ||
console.log('Drew circle'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.setRegion(options, success, error); | ||
}, | ||
drawPolyline: function() { | ||
var pins = [ | ||
{ | ||
lat: 50.28115, | ||
lon: -121.10450 | ||
}, | ||
{ | ||
lat: 49.27503, | ||
lon: -123.12138 | ||
}, | ||
{ | ||
lat: 50.28286, | ||
lon: -124.11891 | ||
} | ||
]; | ||
var options = { | ||
path: pins, | ||
lineColor: { | ||
red: 100, | ||
green: 200, | ||
blue: 150, | ||
alpha: 1 | ||
}, | ||
lineWidth: 3 | ||
}; | ||
var success = function() { | ||
console.log('Drew Polyline'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.drawPolyline(options, success, error); | ||
}, | ||
drawPolygon: function() { | ||
var pins = [ | ||
{ | ||
lat: 50.28115, | ||
lon: -121.10450 | ||
}, | ||
{ | ||
lat: 49.27503, | ||
lon: -123.12138 | ||
}, | ||
{ | ||
lat: 50.28286, | ||
lon: -124.11891 | ||
} | ||
]; | ||
var options = { | ||
path: pins, | ||
strokeColor: { | ||
red: 100, | ||
green: 200, | ||
blue: 150, | ||
alpha: 1 | ||
}, | ||
fillColor: { | ||
red: 0, | ||
green: 100, | ||
blue: 150, | ||
alpha: 0.3 | ||
}, | ||
borderWidth: 2 | ||
}; | ||
var success = function() { | ||
console.log('Drew Polygon'); | ||
}; | ||
var error = function() { | ||
console.log('error'); | ||
}; | ||
mapKit.drawPolygon(options, success, error); | ||
}, | ||
getAddress: function() { | ||
mapKit.getAddressFromCoordinate({ | ||
lat: 49.27503, | ||
lon: -123.12138 | ||
}, function(response) { | ||
alert(JSON.stringify(response)); | ||
}, null); | ||
}, | ||
setMapClickable: function() { | ||
mapKit.setClickable(false); | ||
} | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<plugin id="cordova-plugin-applemapkit" version="0.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<name>MapKit</name> | ||
|
||
<engines> | ||
<engine name="cordova" version=">=4.0.0"/> | ||
</engines> | ||
|
||
<js-module name="MapKit" src="www/MapKit.js"> | ||
<clobbers target="mapKit"/> | ||
</js-module> | ||
|
||
<platform name="ios"> | ||
<framework src="MapKit.framework" /> | ||
<config-file parent="/*" target="config.xml"> | ||
<feature name="MapKit"> | ||
<param name="ios-package" value="MapKitView"/> | ||
<param name="onload" value="true"/> | ||
</feature> | ||
</config-file> | ||
<header-file src="src/ios/MapKit.h"/> | ||
<header-file src="src/ios/AsyncImageView.h"/> | ||
<header-file src="src/ios/CDVAnnotation.h"/> | ||
|
||
<source-file src="src/ios/MapKit.m"/> | ||
<source-file src="src/ios/AsyncImageView.m"/> | ||
<source-file src="src/ios/CDVAnnotation.m"/> | ||
</platform> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// AsyncImage.h | ||
// SabreHotels | ||
// | ||
// Created by Brett Rudd on 19/03/2010. | ||
// Copyright 2010 __MyCompanyName__. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
|
||
@interface AsyncImageView : UIView { | ||
//could instead be a subclass of UIImageView instead of UIView, depending on what other features you want to | ||
// to build into this class? | ||
|
||
NSURLConnection* connection; //keep a reference to the connection so we can cancel download in dealloc | ||
NSMutableData* data; //keep reference to the data so we can collect it as it downloads | ||
//but where is the UIImage reference? We keep it in self.subviews - no need to re-code what we have in the parent class | ||
|
||
} | ||
|
||
- (void)loadImageFromURL:(NSURL*)url; | ||
- (void)loadDefaultImage; | ||
- (UIImage*) image; | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// AsyncImageView.m | ||
// Postcard | ||
// | ||
// Created by markj on 2/18/09. | ||
// Copyright 2009 Mark Johnson. You have permission to copy parts of this code into your own projects for any use. | ||
// www.markj.net | ||
// | ||
|
||
#import "AsyncImageView.h" | ||
|
||
|
||
// This class demonstrates how the URL loading system can be used to make a UIView subclass | ||
// that can download and display an image asynchronously so that the app doesn't block or freeze | ||
// while the image is downloading. It works fine in a UITableView or other cases where there | ||
// are multiple images being downloaded and displayed all at the same time. | ||
|
||
@implementation AsyncImageView | ||
|
||
- (void)dealloc { | ||
[connection cancel]; //in case the URL is still downloading | ||
} | ||
|
||
|
||
- (void)loadImageFromURL:(NSURL*)url { | ||
|
||
NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; | ||
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; //notice how delegate set to self object | ||
//TODO error handling, what if connection is nil? | ||
} | ||
|
||
|
||
//the URL connection calls this repeatedly as data arrives | ||
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData { | ||
if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; } | ||
[data appendData:incrementalData]; | ||
} | ||
|
||
//the URL connection calls this once all the data has downloaded | ||
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection { | ||
//so self data now has the complete image | ||
connection=nil; | ||
if ([[self subviews] count]>0) { | ||
//then this must be another image, the old one is still in subviews | ||
[[[self subviews] objectAtIndex:0] removeFromSuperview]; //so remove it (releases it also) | ||
} | ||
|
||
//make an image view for the image | ||
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData:data]]; | ||
//make sizing choices based on your needs, experiment with these. maybe not all the calls below are needed. | ||
imageView.contentMode = UIViewContentModeScaleAspectFit; | ||
imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ); | ||
[self addSubview:imageView]; | ||
imageView.frame = self.bounds; | ||
[imageView setNeedsLayout]; | ||
[self setNeedsLayout]; | ||
|
||
//[data release]; //don't need this any more, its in the UIImageView now | ||
data=nil; | ||
} | ||
|
||
//in case we want a local image | ||
- (void)loadDefaultImage { | ||
|
||
if ([[self subviews] count]>0) { | ||
//then this must be another image, the old one is still in subviews | ||
[[[self subviews] objectAtIndex:0] removeFromSuperview]; //so remove it (releases it also) | ||
} | ||
|
||
//make an image view for the image | ||
UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon.png"]]; | ||
//make sizing choices based on your needs, experiment with these. maybe not all the calls below are needed. | ||
imageView.contentMode = UIViewContentModeScaleAspectFit; | ||
imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ); | ||
[self addSubview:imageView]; | ||
imageView.frame = self.bounds; | ||
[imageView setNeedsLayout]; | ||
[self setNeedsLayout]; | ||
|
||
} | ||
|
||
//just in case you want to get the image directly, here it is in subviews | ||
- (UIImage*) image { | ||
UIImageView* iv = [[self subviews] objectAtIndex:0]; | ||
return [iv image]; | ||
} | ||
|
||
@end |
Oops, something went wrong.