let filePath:String = NSHomeDirectory() + "/Documents/sample.txt"
try! json.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8)
let filePath:String = NSHomeDirectory() + "/Documents/sample.txt"
try! json.write(toFile: filePath, atomically: true, encoding: String.Encoding.utf8)
<!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>使用的點圖:
<!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>
<!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>
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">