You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@isis.apache.org by Dan Haywood <da...@haywood-associates.co.uk> on 2014/02/18 08:36:30 UTC
Re: isis-wicket-gmap3
Hi Michal,
(I'm cc'ing the Isis users list, since this might be of interest more
generally).
On 16 February 2014 16:13, Michal Vaško <mi...@gmail.com> wrote:
>
> Yes I read LocationLookupService.java<https://github.com/danhaywood/isis-wicket-gmap3/blob/master/service/src/main/java/com/danhaywood/isis/wicket/gmap3/service/LocationLookupService.java> class
> but if I understood well this class have one input text and return one
> output long and latit.
>
> I need UI component where If I start write for example "Ko" component
> autocomplete Kos - Grece, Kooskia - US . Kosice - Slovakia .... and more
> ...
>
> After when user select one item on this component is it possible to use
> your location service. Your api have similar component like
> google.maps.places.Autocomplete ui component? or google map only ?
>
I think that what you want *could* be achieved using an "Address" view
model, an autoComplete lookup and an extension to LocationLookupService to
call the appropriate API. However, reading the docs for the geocoding
service [1] (that LocationLookupService calls), they say that the service
is only intended for server-side lookup, not for UI widgets. For that,
they point over to a Javascript component [2].
Integrating a new Javascript component into Wicket viewer is certainly
doable, but would take more work, I think. If you want to try developing
it, I'll give you some hints.
But, if you do want to (ab)use the existing server-side geocoding service
(beware of quotas), then you could use the following code:
*Address (just a simple wrapper around a string):*
import org.apache.isis.applib.AbstractViewModel;
import org.apache.isis.applib.annotation.AutoComplete;
import org.apache.isis.applib.annotation.Title;
@AutoComplete(repository=Addresses.class)
public class Address extends AbstractViewModel {
@Override
public String viewModelMemento() {
return addresses.mementoFor(getDescription());
}
@Override
public void viewModelInit(String memento) {
setDescription(addresses.descriptionFrom(memento));
}
// //////////////////////////////////////
private String description;
@Title
public String getDescription() {
return description;
}
public void setDescription(String address) {
this.description = address;
}
// //////////////////////////////////////
@javax.inject.Inject
private Addresses addresses;
}
*Addresses:*
import java.util.List;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.apache.isis.applib.DomainObjectContainer;
import org.apache.isis.applib.services.memento.MementoService;
public class Addresses {
public List<Address> autoComplete(String address) {
// TODO: hit a new method in the LocationLookupService that hits
the relevant API of the geocoding service here, to retrieve an array of
address descriptions...
final List<String> addressDescriptions = ...;
// wrap each in an Address view model
return Lists.transform(addressDescriptions, new Function<String,
Address>() {
@Override
public Address apply(String desc) {
return newAddress(desc);
}
});
}
private Address newAddress(String description) {
return container.newViewModelInstance(Address.class,
mementoFor(description));
}
// //////////////////////////////////////
String mementoFor(String description) {
return mementoService.create().set("description",
description).asString();
}
String descriptionFrom(String memento) {
return mementoService.parse(memento).get("description",
String.class);
}
// //////////////////////////////////////
@javax.inject.Inject
private DomainObjectContainer container;
@javax.inject.Inject
private MementoService mementoService;
}
*Usage:*
public ToDoItem updateLocation(@Named("Address") final Address address)
{
final Location location =
this.locationLookupService.lookup(address.getDescription());
setLocation(location);
return this;
}
HTH
Dan
[1] https://developers.google.com/maps/documentation/geocoding/
[2] https://developers.google.com/maps/documentation/javascript/geocoding
> Many thanks !
>
>
>
> 2014-02-16 17:05 GMT+01:00 Michal Vaško <mi...@gmail.com>:
>
>
>>
>> 2014-02-16 16:57 GMT+01:00 Dan Haywood <da...@haywood-associates.co.uk>:
>>
>>
>>>
>>>
>>> On 15 February 2014 20:59, Michal Vaško <mi...@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> Hi Michal, welcome to the mailing list
>>>
>>>
>>>
>>>> I start created wicket application
>>>>
>>>
>>>
>>> ... good to hear....
>>>
>>>
>>>
>>>> and now a need something like google.maps.places.Autocomplete, I need
>>>> select some city. Is it suport in your wicket api?
>>>>
>>>
>>> I presume you are using the gmap3 extension [1] ? As well as providing
>>> the UI extension to the Wicket viewer, it also has a LocationLookupService
>>> [2] which does a search based upon a freetext description... perhaps this
>>> is what you are after?
>>>
>>> Cheers
>>> Dan
>>>
>>> [1] https://github.com/danhaywood/isis-wicket-gmap3
>>> [2]
>>> https://github.com/danhaywood/isis-wicket-gmap3/blob/master/service/src/main/java/com/danhaywood/isis/wicket/gmap3/service/LocationLookupService.java
>>>
>>>
>>>
>>>> Many thanks.
>>>>
>>>
>>>
>>>
>>>> --
>>>> S pozdravom Michal Vasko
>>>>
>>>
>>>
>>
>>
>> --
>> S pozdravom Michal Vasko
>>
>
>
>
> --
> S pozdravom Michal Vasko
>