Skip to content

Commit 115a4c9

Browse files
committed
Adds geocoding for custom field address and place search
TODO: change to place search API
1 parent 032ee3e commit 115a4c9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

assets/javascripts/app.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,49 @@ var App = (function ($, publ) {
609609
*/
610610
publ.setGeocoding = function (){
611611

612+
// Hack to add Geocoding buttons to text fields
613+
// There should be a better way to do this
614+
if ( $("#issue-form #attributes button.btn-geocode").length == 0 ) {
615+
$("#issue-form #attributes label:contains('現地住所')").parent("p").append(
616+
'<button name="button" type="button" class="btn-geocode">住所検索</button>'
617+
);
618+
619+
$("button.btn-geocode").on("click", function(evt) {
620+
if (vector.getSource().getFeatures().length > 0) {
621+
var coords = null
622+
vector.getSource().getFeatures().forEach(function (feature) {
623+
// Todo: only works with point geometries for now for the last geometry
624+
coords = feature.getGeometry().getCoordinates();
625+
});
626+
coords = ol.proj.transform(coords,'EPSG:3857','EPSG:4326')
627+
$.getJSON("https://***REMOVED***/reversegeocode/json/" + coords.join(",") + ",1000", function(data) {
628+
$("#issue-form #attributes label:contains('現地住所')").parent("p").children("input").val(data.result.address);
629+
});
630+
}
631+
});
632+
633+
}
634+
635+
if ( $("#issue-form #attributes button.btn-parksearch").length == 0 ) {
636+
$("#issue-form #attributes label:contains('公園検索')").parent("p").append(
637+
'<button name="button" type="button" class="btn-parksearch">公園検索</button>'
638+
);
639+
640+
$("button.btn-parksearch").on("click", function(evt) {
641+
if (vector.getSource().getFeatures().length > 0) {
642+
var coords = null
643+
vector.getSource().getFeatures().forEach(function (feature) {
644+
// Todo: only works with point geometries for now for the last geometry
645+
coords = feature.getGeometry().getCoordinates();
646+
});
647+
coords = ol.proj.transform(coords,'EPSG:3857','EPSG:4326')
648+
$.getJSON("https://***REMOVED***/reversegeocode/json/" + coords.join(",") + ",1000", function(data) {
649+
$("#issue-form #attributes label:contains('公園検索')").parent("p").children("input").val(data.result.address);
650+
});
651+
}
652+
});
653+
}
654+
612655
// Control button
613656
var geocodingCtrl = new ol.control.Toggle({
614657
html: '<i class="icon-info" ></i>',

0 commit comments

Comments
 (0)