2020年6月18日

Cordova iOS App not full screen (Cordova 沒有滿版問題)

在 TARGETS >> General 

Deployment Info 
Main Interface >> 選擇「CDVLaunchScreen.storyboard

App Icons and Launch Image
Launch Screen File >> 選擇 「CDVLaunchScreen


第三個 OpenLayers 圖台範例 - Point And Marker。

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        })
      });

      // Your loctations
var locations = [[120.696212,24.261705], [120.771935,24.260560], [120.710195,24.174122 ]]; var polyline = new ol.geom.LineString(locations);
polyline.transform('EPSG:4326', 'EPSG:3857');
// Create feature with polygon.
var feature = new ol.Feature(polyline); // Create vector source and the feature to it.
var vectorSource = new ol.source.Vector();
vectorSource.addFeature(feature); // Create vector layer attached to the vector source.
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(100, 255, 0, 1)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(100, 255, 0, 0.3)'
})
})
}); // Add the vector layer to the map.
map.addLayer(vectorLayer);
      map.getView().setCenter(ol.proj.transform([ 120.696212,24.261705], 'EPSG:4326', 'EPSG:3857'))
      //圖台階層
      map.getView().setZoom(13);

      var coord = ol.proj.transform([120.696212, 24.261705], 'EPSG:4326', 'EPSG:3857');
      var Point = new ol.geom.Point(coord);
      var marker = new ol.Feature({
		geometry:Point
      });
      marker.setStyle(new ol.style.Style({
          image: new ol.style.Icon(({
              color: '#ffcd46',
              crossOrigin: 'anonymous',
              src: 'dot.png'
          }))
      }));
	
      var vectorSource = new ol.source.Vector({
		features: [marker]
      });
	
      var markerVectorLayer = new ol.layer.Vector({
		source: vectorSource,
      });
	
      map.addLayer(markerVectorLayer);

    </script>
  </body>
</html>

使用的點圖:



2020年5月31日

第二個 OpenLayers 圖台範例 - LineString (Polyline)。

參考資料:


<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        })
      });


      // Your loctations var locations = [[120.696212,24.261705], [120.771935,24.260560], [120.710195,24.174122 ]]; var polyline = new ol.geom.LineString(locations); polyline.transform('EPSG:4326', 'EPSG:3857'); // Create feature with polygon. var feature = new ol.Feature(polyline); // Create vector source and the feature to it. var vectorSource = new ol.source.Vector(); vectorSource.addFeature(feature); // Create vector layer attached to the vector source. var vectorLayer = new ol.layer.Vector({ source: vectorSource, style: new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(100, 255, 0, 1)', width: 2 }), fill: new ol.style.Fill({ color: 'rgba(100, 255, 0, 0.3)' }) }) }); // Add the vector layer to the map. map.addLayer(vectorLayer);
      //定位
      map.getView().setCenter(ol.proj.transform([ 120.696212,24.261705], 'EPSG:4326', 'EPSG:3857'))
      //圖台階層
      map.getView().setZoom(13);
    </script>
  </body>
</html>



第一個 OpenLayers 圖台範例 - Polygon。

參考資料:


<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.3.1/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        })
      });


      // Your loctations
      var locations = [[120.696212,24.261705], [120.771935,24.260560], [120.710195,24.174122 ],[120.696212,24.261705]];

      var polygon = new ol.geom.Polygon([locations]);
      polygon.transform('EPSG:4326', 'EPSG:3857');
      // Create feature with polygon.
      var feature = new ol.Feature(polygon);
      // Create vector source and the feature to it.
      var vectorSource = new ol.source.Vector();
      vectorSource.addFeature(feature);
      // Create vector layer attached to the vector source.
      var vectorLayer = new ol.layer.Vector({
        source: vectorSource,
        style: new ol.style.Style({
          stroke: new ol.style.Stroke({
            color: 'rgba(100, 255, 0, 1)',
            width: 2
          }),
          fill: new ol.style.Fill({
            color: 'rgba(100, 255, 0, 0.3)'
          })
        })
      });
      // Add the vector layer to the map.
      map.addLayer(vectorLayer);
      //定位
      map.getView().setCenter(ol.proj.transform([ 120.696212,24.261705], 'EPSG:4326', 'EPSG:3857'))
      //圖台階層
      map.getView().setZoom(13);
    </script>
  </body>
</html>


2020年5月27日

Chrome 出現「NET::ERR_CERT_COMMON_NAME_INVALID」問題。


因我使用的網站並沒有使用憑證,所以,出現「NET::ERR_CERT_COMMON_NAME_INVALID」問題,可以利用下面方式,排除。

1. 在 chrome 上輸入 「chrome://net-internals/#hsts

2. 在 「Delete domain」 的區域輸入 Domain 後,按下 Delete

3. 然後,再至「Query domain」輸入剛剛的 Donaim,按下 Query

4. 出現  Not found,代表修改成功!

2020年5月26日

MSSQL 如何知道 geometry 是什麼坐標系統?


STSrid



參考資料:


如何讓電腦重開後,「啟動」您原本的程式,如 Node js 的 forever 功能啟動。

Node js 的 forever 是一個能讓 Node.js 永不停止的運行即使遇到錯誤崩潰他也能夠及時偵測重新啟動工具。

什麼是 forever 可參考這篇:https://andy6804tw.github.io/2018/01/17/api-forever/

雖然,它是如此的強大,但遇到「電腦重開機」時,它還是無法自動開啟,那可以怎麼做呢?
步驟如下:

1. 建立一個 .vbs 檔案,例如 smallApp.vbs

寫入,假設您要執行的 js 是 server.js

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("cmd.exe /C forever start server.js", 0, true)

2.將寫好的 .vbs 放到 server.js 「同一個資料夾」。(可以點看看,會不會啟動 cmd。)如下圖
 

3.建立「smallApp.vbs」的捷徑,如下圖

4.打開「執行」,輸入「shell:startup


5. 把產出的「捷徑」,放到啟動的資料夾。就大功告成了。











如何於 C# 使用 POINT 加入 Parameters 的方式



SQL 語法宣方式:

geometry::STGeomFromText('POINT('+ @X +' '+ @Y +')', 4326)

加入 Parameters 的方式

db.Parameters.Add("@X", SqlDbType.VarChar, X);
db.Parameters.Add("@Y", SqlDbType.VarChar, Y);

如何使用 MSSQL 取得 geometry Point 是否位於 Polygon 內?

使用 STContains 而不是 STWithin 

範例如下:

SELECT [ogr_fid]
      ,[geometry]
      ,[countyid]
      ,[countyname]
      ,[COUNTY_CODE] 
  FROM [WraLandMap].[dbo].[map_county] 
  where geometry::STGeomFromText([geometry].STAsText( ), 4326).MakeValid().STContains(geometry::STGeomFromText('POINT(277466 2681304)', 4326))  = 1





2020年5月7日

WPF DatePicker 如何 修改為 民國年 顯示。


於 InitializeComponent(); 之後加入:


CultureInfo cui = new CultureInfo("zh-TW", true);
cui.DateTimeFormat.Calendar = new TaiwanCalendar();
Thread.CurrentThread.CurrentCulture = cui;

2020年2月12日

Arduino float to String 方法

  float lat = 32.123456;
  float long = 21.121232;
  String str;
  str += "經緯度 \nlat:";
  str += String(latitude, 6);
  str += "\nlong:";
  str += String(longitude, 6);
  Serial.println(str);

2020年2月4日

Swift UITextView 於 .xib 加入框線、圓角


User Defined Runtime AttributesKey Path
加入

layer.cornerRadius

layer. borderUIColor

layer.borderWidth

如下圖:







雖然,修改後,在 .xib 上無法馬上看到修改後的畫面,但經過 complier 到手機或模擬器上就可以清楚看到。

2020年2月3日

Javascript String to Date 出現 Invalid Date 錯誤!

對某些瀏覽器 String 轉成 Date 時,會出現 Invalid Date 的錯誤!

例如:
var dateString = "2020-01-01 01:23:45";
var datetime = new Date(dateString);

//此時,有些瀏覽器,就無法正常轉換,可以使用以下做法。

var dateString = "2020-01-01 01:23:45";
var newDateString = dateString.replace(/-/g,'/'); // 變成"2020/01/01 01:23:45";
var datetime = new Date(newDateString); //就可以正常轉換了


2020年1月8日

Swift google map InfoWindow Open


        let marker = GMSMarker()

        marker.position = CLLocationCoordinate2D(latitude: 23.963, longitude: 120.522)

        marker.title = "所在區域"

        marker.isDraggable = true

        marker.snippet = "X:23.963 \n Y:120.522"

        marker.tracksInfoWindowChanges = true

        marker.map = googleMapView

        googleMapView.selectedMarker = marker //InfoWindow Open

2020年1月3日

MSSQL 異地備份

127.0.0.1 : IP
DataTransfer :  要備份的資料庫名稱

DECLARE @FilePath VARCHAR(200)
SET @FilePath = N'\\127.0.0.1\Database_Backup\DB_' + (CONVERT(VARCHAR(8), GETDATE(), 112) +REPLACE(CONVERT(VARCHAR(5), GETDATE(), 114), ':', ''))+'.bak'
BACKUP DATABASE DataTransfer 
TO  DISK = @FilePath WITH NOFORMAT, NOINIT, 
NAME = N'Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO

MSSQL 自動備份語法! 非使用「維護計畫」


DataTransfer  :  資料庫名稱
Database_Backup  :  需自行建立資料夾  

可以寫在排程上。

以下語法:

GO
DECLARE
@backupTime VARCHAR(20)
DECLARE
@fileName VARCHAR(1000)
SELECT
@backupTime=(CONVERT(VARCHAR(8), GETDATE(), 112) +REPLACE(CONVERT(VARCHAR(5), GETDATE(), 114), ':', ''))
SELECT
@fileName='C:\Database_Backup\DB_'+@backupTime+'.bak'
backup database DataTransfer to disk=@fileName

GO


2019年11月28日

Swift 建立等待畫面


self.showSpinner(onView: self.view,title : "取得資料中,請稍候!")
        
        let seconds = 1.0
        DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
            // Put your code which should be executed with a delay here
            self.removeSpinner()

        }



///等待的畫面,參考資料 http://brainwashinc.com/2017/07/21/loading-activity-indicator-ios-swift/
var vSpinner : UIView?

extension UIViewController {
    func showSpinner(onView : UIView,title:String) {
        let spinnerView = UIView.init(frame: onView.bounds)
        spinnerView.backgroundColor = UIColor.init(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)
        let ai = UIActivityIndicatorView.init(style: .whiteLarge)
        ai.startAnimating()
        ai.center = spinnerView.center
        
        
        DispatchQueue.main.async {
            spinnerView.addSubview(ai)
            onView.addSubview(spinnerView)
        }
        
        vSpinner = spinnerView
    }
    
    func removeSpinner() {
        DispatchQueue.main.async {
            vSpinner?.removeFromSuperview()
            vSpinner = nil
        }
    }
}

2019年11月18日

Node js 出現 unable to get local issuer certificate 錯誤,不安全做法

如出現以上問題: unable to get local issuer certificate 

可以參考以下連結 :
https://blog.darkthread.net/blog/npm-unable-get-local-issuer-cert-issue/

不安全的方式可以於 app.listen 使用加入:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;