@@ -38,7 +38,9 @@ var App = (function ($, publ) {
38
38
lon : 139.691706 ,
39
39
lat : 35.689524 ,
40
40
zoom : 13 ,
41
- maxzoom : 19
41
+ maxzoom : 19 ,
42
+ geocoderAddress : "現地住所" ,
43
+ geocoderDistrict : "区名"
42
44
} ;
43
45
44
46
/**
@@ -72,6 +74,12 @@ var App = (function ($, publ) {
72
74
if ( defaults . maxzoom == null ) {
73
75
defaults . maxzoom = quick_hack . maxzoom ;
74
76
}
77
+ if ( defaults . geocoderAddress == null ) {
78
+ defaults . geocoderAddress = quick_hack . geocoderAddress ;
79
+ }
80
+ if ( defaults . geocoderDistrict == null ) {
81
+ defaults . geocoderDistrict = quick_hack . geocoderDistrict ;
82
+ }
75
83
76
84
if ( contents . geom && contents . geom !== null ) {
77
85
features = new ol . format . GeoJSON ( ) . readFeatures (
@@ -592,7 +600,7 @@ var App = (function ($, publ) {
592
600
// Hack to add Geocoding buttons to text fields
593
601
// There should be a better way to do this
594
602
if ( $ ( "#issue-form #attributes button.btn-geocode" ) . length == 0 ) {
595
- $ ( "#issue-form #attributes label:contains('現地住所 ')" ) . parent ( "p" ) . append (
603
+ $ ( "#issue-form #attributes label:contains('" + defaults . geocoderAddress + " ')") . parent ( "p" ) . append (
596
604
'<button name="button" type="button" class="btn-geocode">住所検索</button>'
597
605
) ;
598
606
@@ -605,11 +613,25 @@ var App = (function ($, publ) {
605
613
} ) ;
606
614
coords = ol . proj . transform ( coords , 'EPSG:3857' , 'EPSG:4326' )
607
615
$ . getJSON ( "https://***REMOVED***/reversegeocode/json/" + coords . join ( "," ) + ",1000" , function ( data ) {
616
+ var addressInput = $ ( "#issue-form #attributes label:contains('" + defaults . geocoderAddress + "')" ) . parent ( "p" ) . children ( "input" ) ;
617
+ var districtInput = $ ( "#issue-form #attributes label:contains('" + defaults . geocoderDistrict + "')" ) . parent ( "p" ) . children ( "input" ) ;
618
+ var foundDistrict = false ;
608
619
if ( data . result . address ) {
609
- $ ( "#issue-form #attributes label:contains('現地住所')" ) . parent ( "p" ) . children ( "input" ) . val ( data . result . address ) ;
620
+ addressInput . val ( data . result . address ) ;
621
+ if ( districtInput && data . result . shikuchoson ) {
622
+ var regexp = / ^ \S + 市 ( \S + 区 ) $ / g;
623
+ var match = regexp . exec ( data . result . shikuchoson ) ;
624
+ if ( match && match . length === 2 ) {
625
+ districtInput . val ( match [ 1 ] ) ;
626
+ foundDistrict = true ;
627
+ }
628
+ }
610
629
}
611
630
else {
612
- $ ( "#issue-form #attributes label:contains('現地住所')" ) . parent ( "p" ) . children ( "input" ) . val ( "---" ) ;
631
+ addressInput . val ( "---" ) ;
632
+ }
633
+ if ( ! foundDistrict ) {
634
+ districtInput . val ( "" ) ;
613
635
}
614
636
} ) ;
615
637
}
0 commit comments