Raruto / leaflet-rotate

Leaflet plugin that allows to add rotation functionality to map tiles
GNU General Public License v3.0
77 stars 21 forks source link

After rotating the map, clicking on the map to get WMS service information is incorrect. #46

Closed JerckyLY closed 7 months ago

JerckyLY commented 9 months ago
  1. Set the map rotation to a degree other than 0
  2. Click on the map to query the WMS service information, click on the feature can not be found, click on other wrong locations to find it
  3. It should be a problem with picking up coordinates after rotation, how to get the corresponding coordinates before rotation according to the error after rotation ?

Thanks in a lot

get wms info code:


var point = this._map.latLngToContainerPoint();

var size = this._map.getSize();

var params = {
  request: "GetFeatureInfo",
  service: "WMS",
  srs: "EPSG:4326",
  styles: this.wmsParams.styles,
  transparent: this.wmsParams.transparent,
  version: this.wmsParams.version,
  format: this.wmsParams.format,
  bbox: this._map.getBounds().toBBoxString(),
  height: size.y,
  width: size.x,
  layers: layers,
  query_layers: layers,
  info_format: "application/json",
};

params[params.version === "1.3.0" ? "i" : "x"] = parseInt(point.x)
params[params.version === "1.3.0" ? "j" : "y"] = parseInt(point.y)
Raruto commented 9 months ago

Hi liuyang,

this value could also be incorrect (or at least for your use case):

var size = this._map.getSize();

I recommend you explore the L.Map class (both in the core repository and here) to find the function that might be right for you:

https://github.com/Raruto/leaflet-rotate/blob/48e97a6408df7796b3e06e6d8eb0729eb504b1be/src/map/Map.js#L28-L190

PS: if you need dev support, try asking on stackoverflow.com too..

👋 Raruto

JerckyLY commented 9 months ago

Hi @Raruto

  1. When I use map.setBearing(0) it will query wms normally, but when I setBeaing(angle > 0) it will not query normally, in both cases. The value of getSize() is the same.
  2. I also tried to calculate the point after rotation that corresponds to the point without rotation, but it doesn't work.
  3. I don't know what to do anymore, can you give me an idea?

Thanks in a lot

the code:

var containerPoint = this._map.latLngToContainerPoint(latlng);

// get unRotate point
var angle  = this._map.getBearing() * L.DomUtil.DEG_TO_RAD;  //
var center = this._map._getPixelCenter();
var point  = containerPoint.rotateFrom(-angle, center);

var size = this._map.getSize(),
  params = {
    request: "GetFeatureInfo",
    service: "WMS",
    srs: "EPSG:4326",
    styles: this.wmsParams.styles,
    transparent: this.wmsParams.transparent,
    version: this.wmsParams.version,
    format: this.wmsParams.format,
    bbox: this._map.getBounds().toBBoxString(),
    // bbox,
    height: size.y,
    width: size.x,
    layers: layers,
    query_layers: layers,
    info_format: "application/json",
  }

params[params.version === "1.3.0" ? "i" : "x"] = parseInt(point.x)
params[params.version === "1.3.0" ? "j" : "y"] = parseInt(point.y)
Raruto commented 9 months ago

I don't know what to do anymore, can you give me an idea?

Honestly?

Your code also depends on:

 this._map.getBounds()

which could cause further problems, but really, it depends on your goal/context.

Frankly, this repo contains difficult notions (unless is your daily job..), I'm not going to get into the code just because you ask..

👋 Raruto

JerckyLY commented 9 months ago

@Raruto Thanks for the reply, I'll look into it myself again, thanks in a lot