Skip to content

Instantly share code, notes, and snippets.

@akari0624
Last active May 8, 2019 11:02
Show Gist options
  • Save akari0624/9e89de8395c8fe9de604683c6e6d94fb to your computer and use it in GitHub Desktop.
Save akari0624/9e89de8395c8fe9de604683c6e6d94fb to your computer and use it in GitHub Desktop.
EmbedMap
var paintLifeCircleOnMap = function(geojsonFilePath, errorCB) {
if (!EmbedMap) {
errorCB("地圖程式未正確載入!");
return;
}
if (geojsonFilePath) {
try {
EmbedMap.clearDrawing();
EmbedMap.addVector({
projection: "EPSG:3826",
url: geojsonFilePath + ".geojson",
id: "myLayer",
callback: LifeCircle2019.setPolygonStyle
});
} catch (err) {
errorCB(err);
}
} else {
errorCB("請選取正確生活圈");
}
};
var LifeCircle2019 = (function() {
return {
setPolygonStyle: function(o) {
EmbedMap.setStyle({
type: "function",
layerId: "myLayer",
// feature 就是 讀取完geojson檔之後 裡面的資料
styleFunction: function(feature, resolution) {
var geometry = feature.getGeometry();
var styles = [
new ol.style.Style({
fill: new parent.ol.style.Fill({
color: "rgba(0, 219, 0, 0.1)"
}),
stroke: new parent.ol.style.Stroke({
color: "rgba(0, 219, 0, 1)",
width: 2
}),
text: new ol.style.Text({
textAlign: "center",
textBaseline: "middle",
font: "bold 14pt Arial",
text: feature.get("label"),
fill: new ol.style.Fill({ color: "#11bf11" }),
stroke: new ol.style.Stroke({ color: "#ffffff", width: 3 })
//offsetX: 15,
//offsetY: -15
})
})
];
return styles;
}
});
setTimeout(function() {
EmbedMap.locateBBOX(
EmbedMap.getLayerById({ id: "myLayer" })
.getSource()
.getSource()
.getExtent()
);
}, 1000);
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment