如何使用 ArcGIS 旋转 MapImage Javascript API

How to rotate a MapImage with ArcGIS Javascript API

我创建了一个地图并添加了一个 MapImage 到一个 MapImageLayer。现在我想在地图上将图像旋转一定角度。这怎么可能? 或者有其他方法可以将旋转图像添加到地图吗?

var map;
require(["esri/geometry/Extent", "esri/geometry/geometryEngine", "esri/layers/MapImageLayer", "esri/layers/MapImage",
  "esri/map", "dojo/domReady!"
], function(Extent, geometryEngine, MapImageLayer, MapImage, Map) {

  map = new Map("map", {
    basemap: "topo",
    center: [-80.93, 31.47],
    zoom: 4
  });

  var mil = new MapImageLayer({
    'id': 'image_layer'
  });

  var mi = new MapImage({
    'extent': {
      'xmin': -8864908,
      'ymin': 3085443,
      'xmax': -8062763,
      'ymax': 3976997,
      'spatialReference': {
        'wkid': 3857
      }
    },
    'href': 'https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png'
  });

  mil.addImage(mi);
  map.addLayer(mil);
});
html,
body,
#map {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}
<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Simple Image Service</title>
  <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css" />
  <script src="https://js.arcgis.com/3.16/"></script>
</head>

<body>
  <div id="map"></div>
</body>

</html>

好吧,使用 Css 我们可以尝试旋转图像。

但是 esri esri/layers/MapImageLayer 期望 className 属性 可以在其中传递预期的 css 属性。

此 CSS 属性适用于整个图层,而不仅仅是一张图像。

Below running code will explain how to achieve this:

var map;
require(["esri/geometry/Extent", "esri/geometry/geometryEngine", "esri/layers/MapImageLayer", "esri/layers/MapImage",
  "esri/map", "dojo/domReady!"
], function(Extent, geometryEngine, MapImageLayer, MapImage, Map) {

  map = new Map("map", {
    basemap: "topo",
    center: [-80, 25],
    zoom: 4
  });

  var mil = new MapImageLayer({
    'id': 'image_layer',
      'className':'rotateClass'
  });

  var mi = new MapImage({
    'extent': {
      'xmin': -8864908,
      'ymin': 3085443,
      'xmax': -8062763,
      'ymax': 3976997,
      'spatialReference': {
        'wkid': 3857
      }
    },
    'href': 'https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png'
  });

  mil.addImage(mi);
  map.addLayer(mil);
});
html,
body,
#map {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

 .rotateClass {
    -ms-transform: rotate(15deg) !important; /* IE 9 */
    -webkit-transform: rotate(15deg) !important; /* Chrome, Safari, Opera */
    transform: rotate(15deg) !important;
}
<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <title>Simple Image Service</title>
  <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css" />
  <script src="https://js.arcgis.com/3.16/"></script>
</head>

<body>
  <div id="map"></div>
</body>

</html>

希望对您有所帮助:)