Re: Cache problems with jxmapviewer2 in NetBeans Platform

Patrik Karlsson <[email protected]> Tue, 13 Jun 2017 20:07:05 +0200
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CANiFHSHiPxUf9e=nvQtP4LDp_T0gGQp90wm8GHw_H_eF8_BvWQ@mail.gmail.com>
Thank you, much appreciated!

2017-06-04 20:22 GMT+02:00 geertjan wielenga <[email protected]>:

>
> Don't know why it doesn't work in NetBeans Platform applications, though I
> can reproduce it.
>
> A workaround is to override TileFactory.setTileCache:
>
>
> tileFactory.setTileCache(new TileCache() {
>     @Override
>     public void put(URI uri, byte[] bimg, BufferedImage bi) {
>         try {
>             super.put(uri, bimg, bi);
>             int index = uri.toString().lastIndexOf("/");
>             String name = uri.toString().substring(index+1);
>             File outputfile = new File(cacheDir+"/"+name);
>             ImageIO.write(bi, "png", outputfile);
>         } catch (IOException ex) {
>             Exceptions.printStackTrace(ex);
>         }
>     }
> });
>
> It's not perfect, but a start, and evidence that caching can work, if you
> set it explicitly.
>
> Gj
>
>
>
> On 4-6-2017 13:26, geertjan wielenga wrote:
>
>>
>> Maybe this will help:
>>
>> https://github.com/mitll/vizlinc/blob/master/vizlinc_module/
>> src/edu/mit/ll/vizlinc/components/MapTopComponent.java
>>
>> Looks like an interesting NetBeans Platform project:
>>
>> https://github.com/mitll/vizlinc
>>
>> Gj
>>
>>
>> On 4-6-2017 12:53, geertjan wielenga wrote:
>>
>>>
>>>
>>> On 15-5-2017 13:06, Patrik Karlsson wrote:
>>>
>>>> Hi,
>>>>
>>>> I'm building a platform application using jxmapviewer2
>>>> https://github.com/msteiger/jxmapviewer2 and can't get the caching to
>>>> work. The map renders just fine but the tiles are not cached.
>>>>
>>>> Caching works in the example
>>>> https://github.com/msteiger/jxmapviewer2/blob/master/example
>>>> s/src/sample3_interaction/Sample3.java
>>>>
>>>> and I have sucessfully added caching to MapKit in Sample6
>>>> https://github.com/msteiger/jxmapviewer2/blob/master/example
>>>> s/src/sample6_mapkit/Sample6.java
>>>>
>>>
>>> There is no cache in the above sample.
>>>
>>> Gj
>>>
>>>
>>>
>>>> However, it fails when I try to do it in NB 8.2 platform using Windows
>>>> 7 and Java 8u131.
>>>> The cache directory gets created but is always empty.
>>>>
>>>> Could this be related to the platform and the usage of
>>>> java.net.ResponseCache?
>>>>
>>>>
>>>> I have created the following repo https://github.com/trixon/netb
>>>> eans-jxmapviewer2.git
>>>> The map related code is in https://github.com/trixon/netbeans-
>>>> jxmapviewer2/blob/master/maptest/src/main/java/se/trixon/
>>>> jxmapviewer2/maptest/MapKitTopComponent.java
>>>>
>>>>     private void init() {
>>>>         setLayout(new java.awt.GridLayout());
>>>>         final JXMapKit jXMapKit = new JXMapKit();
>>>>         TileFactoryInfo info = new OSMTileFactoryInfo();
>>>>         DefaultTileFactory tileFactory = new DefaultTileFactory(info);
>>>>
>>>>         // Setup local file cache
>>>>         File cacheDir = new File(System.getProperty("user.home") +
>>>> File.separator + ".jxmapviewer2");
>>>> LocalResponseCache.installResponseCache(info.getBaseURL(), cacheDir,
>>>> false);
>>>>
>>>>         jXMapKit.setTileFactory(tileFactory);
>>>>
>>>>         jXMapKit.setZoom(16);
>>>>         add(jXMapKit);
>>>>     }
>>>>
>>>> /Patrik
>>>>
>>>
>>>
>>
>