maps:mapView using EPSG:21781 instead of EPSG:4326

Dear All

Is it possible to get a sample how to use custom projection. We need EPSG:21781 instead of EPSG:4326.

The used JMIX Library does support this https://epsg.io/21781-to-4326.

It would be great to have the map sample project extended by this.

Thank you

Felix

Hello!

While preparing sample project found out that there is an issue with custom projection. Unfortunately it is not applied and I created an issue: Custom projection is not applied in Map component · Issue #2984 · jmix-framework/jmix · GitHub

It will be fixed in the next bugfix release.

About how to set custom projection. You can follow these steps after the issue will be fixed:

  1. In your Spring configuration define a registration bean for projection. You should set projection name and projection definition in PROJ.4 format:

    @Bean
    public ProjectionRegistration projectionRegistration21781() {
         return new GeoMapProjectionRegistration("EPSG:21781",
                 "+proj=somerc +lat_0=46.9524055555556 +lon_0=7.43958333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=674.374,15.056,405.346,0,0,0,0 +units=m +no_defs +type=crs");
    }
    
  1. In your map component define a mapView:

    <maps:mapView projection="EPSG:21781"
                  zoom="10"
                  centerX="660013.54"
                  centerY="185171.98"/>
    
  2. In the controller set this projection to the map component. Pay attention, that this projection will be applied for all map components that are shown on the page. This will enable to use projection’s unit type in the whole Map component API.

    @ViewComponent
    private GeoMap map;
    
    @Subscribe
    public void onInit(final InitEvent event) {
        map.setProjection(() -> "EPSG:21781");
    }
    

I’ve also create issue to add example to UI samples and in documentation.

1 Like

Hello Roman

Thank you a lot for your help.

In my use case, we have different entities with different projections. In the case, that one projection is applied to all map components on the page, it would make sense to use the standard EPSG:4326 projection and to have a converter to create from EPSG:21781 projection ( or anything else ) an EPSG:4326 projection.

This could be easier ?

Best regards

Felix

If you have two GeoMap components on the same page, probably it would be easier. org.geotools has modules that provides classes to convert geometries from one CRS to another. We will check this case also while working on the issue.

1 Like

Today I saw the Version 2.2.1 and I think this problem is solved ?

In the attached project, it does not work :wink:

Let me know what is wrong; thank you.
MapSample.zip (106.2 KB)

Best regards

Hello!

Could you clarify what an issue do you face? The white screen instead of map component? If yes, you can try to delete:

  1. src/main/bundle folder
  2. frontend/generated folder
  3. build folder (just in case)

Also clear cookies for localhost.

I’ve checked your project and I think there is a little issue. The projection you specify using map.setProjection() is EPSG:21781. It means that Map or its elements take the coordinates in specified projection. I saw mapView extent uses WGS84 coordinates and VectorLayer is bound with WGS84 property. So the Map thinks that property uses meter units and shows the point accordingly. And the same for the mapView extent.

For MapView extent you can use the following converted coordinates (EPSG:21781):

<maps:extent minX="-1619770.8081953595" 
             maxX="2418526.323681824" 
             minY="-1380199.875185836" 
             maxY="2057726.0042004283"/>

To show the point with WGS84 you need to convert coordinates to EPSG:21781 and store it in transient property.
I’ve prepared a demo project that demonstrates coordinates conversion. The project contains two entities:

  • PointBng: with transient pointWgs (WGS84) and point (EPSG:27700)
  • PointSwiss: with transient pointWgs (WGS84) and point (EPSG: 21781)

And there is a view with two Maps with default WGS84 projection. These maps are bound with pointWgs properties. Every entity converts coordinates from their projection to WGS84.

Project: sample.zip (117.4 KB)

Hi Roman
Today I did want to open your sample and got the following error

A problem occurred configuring root project 'sample-2-2-0'.
> Could not resolve all files for configuration ':classpath'.
   > Could not resolve io.jmix.gradle:jmix-gradle-plugin:2.2.1.1.
     Required by:
         project : > io.jmix:io.jmix.gradle.plugin:2.2.1.1
      > No matching variant of io.jmix.gradle:jmix-gradle-plugin:2.2.1.1 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.6' but:
          - Variant 'apiElements' capability io.jmix.gradle:jmix-gradle-plugin:2.2.1.1 declares a library, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component for use during compile-time, compatible with Java 17 and the consumer needed a component for use during runtime, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
          - Variant 'javadocElements' capability io.jmix.gradle:jmix-gradle-plugin:2.2.1.1 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
          - Variant 'runtimeElements' capability io.jmix.gradle:jmix-gradle-plugin:2.2.1.1 declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 8
              - Other compatible attribute:
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')
          - Variant 'sourcesElements' capability io.jmix.gradle:jmix-gradle-plugin:2.2.1.1 declares a component for use during runtime, and its dependencies declared externally:
              - Incompatible because this component declares documentation and the consumer needed a library
              - Other compatible attributes:
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Doesn't say anything about org.gradle.plugin.api-version (required '8.6')

* Try:
> Review the variant matching algorithm at https://docs.gradle.org/8.6/userguide/variant_attributes.html#sec:abm_algorithm.
> No matching variant errors are explained in more detail at https://docs.gradle.org/8.6/userguide/variant_model.html#sub:variant-no-match.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

How to solve this ?

Thank you for your help.

Felix

Jmix version: 2.2.3
Jmix Studio plugin version: 2.2.3-241
IntelliJ version: IntelliJ IDEA 2024.1.1 (Ultimate Edition)

Hello Felix!

Most probably the project uses JDK 8 for Gradle. You can check it in IDE settings: File -> Settings -> Build, Execution, Deployment -> Gradle

image