Преглед изворни кода

添加支持本地缓存的地图瓦片层

Ray Zhang пре 6 година
родитељ
комит
966917e1aa

+ 16 - 4
Apex Mobile/Apex Mobile.xcodeproj/project.pbxproj

@@ -7,6 +7,8 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		3C0F4E9423BAE74F000A2FE7 /* CachedTileOverlay.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C0F4E9323BAE74F000A2FE7 /* CachedTileOverlay.m */; };
+		3C0F4E9723BAF594000A2FE7 /* FileCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C0F4E9623BAF594000A2FE7 /* FileCache.m */; };
 		3C1DEC3D239F6C42006F7E2A /* MKMapView+ZoomLevel.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C1DEC3B239F6C42006F7E2A /* MKMapView+ZoomLevel.m */; };
 		3C2D99A2239B92F1007B759E /* ApexMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C2D99A0239B92F1007B759E /* ApexMapView.m */; };
 		3C2D99A5239B93C8007B759E /* AMViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C2D99A4239B93C8007B759E /* AMViewController.m */; };
@@ -45,7 +47,6 @@
 		425390262079B9B500ECF982 /* KPI.json in Resources */ = {isa = PBXBuildFile; fileRef = 425390252079B9B400ECF982 /* KPI.json */; };
 		42539029207A159300ECF982 /* KPIButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 42539028207A159300ECF982 /* KPIButton.m */; };
 		42541ACF207C49610072BC5A /* fake_home.json in Resources */ = {isa = PBXBuildFile; fileRef = 42541ACE207C49610072BC5A /* fake_home.json */; };
-		425660DB202015E1002DB0CA /* Launch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 425660DA202015E1002DB0CA /* Launch.storyboard */; };
 		425CF096201EB2B500750E32 /* JLRefreshFooter.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF08C201EB2B500750E32 /* JLRefreshFooter.m */; };
 		425CF097201EB2B500750E32 /* JLRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF08F201EB2B500750E32 /* JLRefreshHeader.m */; };
 		425CF098201EB2B500750E32 /* JLRefreshBasis.m in Sources */ = {isa = PBXBuildFile; fileRef = 425CF091201EB2B500750E32 /* JLRefreshBasis.m */; };
