@@ -609,6 +609,61 @@ var App = (function ($, publ) {
609
609
*/
610
610
publ . setGeocoding = function ( ) {
611
611
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
+ if ( data . result . address ) {
629
+ $ ( "#issue-form #attributes label:contains('現地住所')" ) . parent ( "p" ) . children ( "input" ) . val ( data . result . address ) ;
630
+ }
631
+ else {
632
+ $ ( "#issue-form #attributes label:contains('現地住所')" ) . parent ( "p" ) . children ( "input" ) . val ( "---" ) ;
633
+ }
634
+ } ) ;
635
+ }
636
+ } ) ;
637
+
638
+ }
639
+
640
+ if ( $ ( "#issue-form #attributes button.btn-parksearch" ) . length == 0 ) {
641
+ $ ( "#issue-form #attributes label:contains('公園検索')" ) . parent ( "p" ) . append (
642
+ '<button name="button" type="button" class="btn-parksearch">公園検索</button>'
643
+ ) ;
644
+
645
+ $ ( "button.btn-parksearch" ) . on ( "click" , function ( evt ) {
646
+ if ( vector . getSource ( ) . getFeatures ( ) . length > 0 ) {
647
+ var coords = null
648
+ vector . getSource ( ) . getFeatures ( ) . forEach ( function ( feature ) {
649
+ // Todo: only works with point geometries for now for the last geometry
650
+ coords = feature . getGeometry ( ) . getCoordinates ( ) ;
651
+ } ) ;
652
+ coords = ol . proj . transform ( coords , 'EPSG:3857' , 'EPSG:4326' )
653
+ $ . getJSON ( "http://***REMOVED***/geocoder/service/reversegeocode/json/" + coords . join ( "," ) + ",500?useaddr=true&owner=***REMOVED***&details=true" , function ( data ) {
654
+ if ( data . result . address && data . result . details . id ) {
655
+ $ ( "#issue-form #attributes label:contains('公園検索')" ) . parent ( "p" ) . children ( "input" ) . val (
656
+ "[" + data . result . details . id + "] " + data . result . address
657
+ ) ;
658
+ }
659
+ else {
660
+ $ ( "#issue-form #attributes label:contains('公園検索')" ) . parent ( "p" ) . children ( "input" ) . val ( "---" ) ;
661
+ }
662
+ } ) ;
663
+ }
664
+ } ) ;
665
+ }
666
+
612
667
// Control button
613
668
var geocodingCtrl = new ol . control . Toggle ( {
614
669
html : '<i class="icon-info" ></i>' ,
0 commit comments