@@ -208,6 +209,10 @@
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
+		3C0F4E9223BAE74F000A2FE7 /* CachedTileOverlay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CachedTileOverlay.h; path = ../../common/ApexMap/CachedTileOverlay.h; sourceTree = "<group>"; };
+		3C0F4E9323BAE74F000A2FE7 /* CachedTileOverlay.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = CachedTileOverlay.m; path = ../../common/ApexMap/CachedTileOverlay.m; sourceTree = "<group>"; };
+		3C0F4E9523BAF594000A2FE7 /* FileCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileCache.h; path = ../../common/FileCache.h; sourceTree = "<group>"; };
+		3C0F4E9623BAF594000A2FE7 /* FileCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileCache.m; path = ../../common/FileCache.m; sourceTree = "<group>"; };
 		3C1DEC3B239F6C42006F7E2A /* MKMapView+ZoomLevel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "MKMapView+ZoomLevel.m"; path = "../../common/ApexMap/MKMapView+ZoomLevel.m"; sourceTree = "<group>"; };
 		3C1DEC3C239F6C42006F7E2A /* MKMapView+ZoomLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "MKMapView+ZoomLevel.h"; path = "../../common/ApexMap/MKMapView+ZoomLevel.h"; sourceTree = "<group>"; };
 		3C2D99A0239B92F1007B759E /* ApexMapView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ApexMapView.m; path = ../../common/ApexMap/ApexMapView.m; sourceTree = "<group>"; };
@@ -273,7 +278,6 @@
 		42539027207A159300ECF982 /* KPIButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPIButton.h; sourceTree = "<group>"; };
 		42539028207A159300ECF982 /* KPIButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KPIButton.m; sourceTree = "<group>"; };
 		42541ACE207C49610072BC5A /* fake_home.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = fake_home.json; sourceTree = "<group>"; };
-		425660DA202015E1002DB0CA /* Launch.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Launch.storyboard; sourceTree = "<group>"; };
 		425CF08B201EB2B500750E32 /* JLRefreshFooter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JLRefreshFooter.h; sourceTree = "<group>"; };
 		425CF08C201EB2B500750E32 /* JLRefreshFooter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JLRefreshFooter.m; sourceTree = "<group>"; };
 		425CF08E201EB2B500750E32 /* JLRefreshHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JLRefreshHeader.h; sourceTree = "<group>"; };
@@ -1072,6 +1076,8 @@
 		719A51AC18C5A6A80080C075 /* Location */ = {
 			isa = PBXGroup;
 			children = (
+				3C0F4E9223BAE74F000A2FE7 /* CachedTileOverlay.h */,
+				3C0F4E9323BAE74F000A2FE7 /* CachedTileOverlay.m */,
 				3C2D99A1239B92F1007B759E /* ApexMapView.h */,
 				3C2D99A0239B92F1007B759E /* ApexMapView.m */,
 				3C1DEC3C239F6C42006F7E2A /* MKMapView+ZoomLevel.h */,
@@ -1184,6 +1190,8 @@
 		719E7E2D18C01555003408FF /* utils */ = {
 			isa = PBXGroup;
 			children = (
+				3C0F4E9523BAF594000A2FE7 /* FileCache.h */,
+				3C0F4E9623BAF594000A2FE7 /* FileCache.m */,
 				719E7E3118C0368A003408FF /* ApexMobileDB.h */,
 				719E7E3218C0368A003408FF /* ApexMobileDB.m */,
 				71A565DD18C212EA00CDAC07 /* Constant.h */,
@@ -1196,7 +1204,6 @@
 			isa = PBXGroup;
 			children = (
 				3CA1A2DD23A212E700639FCC /* Launch Screen.storyboard */,
-				425660DA202015E1002DB0CA /* Launch.storyboard */,
 				427994B120300E7300746EDC /* Apex Mobile.entitlements */,
 				719EF8E618BB839F00EFFF5F /* Apex Mobile */,
 				719EF90B18BB839F00EFFF5F /* Apex MobileTests */,
@@ -1461,7 +1468,6 @@
 				714C39BF19234065004F045B /* Localizable.strings in Resources */,
 				427CF5D02023F5560041472A /* NewImages.xcassets in Resources */,
 				4225E42621E08576009D2364 /* ApexResult.storyboard in Resources */,
-				425660DB202015E1002DB0CA /* Launch.storyboard in Resources */,
 				42E8212F21F6ED1800127705 /* ApexResultAdditionView.xib in Resources */,
 				420DEF2720A1898500720524 /* AMCommHeadCell.xib in Resources */,
 				42BB740B2084737800B9B6E4 /* KPILegendCell.xib in Resources */,
@@ -1493,7 +1499,9 @@
 				718BE8B2190F9D970046EA6A /* MyAutocompleteItemsSource.m in Sources */,
 				71406DCE18C36A52000914C4 /* TableCellBool.m in Sources */,
 				426E8ABD2021AEC50073BA5D /* JLCustomerNavigationAlertController.m in Sources */,
+				3C0F4E9423BAE74F000A2FE7 /* CachedTileOverlay.m in Sources */,
 				71A01D7F18C9AEC8003307A9 /* DetailCellWeb.m in Sources */,
+				3C0F4E9723BAF594000A2FE7 /* FileCache.m in Sources */,
 				71A01D8518C9BDC8003307A9 /* DetailTabBarController.m in Sources */,
 				71F67CFC19066375004E8462 /* PulldownMenu.m in Sources */,
 				71406DD118C36A6E000914C4 /* TableCellDate.m in Sources */,
@@ -1773,6 +1781,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
+				CURRENT_PROJECT_VERSION = 191231;
 				DEVELOPMENT_TEAM = "";
 				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -1788,6 +1797,7 @@
 				HEADER_SEARCH_PATHS = "";
 				INFOPLIST_FILE = "Apex Mobile/Apex Mobile-Info.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
+				MARKETING_VERSION = 2.80;
 				OTHER_LDFLAGS = "-ObjC";
 				PRODUCT_BUNDLE_IDENTIFIER = "usai.apex.$(PRODUCT_NAME:rfc1034identifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1810,6 +1820,7 @@
 				CODE_SIGN_IDENTITY = "iPhone Distribution";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				CODE_SIGN_STYLE = Automatic;
+				CURRENT_PROJECT_VERSION = 191231;
 				DEVELOPMENT_TEAM = "";
 				ENABLE_BITCODE = YES;
 				FRAMEWORK_SEARCH_PATHS = (
@@ -1821,6 +1832,7 @@
 				HEADER_SEARCH_PATHS = "";
 				INFOPLIST_FILE = "Apex Mobile/Apex Mobile-Info.plist";
 				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
+				MARKETING_VERSION = 2.80;
 				OTHER_LDFLAGS = "-ObjC";
 				PRODUCT_BUNDLE_IDENTIFIER = "usai.apex.$(PRODUCT_NAME:rfc1034identifier)";
 				PRODUCT_NAME = "$(TARGET_NAME)";

+ 2 - 2
Apex Mobile/Apex Mobile/AMMapView.h

@@ -7,7 +7,7 @@
 //
 
 #import <MapKit/MapKit.h>
-
-@interface AMMapView : MKMapView
+#import "ApexMapView.h"
+@interface AMMapView : ApexMapView
 
 @end

+ 4 - 4
Apex Mobile/Apex Mobile/Apex Mobile-Info.plist

@@ -17,11 +17,11 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>2.70</string>
+	<string>$(MARKETING_VERSION)</string>
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>CFBundleVersion</key>
-	<string>190419</string>
+	<string>$(CURRENT_PROJECT_VERSION)</string>
 	<key>LSRequiresIPhoneOS</key>
 	<true/>
 	<key>NSAppTransportSecurity</key>
@@ -41,8 +41,6 @@
 	<string>Launch Screen</string>
 	<key>UIMainStoryboardFile</key>
 	<string>Main</string>
-	<key>UIMainStoryboardFile~ipad</key>
-	<string>Main_iPhone</string>
 	<key>UIRequiredDeviceCapabilities</key>
 	<array>
 		<string>armv7</string>
@@ -68,5 +66,7 @@
 		<string>UIInterfaceOrientationLandscapeLeft</string>
 		<string>UIInterfaceOrientationLandscapeRight</string>
 	</array>
+	<key>UIUserInterfaceStyle</key>
+	<string>Light</string>
 </dict>
 </plist>

+ 1 - 1
Apex Mobile/Apex Mobile/LocationViewController.m

@@ -836,7 +836,7 @@
 
 //当MKMapView显示区域改变完成时激发该方法
 -(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
-NSLog(@"地图控件完成了改变");
+//NSLog(@"地图控件完成了改变");
 
 }
 

+ 0 - 29
Apex Mobile/Launch.storyboard

@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
-    <device id="retina4_7" orientation="portrait">
-        <adaptation id="fullscreen"/>
-    </device>
-    <dependencies>
-        <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
-        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
-        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
-    </dependencies>
-    <scenes>
-        <!--View Controller-->
-        <scene sceneID="XyC-Av-ghC">
-            <objects>
-                <viewController storyboardIdentifier="launch_vc" useStoryboardIdentifierAsRestorationIdentifier="YES" id="urU-mG-k2m" sceneMemberID="viewController">
-                    <view key="view" contentMode="scaleToFill" id="c56-wu-QAG">
-                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
-                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                        <color key="backgroundColor" red="0.18151141800000001" green="1" blue="0.69469557609999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
-                        <viewLayoutGuide key="safeArea" id="8TE-3E-snY"/>
-                    </view>
-                </viewController>
-                <placeholder placeholderIdentifier="IBFirstResponder" id="ut4-cr-xUh" userLabel="First Responder" sceneMemberID="firstResponder"/>
-            </objects>
-            <point key="canvasLocation" x="210" y="121"/>
-        </scene>
-    </scenes>
-</document>

+ 1 - 1
common/ApexMap/ApexMapView.h

@@ -10,6 +10,6 @@
 #import "MKMapView+ZoomLevel.h"
 
 @interface ApexMapView : MKMapView
-- (double )zoomLevel;
+//- (double )zoomLevel;
 @end
 

+ 9 - 4
common/ApexMap/ApexMapView.m

@@ -8,6 +8,7 @@
 
 #import "ApexMapView.h"
 #import "UIView+RAConstraint.h"
+#import "CachedTileOverlay.h"
 
 //static NSString * const kTileSource = @"https://map.apexshipping.com/osm_tiles/{z}/{x}/{y}.png";
 //static NSString * const kTileSource = @"https://map.apexshipping.com/osmmt/{z}/{x}/{y}.png";
@@ -19,7 +20,7 @@ static NSString * const kCopyright = @"OpenStreetMap";
 @interface ApexMapView () <MKMapViewDelegate>
 
 @property (nonatomic,strong) UIButton *legalBtn;
-@property (nonatomic,strong) MKTileOverlay *tileOverlay;
+@property (nonatomic,strong) CachedTileOverlay *tileOverlay;
 @property (nonatomic,weak) id<MKMapViewDelegate> internalDelegate;
 
 @end
@@ -45,6 +46,10 @@ static NSString * const kCopyright = @"OpenStreetMap";
     self.rotateEnabled = NO;
     [self apex_setDelegate:self];
     
+    self.backgroundColor = [UIColor redColor];
+    
+    
+//    self.showsLargeContentViewer=false;
     [self addOverlay:self.tileOverlay];
     
 //        if (@available(iOS 13.0, *)) {
@@ -125,7 +130,7 @@ static NSString * const kCopyright = @"OpenStreetMap";
 
 - (MKTileOverlay *)tileOverlay {
     if (!_tileOverlay) {
-        _tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:kTileSource];
+        _tileOverlay = [[CachedTileOverlay alloc] initWithURLTemplate:kTileSource];
         _tileOverlay.canReplaceMapContent = YES;
         _tileOverlay.minimumZ = 0;
         _tileOverlay.maximumZ = 18;
@@ -176,11 +181,11 @@ static NSString * const kCopyright = @"OpenStreetMap";
 
     int y= floor((1 - log(tan(mapView.centerCoordinate.latitude * pi / 180) + 1 / cos(mapView.centerCoordinate.latitude * pi / 180)) / pi) / 2 * pow(2 , z));
 
-        NSLog(@"地图控件完成了改变 x:%d,y:%d,z:%f",x,y,z);
+//        NSLog(@"地图控件完成了改变 x:%d,y:%d,z:%f",x,y,z);
     if(mapView.zoomLevel>18)
     {
         
-        NSLog(@"地图控件完成了改变 zoom to 18");
+//        NSLog(@"地图控件完成了改变 zoom to 18");
         [mapView setCenterCoordinate:mapView.centerCoordinate zoomLevel:18 animated:true];
 
     }

+ 17 - 0
common/ApexMap/CachedTileOverlay.h

@@ -0,0 +1,17 @@
+//
+//  CachedTileOverlay.h
+//  Apex Mobile
+//
+//  Created by Rui Zhang on 12/31/19.
+//  Copyright © 2019 United Software Applications, Inc. All rights reserved.
+//
+
+#import <MapKit/MapKit.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface CachedTileOverlay : MKTileOverlay
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 77 - 0
common/ApexMap/CachedTileOverlay.m

@@ -0,0 +1,77 @@
+//
+//  CachedTileOverlay.m
+//  Apex Mobile
+//
+//  Created by Rui Zhang on 12/31/19.
+//  Copyright © 2019 United Software Applications, Inc. All rights reserved.
+//
+
+#import "CachedTileOverlay.h"
+#import "FileCache.h"
+@implementation CachedTileOverlay
+- (void)loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData * _Nullable, NSError * _Nullable))result
+{
+    
+    if (!result)
+    {
+        return;
+    }
+    
+    NSURL* url=[self URLForTilePath:path];
+    NSString* img_url = [url absoluteString];
+    NSString* file_name=[img_url lastPathComponent];
+
+    NSData *cachedData = [FileCache load_cached_img:file_name loadFrom:img_url];
+    if (cachedData)
+    {
+        result(cachedData, nil);
+    }
+    else
+    {
+        
+        
+        NSLog(@"load image");
+        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+            
+//            NSData*  downloadimg_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:img_url]];
+            NSError* error;
+            NSData*  downloadimg_data = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&error];
+            dispatch_async(dispatch_get_main_queue(), ^{
+                
+                
+                
+                if(downloadimg_data!=nil)
+                {
+                    
+                    [FileCache cache_img:downloadimg_data filename:file_name saveTo:img_url];
+                    
+//                    UIImage * img =[UIImage imageWithData:downloadimg_data];
+//                    cell.cellImageView.image = img;
+                }
+                
+                result(downloadimg_data, error);
+//                else
+//                    cell.cellImageView.image = [UIImage imageNamed:notFound];
+                
+            });
+        });
+        
+        
+//        NSURLRequest *request = [NSURLRequest requestWithURL:[self URLForTilePath:path]];
+//        [NSURLConnection sendAsynchronousRequest:request queue:self.operationQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
+//            // Should inspect the response to see if the request completed successfully!!
+//            [self.cache setObject:data forKey:[self URLForTilePath:path]];
+//            result(data, connectionError);
+//        }];
+    }
+    
+    
+    
+    
+    
+//
+//    NSLog(@"%@",url);
+////    NSLog(@"%ld,%ld,%ld",path.x,path.y,path.z);
+//    [super loadTileAtPath:path result:result];
+}
+@end